Skip to Content
GuidesFrom a GraphQL schema

Generate from a GraphQL schema

mcpgen reads a GraphQL schema and turns each root query and mutation field into an MCP tool. Field arguments become tool inputs; the GraphQL type maps to JSON Schema.

Supported

  • SDL (.graphql / .gql) — a schema definition document.
  • Introspection JSON — the result of an introspection query.
  • Parsed with the reference graphql package; no network calls during parse.

Generate

npx mcpgenx generate ./schema.graphql --out ./my-server
npx mcpgenx inspect ./schema.graphql

How fields map to tools

GraphQLIR / generated tool
Query.<field>a tool with operation: query, root field
Mutation.<field>a tool with operation: mutation, root field
field argumentstool input fields (location: arg)
argument / field typesJSON Schema on the input/output
field descriptionthe tool description

The generated server builds and issues the GraphQL operation for you against the upstream endpoint (MCPGEN_API_BASE_URL), selecting the requested root field.

Subscriptions are not generated — MCP tools are request/response, so only Query and Mutation roots become tools.

Tips

  • Endpoint — set MCPGEN_API_BASE_URL to your GraphQL HTTP endpoint (e.g. https://api.example.com/graphql).
  • Auth — most GraphQL APIs use a bearer token; see Adding auth.
  • Selection sets — generated handlers request the fields described by the schema’s output type; trim or extend them in the generated handler if you need a narrower selection.

Next

Last updated on