Skip to main content

Basic Configuration

To enable MCP in your Cosmo Router, add the following to your config.yaml:

Configuration Options

For OAuth-specific configuration, see OAuth 2.1 Authorization.

Environment Variables

All MCP options can also be set via environment variables: Map-valued options use comma-separated key:value pairs. For example: MCP_SCALAR_MAPPINGS=Foo:object,BigInt:integer. For OAuth-related environment variables, see OAuth Configuration Reference.

Custom Scalar Mappings

The router generates each tool’s input schema from the variables of the GraphQL operation. Custom scalars are opaque to JSON Schema, but MCP clients require every property to declare a type. The router therefore advertises custom scalar variables as string by default. This matches the wire format of most opaque scalars, such as cursors, IDs, and timestamps. GraphQL has five built-in scalars: Int, Float, String, Boolean, and ID. Every other scalar in your schema is a custom scalar. The examples below use two custom scalars: scalar Foo, whose wire format is an object, and scalar BigInt, whose wire format is an integer. Use scalar_mappings for custom scalars whose wire format is not a string:
A mapped scalar’s schema states its GraphQL nullability. A non-nullable variable, such as $filter: Foo!, emits the mapped type alone: "type": "object". A nullable variable, such as $filter: Foo, emits the type with "null": "type": ["object", "null"]. Two behaviors help you keep mappings correct:
  • On startup, the router logs a warning that lists every custom scalar that fell back to the string default. Non-string arguments for these scalars are rejected by input validation, so add a mapping for any scalar with a different wire format.
  • A mapping with a value outside the allowed set fails router startup. A wrong schema contract is a configuration error, not a warning.
The router forces only GraphQL input object variables to a non-nullable object type at the top level. A scalar mapped to object is not a GraphQL input object, so it keeps its own declared nullability.

Storage Providers

MCP loads operations from a configured storage provider. Currently, only the file_system provider is supported:
Then reference this storage provider in your MCP configuration:
A storage provider must be specified to load GraphQL operations. See Storage Providers for more details on configuring storage providers.

Server Discovery

The MCP server implements the server/discover method. This method arrived in MCP protocol version 2026-07-28 as the successor to the initialize handshake. Clients call it to read the supported protocol versions, capabilities, and identity in one stateless request. The discover.instructions option sends natural-language guidance to MCP clients. Use it to tell AI agents how to work with your graph:
The server sends the instructions to every MCP client. This covers clients that connect with server/discover and clients that still use the legacy initialize handshake. The router advertises protocol version 2026-07-28 by default. In session-based mode (session.stateless: false), clients negotiate 2025-11-25 or older.

Session Handling

The MCP server uses the Streamable HTTP transport and maintains per-session state via the Mcp-Session-Id header. When deploying multiple Router instances, you need sticky sessions to ensure all requests for a session reach the same instance. To configure sticky sessions:
  1. The Router returns a unique Mcp-Session-Id response header when a session is established
  2. Clients must include that value in subsequent requests as the Mcp-Session-Id request header
  3. Your load balancer or reverse proxy must route requests with the same Mcp-Session-Id to the same instance
For details, see your load balancer or reverse proxy documentation (e.g., F5 NGINX Plus - MCP Session Affinity).

CORS

The MCP server automatically configures CORS to allow cross-origin requests from MCP clients. It sets Access-Control-Allow-Origin: * and allows the required MCP headers (Mcp-Protocol-Version, Mcp-Session-Id, Authorization, Last-Event-ID). The Mcp-Session-Id and WWW-Authenticate headers are exposed in responses. If you have additional CORS headers configured on the router, they are merged with the MCP-specific headers.

Full Configuration Example