
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
A library for automatically generating FastMCP tools from a GraphQL schema.
This allows you to expose your GraphQL API as a set of tools that can be used by other systems, such as AI agents or other services that understand the MCP (Multi-Model-Protocol).
FastMCP
Integration: Seamlessly adds the generated functions as tools to a FastMCP
server instance.strawberry-graphql
.You can install graphql-mcp
using pip. To follow the usage example, you'll also need strawberry-graphql
:
pip install graphql-mcp "strawberry-graphql[cli]"
Here's a simple example of how to use graphql-mcp
to create tools from a strawberry-graphql
schema.
# example.py
import asyncio
import strawberry
from fastmcp import FastMCP
from graphql_mcp.server import add_tools_from_schema
# 1. Define your GraphQL schema using Strawberry
@strawberry.type
class Query:
@strawberry.field
def hello(self, name: str = "World") -> str:
"""Returns a greeting."""
return f"Hello, {name}!"
@strawberry.type
class Mutation:
@strawberry.mutation
def send_message(self, message: str) -> str:
"""Prints a message and returns a confirmation."""
print(f"Received message: {message}")
return f"Message '{message}' sent successfully."
# The strawberry.Schema object is compatible with graphql-core's GraphQLSchema
schema = strawberry.Schema(query=Query, mutation=Mutation)
# 2. Create a FastMCP server instance
server = FastMCP(name="MyGraphQLServer")
# 3. Add tools from the schema
# The `strawberry.Schema` object can be passed directly.
add_tools_from_schema(schema, server)
# 4. Use the generated tools
async def main():
# You can inspect the tools
print("Available tools:", server.get_tool_names())
# You can also inspect a specific tool's signature
print("Tool 'hello' signature:", server.get_tool_signature("hello"))
# Call a query tool
result = await server.acall_tool("hello", name="Bob")
print("Query result:", result)
# Call a mutation tool
result = await server.acall_tool("send_message", message="This is a test")
print("Mutation result:", result)
if __name__ == "__main__":
asyncio.run(main())
When you run this script, you will see the following output:
Available tools: ['send_message', 'hello']
Tool 'hello' signature: (name: str = 'World') -> str
Query result: Hello, Bob!
Received message: This is a test
Mutation result: Message 'This is a test' sent successfully.
GraphQLMCPServer
For convenience, you can also use the GraphQLMCPServer
class, which inherits from FastMCP
and provides class methods to create a server directly from a schema.
GraphQLSchema
objectYou can use GraphQLMCPServer.from_schema()
and pass any graphql-core
-compatible GraphQLSchema
object. This includes schemas created with strawberry-graphql
.
# example_from_schema.py
import asyncio
import strawberry
from graphql_mcp.server import GraphQLMCPServer
# 1. Define your schema (e.g., with Strawberry)
@strawberry.type
class Query:
@strawberry.field
def hello(self, name: str = "World") -> str:
return f"Hello, {name}!"
schema = strawberry.Schema(query=Query)
# 2. Create the server from the schema
server = GraphQLMCPServer.from_schema(schema, name="MyGraphQLServer")
# 3. Use the server
async def main():
print("Available tools:", server.get_tool_names())
result = await server.acall_tool("hello", name="From Schema")
print("Query result:", result)
if __name__ == "__main__":
asyncio.run(main())
graphql-api
objectIf you are using the graphql-api
library, you can use the GraphQLMCPServer.from_api()
method.
# example_from_api.py
import asyncio
from graphql_api import GraphQLAPI, field
from graphql_mcp.server import GraphQLMCPServer, HAS_GRAPHQL_API
# The .from_graphql_api() method is only available if `graphql-api` is installed.
if HAS_GRAPHQL_API:
# 1. Define your API using `graphql-api`
class MyAPI:
@field
def hello(self, name: str = "World") -> str:
return f"Hello, {name}!"
api = GraphQLAPI(roottype=MyAPI)
# 2. Create the server from the API object
server = GraphQLMCPServer.from_graphql_api(api)
# 3. Use the server
async def main():
print("Available tools:", server.get_tool_names())
result = await server.acall_tool("hello", name="From API")
print("Query result:", result)
if __name__ == "__main__":
asyncio.run(main())
graphql-mcp
introspects your GraphQL schema's queries and mutations. For each field, it does the following:
String
, Int
, ID
, and custom Enum
types to their Python equivalents. Input objects are treated as dictionaries.graphql-sync
to execute the query against the schema, passing in the provided arguments as variables.The tool names are converted from camelCase
(GraphQL convention) to snake_case
(Python convention). For example, a mutation sendMessage
becomes a tool named send_message
.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
A framework for building Python GraphQL MCP servers.
We found that graphql-mcp demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.