loading…
Search for a command to run...
loading…
Library for integrating GraphQL-to-MCP conversion into existing TypeScript MCP servers
Library for integrating GraphQL-to-MCP conversion into existing TypeScript MCP servers
npm version npm downloads TypeScript license
Convert GraphQL schemas and endpoints into Model Context Protocol (MCP) servers. Point at any GraphQL API and get an MCP server with tools mapped from queries and mutations.
readOnlyHint: true, mutations get destructiveHint: trueRun against a live GraphQL endpoint (introspects the schema automatically):
npx graphql2mcp https://api.example.com/graphql -t http
This starts a Streamable HTTP MCP server on port 3000. For stdio transport (used by Claude Desktop, Cursor), omit the -t http flag:
npx graphql2mcp https://api.example.com/graphql
Or from a local SDL file:
npx graphql2mcp schema.graphql -e https://api.example.com/graphql -t http
Add GraphQL tools to an existing MCP server:
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import { registerGraphQLTools } from '@graphql2mcp/lib';
const server = new McpServer({ name: 'my-server', version: '1.0.0' });
// Register your own tools alongside GraphQL tools
registerGraphQLTools(server, {
source: 'schema.graphql',
endpoint: 'https://api.example.com/graphql'
});
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
await server.connect(transport);
Or use getGraphQLTools for full control over registration:
import { getGraphQLTools } from '@graphql2mcp/lib';
const { tools } = getGraphQLTools({
source: 'schema.graphql',
endpoint: 'https://api.example.com/graphql'
});
for (const tool of tools) {
server.registerTool(
tool.name,
{
title: tool.title,
description: tool.description,
inputSchema: tool.inputSchema,
annotations: tool.annotations
},
tool.handler
);
}
This is a monorepo managed with pnpm workspaces:
| Package | Description |
|---|---|
| graphql2mcp | Standalone CLI proxy — point at a GraphQL endpoint, get an MCP server |
| @graphql2mcp/core | Shared engine — schema loading, tool generation, execution, and MCP server registration |
| @graphql2mcp/lib | Library for integrating into existing TypeScript MCP servers |
flowchart TD
subgraph Input
A[SDL File] --> L
B[Inline SDL] --> L
C[Introspection JSON] --> L
D[Glob Pattern] --> L
E[Live URL] --> U
end
L[loadSchema] --> S[GraphQLSchema]
U[loadSchemaFromUrl] --> S
subgraph "@graphql2mcp/core"
S --> G[generateTools]
G --> T[ToolDefinition]
end
subgraph MCP Server
T --> R[registerTool]
R --> Q[Tool Called]
end
Q -->|POST query + variables| EP[GraphQL Endpoint]
EP -->|JSON response| Q
GraphQLSchema object using the graphql libraryToolDefinition objects with names, descriptions, annotations, and pre-built query documentsMcpServer. When an AI agent calls a tool, the server executes the corresponding GraphQL operation against the endpoint and returns the result as JSON| Runtime | Version | Status |
|---|---|---|
| Node.js | >= 22 | Tested |
| Bun | >= 1.2 | Tested |
| Deno | >= 2.0 | Tested |
pnpm install
pnpm build
pnpm test
MIT
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"lib": {
"command": "npx",
"args": [
"-y",
"@graphql2mcp/lib"
]
}
}
}