MCP Server

MCP Server GraphQL Endpoints

Applies to
Gatewayruntime for API, AI, and MCP gateways
Hosting
Managed EdgeManaged DedicatedSelf-Hosted

The MCP Server Handler supports GraphQL endpoints through the x-zuplo-route OpenAPI extension. A GraphQL route becomes a set of MCP tools that let AI systems read your schema and run operations, without a tool definition for each query.

Your project's compatibility date picks the tools a GraphQL route registers:

Compatibility dateTools
2026-11-06 and laterSchema tool (SDL), query tool (queries only), mutation tool (mutations only)
Before 2026-11-06Introspection tool, execute tool (any operation)

The schema, query, and mutation tools keep reads and writes in separate tools, so MCP clients and MCP directories can tell them apart, and you can turn writes off. To use them, set "compatibilityDate": "2026-11-06" or later in zuplo.jsonc.

Quick Start

1. Configure a GraphQL Endpoint

Add a route that forwards to your GraphQL endpoint and include the x-zuplo-route.mcp configuration:

JSONCode
{ "openapi": "3.1.0", "info": { "version": "1.0.0" }, "paths": { "/graphql": { "post": { "operationId": "graphql", "summary": "GraphQL API endpoint", "x-zuplo-route": { "handler": { "export": "urlForwardHandler", "module": "$import(@zuplo/runtime)", "options": { "baseUrl": "https://api.example.com", "followRedirects": true } }, "mcp": { "type": "graphql" } } } } } }

2. Add to Your MCP Server

Include the GraphQL route in your MCP Server configuration using the operations array:

JSONCode
{ "paths": { "/mcp": { "post": { "summary": "MCP server", "operationId": "mcp-server", "x-zuplo-route": { "corsPolicy": "none", "handler": { "export": "mcpServerHandler", "module": "$import(@zuplo/runtime)", "options": { "name": "My MCP Server", "version": "1.0.0", "operations": [ { "file": "./config/routes.oas.json", "id": "graphql" } ] } } } } } } }

On compatibility date 2026-11-06 or later, this configuration creates:

  • graphql_schema - Returns types of the GraphQL schema as SDL
  • graphql_query - Runs GraphQL queries
  • graphql_mutation - Runs GraphQL mutations

On an earlier date, it creates:

  • graphql_introspect - Fetches the GraphQL schema
  • graphql_execute_query - Runs any GraphQL operation

Configuration Options

These options apply on every compatibility date:

  • type: Must be set to "graphql".
  • enabled: Set to false to register no tools for the route (default: true). Before compatibility date 2026-11-06, the route ignores enabled: false.

Each set of tools has its own options, described below. A route that sets an option of the other set fails the build: for example, executeTool on compatibility date 2026-11-06 or later, or queryTool on an earlier date. An introspectionTool or executeTool with only empty values doesn't count.

Schema, Query, and Mutation Tools

From compatibility date 2026-11-06, a GraphQL route registers these tools, in this order:

ToolWhat it doesAnnotations
{operationId}_schemaReturns types of the schema as SDLRead-only, idempotent
{operationId}_queryRuns query operations onlyRead-only, idempotent
{operationId}_mutationRuns mutation operations onlyDestructive, not idempotent

Every tool sends a title and openWorldHint: false. The default titles are {summary} schema, {summary} query, and {summary} mutation, where {summary} is the operation's summary, or its operationId when it has none.

Schema, Query, and Mutation Tool Options

  • documentationUrl: A link to your GraphQL API reference. The default query and mutation descriptions end with it.
  • schemaTool, queryTool, mutationTool: Configuration for each tool.
    • enabled: Set to false to leave the tool out.
    • name: Custom name for the tool.
    • title: Custom title for the tool.
    • description: Custom description, used as written.
    • annotations: MCP tool annotations, merged over the defaults in the table above.
  • schemaTool.defaultTypeNames: The types the schema tool returns when a call doesn't pass typeNames, for example ["Query"]. See Schema tool.
  • schemaTool.defaultDepth: The depth used when a call doesn't pass depth: 0, 1, or 2 (default: 0).

For example, a read-only server with custom tool names:

JSONCode
"mcp": { "type": "graphql", "documentationUrl": "https://docs.example.com/graphql", "schemaTool": { "name": "example_schema" }, "queryTool": { "name": "example_query" }, "mutationTool": { "enabled": false } }

If your mutations only ever add data, mark them as not destructive:

JSONCode
"mutationTool": { "annotations": { "destructiveHint": false } }

Schema Tool

The schema tool returns types of the schema as SDL text, so an agent reads only the part of a large schema it needs. Called without arguments, it returns the root query type, the root mutation type, and a last line that names every other type:

GraphQLCode
type Query { order(id: ID!): Order customer(id: ID!): Customer } type Mutation { deleteOrder(id: ID!): Boolean } # Other types: Address, Customer, Order

The agent then asks for the types it needs by name. The tool takes two optional arguments:

  • typeNames: The types to return, for example ["Order"].
  • depth: How many levels of referenced types to include, from 0 to 2. Referenced types are the types of fields, arguments, input fields, interfaces, and union members.

The schema tool never returns or names the root subscription type, because no tool runs subscriptions. When you turn the mutation tool off, it leaves out the root mutation type too.

To return other types from a call without typeNames, set schemaTool.defaultTypeNames. For example, to return only the root query fields:

JSONCode
"schemaTool": { "defaultTypeNames": ["Query"] }

An unknown type name returns a tool error that suggests close names:

Code
Unknown type "Ordr". Did you mean: Order, OrderLine, OrderInput, OrderStatus? Type names are case-sensitive. Call graphql_schema without typeNames to list every type.

The schema tool sends a standard introspection query to the route, so the route must allow GraphQL introspection.

Query and Mutation Tools

Both tools take query (required), variables, and operationName, and send them to the route as a JSON body. The route's policies run as usual. A call with any other argument is rejected.

Each tool parses the document before it sends anything to the route, and rejects the call when:

  • the operation is the other tool's type, for example a mutation sent to the query tool;
  • the operation is a subscription;
  • the document has a syntax error or no operation;
  • the document has several operations and operationName doesn't pick one;
  • several operations share the name in operationName.

The error tells the agent what to change:

Code
Invalid arguments for tool 'graphql_query': Operation is a mutation. Use the graphql_mutation tool.

A result is a tool error (isError: true) when the route answers with a status outside 200-299, or when the response has a non-empty errors array, even with partial data.

Introspection and Execute Tools

Before compatibility date 2026-11-06, a GraphQL route registers an introspection tool, {operationId}_introspect, and an execute tool, {operationId}_execute_query, which runs any operation the route accepts.

Introspection and Execute Tool Options

  • introspectionTool: Configuration for the introspection tool.
    • name: Custom name for the introspection tool.
    • description: Custom description for the introspection tool.
    • annotations: MCP tool annotations, sent as configured.
  • executeTool: Configuration for the execute tool.
    • name: Custom name for the execute tool.
    • description: Custom description for the execute tool.
    • annotations: MCP tool annotations, sent as configured.

For example:

JSONCode
{ "paths": { "/graphql": { "post": { "operationId": "github_graphql", "x-zuplo-route": { "handler": { "export": "urlForwardHandler", "module": "$import(@zuplo/runtime)", "options": { "baseUrl": "https://api.github.com" } }, "mcp": { "type": "graphql", "introspectionTool": { "name": "github_schema", "description": "Fetch the GitHub GraphQL schema" }, "executeTool": { "name": "github_query", "description": "Execute a query against the GitHub GraphQL API" } } } } } } }

Custom GraphQL Tools

For more complex scenarios like bounded mutations or queries with complex logic, you can create custom GraphQL tools as endpoints using the Zuplo custom MCP tool patterns and the graphql library.

Here's a simple example of a custom bounded GraphQL query that expects an id input from the MCP client:

JSONCode
{ "paths": { "/graphql/ship": { "post": { "summary": "Get details about a specific ship", "operationId": "get_ship", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["id"], "properties": { "id": { "type": "string", "description": "The ID of the ship to query" } } } } } }, "x-zuplo-route": { "handler": { "export": "default", "module": "$import(./modules/get-ship)" } } } } } }

In your handler (modules/get-ship.ts):

TypeScriptCode
import { ZuploContext, ZuploRequest } from "@zuplo/runtime"; export default async function handler( request: ZuploRequest, context: ZuploContext, ) { const { id } = await request.json(); const query = ` query GetShip($id: ID!) { ship(id: $id) { name model manufacturer } } `; const response = await fetch("https://api.example.com/graphql", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ query, variables: { id }, }), }); return response; }

For more complex custom tools with validation, error handling, and multi-step workflows, see the Custom Tools documentation.

See Also

Last modified on