MCP Gateway | GraphQL MCP, Connect APIs to AI

WunderGraph

4 min read Original article ↗

Questions about AI agent access

What is an MCP gateway?

An MCP gateway sits between AI clients and your APIs, exposing a controlled set of operations as tools an agent can call. Instead of handing an agent your whole schema, you publish a specific list. The gateway handles the Model Context Protocol so your backend services do not have to.

How is an MCP gateway different from an API gateway?

An API gateway routes requests from applications to endpoints. An MCP gateway serves autonomous agents calling tools, so the unit of access control is the operation, not the route. The question shifts from "can this client reach /orders" to "can this agent execute cancelOrder, for this user, right now".

Is an MCP gateway safer than giving an agent direct access to a GraphQL API?

Direct access means the agent can run any query the schema permits, including combinations you never anticipated. A gateway narrows that to operations you wrote and reviewed. The difference is not encryption or authentication, both of which you should have either way. It is the size of the surface an agent can act on.

How do you decide what an AI agent is allowed to do?

You write GraphQL operation files and point the Router at that directory. Each one becomes a tool. Anything you did not write is not available. Because they are normal GraphQL operations, they go through the same review as any other change to your graph, rather than living in a separate policy system.

Can an AI agent run arbitrary queries against your schema?

Not by default. The gateway exposes only the operations in your configured directory. Two settings widen that, and both are off by default: enable_arbitrary_operations turns on the execute_graphql tool, and expose_schema turns on get_schema. Either one hands the agent back the surface the safelist was there to remove.

Can you stop an AI agent from running mutations?

Yes. Set exclude_mutations: true in the MCP configuration and only queries are exposed. It defaults to false, so set it explicitly if you want read-only. This gives you a read-only agent without building a second API.

How do you scope MCP tool permissions per operation instead of per server?

Scopes come from your schema. The Router reads @requiresScopes directives on the fields an operation selects and enforces the resulting scope set on that tool, so each tool carries only the permissions its operation needs. Scope claims must arrive as a space-separated string; array-format claims are not supported.

Can prompt injection reach your backend through an MCP gateway?

A gateway does not stop an agent being manipulated. What it does is limit what a manipulated agent can execute. An injected instruction can only call operations you published, with the arguments those operations accept, so the blast radius is whatever your operation list allows rather than whatever the schema allows. Keep the list tight.

Do your backend services need to support MCP?

No. Your subgraphs stay GraphQL and do not know MCP exists. The Cosmo Router speaks the protocol on their behalf, including as the specification changes, so protocol churn is the Router problem rather than your services.

Do you need to build a separate AI-safe API?

No. That is the usual workaround: a second, narrower API built alongside the real one, then maintained in parallel forever. The MCP Gateway exposes a controlled slice of the graph you already run.

What MCP specification version does Cosmo support?

The Router advertises protocol version 2026-07-28 by default. In session mode it negotiates 2025-11-25 or older, so a client on an earlier revision still connects rather than being refused. Transport is Streamable HTTP.

Can an AI agent subscribe to live data through the gateway?

No. The MCP gateway exposes queries and mutations as tools, and subscriptions are not supported. A tool call is one request and one response, which does not map onto a long-lived stream. For streaming, use the Router subscription transports directly.

Which AI tools work with the Cosmo MCP Gateway?

Claude Desktop, Cursor (v0.48.0+), Windsurf, VS Code Copilot, and any MCP-compatible AI platform. The Router uses Streamable HTTP transport.

How do you make operations understandable to AI models?

Add a docstring to each operation file using the September 2025 GraphQL spec. The Router uses this as the tool description that AI models read when discovering available tools.

How do you handle authentication on the MCP Gateway?

The MCP server forwards most client headers to the Router, including authorization, custom and tracing headers, skipping only hop-by-hop and content-negotiation headers. What reaches your subgraphs from there is governed separately by the header rules on the router itself. The built-in OAuth 2.1 support adds JWT-based auth with scopes enforced at five levels, and it is off by default.