Skip to content

graphql2mcp

npm version

Standalone CLI proxy that converts GraphQL endpoints into MCP (Model Context Protocol) servers. Point it at a GraphQL endpoint and get an MCP server with tools mapped from queries and mutations.

Install

bash
npm install -g graphql2mcp

Or run directly with npx:

bash
npx graphql2mcp https://api.example.com/graphql

CLI Usage

bash
graphql2mcp <source> [options]

The source argument can be a GraphQL endpoint URL, an SDL file path, a glob pattern, or an introspection JSON file.

From a live endpoint (introspects automatically)

bash
graphql2mcp https://api.example.com/graphql

From a GraphQL File

bash
graphql2mcp schema.graphql -e https://api.example.com/graphql

With authentication headers

bash
graphql2mcp https://api.example.com/graphql \
    -H "Authorization: Bearer YOUR_TOKEN"

Enable mutations

bash
# All mutations
graphql2mcp schema.graphql -e https://api.example.com/graphql -m all

# Specific mutations only
graphql2mcp schema.graphql -e https://api.example.com/graphql \
    -m whitelist --mutation-whitelist createUser updateUser

Filter operations

bash
# Only include specific queries
graphql2mcp schema.graphql -e https://api.example.com/graphql \
    --include users user

# Exclude specific queries
graphql2mcp schema.graphql -e https://api.example.com/graphql \
    --exclude internalMetrics debugInfo
bash
graphql2mcp https://api.example.com/graphql -t http -p 8080

CLI Flags

FlagDescriptionDefault
-e, --endpoint <url>GraphQL execution endpoint (required for file sources)-
-t, --transport <type>MCP transport type (stdio or http)stdio
-p, --port <number>HTTP port (when transport is http)3000
-m, --mutations <mode>Mutation exposure mode (all, none, or whitelist)none
--mutation-whitelist <names...>Mutation names to whitelist-
-H, --header <headers...>HTTP headers (e.g. "Authorization: Bearer x")-
-n, --name <name>MCP server namegraphql-mcp-server
-d, --depth <number>Field selection depth for return types3
--include <names...>Only include these operations-
--exclude <names...>Exclude these operations-
-V, --versionShow version number-

Programmatic Usage

The package also exports functions for creating proxy servers programmatically.

From a live URL (with introspection)

typescript
import { createProxyServerFromUrl } from 'graphql2mcp';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';

const server = await createProxyServerFromUrl({
    url: 'https://api.example.com/graphql',
    headers: { Authorization: 'Bearer YOUR_TOKEN' },
    mutations: 'all'
});

const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
await server.connect(transport);

From a GraphQL File

typescript
import { createProxyServer } from 'graphql2mcp';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';

const server = createProxyServer({
    endpoints: [
        {
            source: 'schema.graphql',
            endpoint: 'https://api.example.com/graphql',
            headers: { Authorization: 'Bearer YOUR_TOKEN' }
        }
    ]
});

const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
await server.connect(transport);

Multi-endpoint

Combine multiple GraphQL APIs into a single MCP server. Use the prefix option to namespace tools and avoid collisions:

typescript
import { createProxyServer } from 'graphql2mcp';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';

const server = createProxyServer({
    endpoints: [
        {
            source: 'schemas/users.graphql',
            endpoint: 'https://users-api.example.com/graphql',
            prefix: 'users'
        },
        {
            source: 'schemas/products.graphql',
            endpoint: 'https://products-api.example.com/graphql',
            prefix: 'products',
            mutations: { whitelist: ['createProduct'] }
        }
    ],
    name: 'multi-api-server'
});

// Tools are named: users_query_getUser, products_query_listProducts, products_mutation_createProduct, etc.
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
await server.connect(transport);

ProxyServerOptions

OptionTypeDefaultDescription
endpointsEndpointConfig[](required)Endpoint configurations (at least one)
namestring'graphql-mcp-server'MCP server name
versionstring'1.0.0'MCP server version
depthnumber3Field selection depth
timeoutnumber30000Request timeout in milliseconds
queryPrefixstring'query_'Prefix for query tool names
mutationPrefixstring'mutation_'Prefix for mutation tool names

EndpointConfig

OptionTypeDefaultDescription
sourcestring(required)SDL file path, glob, SDL string, or introspection JSON path
endpointstringundefinedGraphQL execution endpoint URL
headersRecord<string, string>undefinedHTTP headers for introspection and runtime execution
mutationsMutationMode'none'Mutation exposure mode ('none', 'all', or { whitelist: [...] })
includestring[]undefinedOnly include these operations
excludestring[]undefinedExclude these operations
prefixstringundefinedPrefix for this endpoint's tools (for multi-endpoint collision avoidance)

License

MIT

Released under the MIT License.