MCP

JSON-RPC 2.0 endpoint for the gateway's MCP server

JSON-RPC 2.0 endpoint exposing the gateway itself as an MCP server. It aggregates every server configured in MCP_SERVERS behind one URL, so MCP clients (opencode, infer, IDE assistants) configure a single entry and get the whole fleet, with the gateway's auth, metrics and guardrails applied to every tool call.

The endpoint lives at the root, not under /v1 - /v1/* is the OpenAI-compatible surface, MCP is its own protocol and clients expect a plain /mcp.

Gated by MCP_EXPOSE=true (and MCP_ENABLED=true); otherwise the gateway answers 403. Gateway auth is global, so when AUTH_ENABLE=true this endpoint requires a bearer token like every other route except /health.

The endpoint speaks MCP protocol version 2026-07-28 only, over the stateless Streamable HTTP transport with application/json responses. There is no initialize handshake and no session: every request carries its protocol version in params._meta["io.modelcontextprotocol/protocolVersion"] (alongside the required io.modelcontextprotocol/clientInfo and io.modelcontextprotocol/clientCapabilities), mirrored in the MCP-Protocol-Version, Mcp-Method and, for tools/call, Mcp-Name headers. Mcp-Name may use the =?base64?<value>?= encoding.

Supported methods:

MethodParamsResult
server/discover_meta onlyDiscoverResult - supportedVersions (["2026-07-28"]), capabilities (tools)
tools/listoptional cursorListToolsResult - the aggregated, namespaced tools of every healthy MCP server
tools/callCallToolRequestParams (name, arguments)CallToolResult

Every result carries resultType: "complete" and identifies the gateway in _meta["io.modelcontextprotocol/serverInfo"].

Param and result shapes are the vendored MCP spec types in mcp/mcp-schema.yaml (RequestMetaObject, DiscoverResult, ServerCapabilities, ListToolsResult, CallToolRequestParams, CallToolResult); this spec only describes the JSON-RPC envelopes the gateway puts them in.

tools/list tolerates partial availability: when one of the configured MCP servers is unreachable its tools are omitted and the healthy servers' tools are still returned, rather than failing the whole call. A tools/call routed to an unavailable server fails with JSON-RPC error code -32603.

Errors use JSON-RPC error envelopes:

CodeMeaningHTTP status
-32020header mismatch - a required header is missing, malformed or disagrees with the body; a legacy initialize request lands here400
-32022unsupported protocol version; data carries requested and supported400
-32601method not found404
-32700parse error200
-32600invalid request200
-32602invalid params (unknown tool name, bad arguments)200
-32603internal error (upstream MCP server failure)200

A request carrying an Origin header is rejected with 403: MCP clients are not browsers, and this blocks DNS-rebinding attacks. GET and DELETE answer 405 - there is no standalone stream and no session to terminate.

post/mcp

Headers

MCP-Protocol-Versionstring required
Example:2026-07-28

Must equal params._meta["io.modelcontextprotocol/protocolVersion"].

Mcp-Methodstring required
Example:tools/call

Must equal the JSON-RPC method.

Mcp-Namestring
Example:mcp_deepwiki_ask_question

Required for tools/call; must equal params.name. Values that are not plain ASCII are sent as =?base64?<value>?=.

Request body

jsonrpc'2.0' required

JSON-RPC protocol version, always "2.0"

method'server/discover' | 'tools/list' | 'tools/call' required

The MCP method to invoke

paramsobject

Method parameters, as defined by the MCP specification

Example request

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "name": "mcp_deepwiki_ask_question",
    "arguments": {
      "repoName": "inference-gateway/inference-gateway",
      "question": "How is MCP wired up?"
    },
    "_meta": {
      "io.modelcontextprotocol/protocolVersion": "2026-07-28",
      "io.modelcontextprotocol/clientInfo": {
        "name": "opencode",
        "version": "1.0.0"
      },
      "io.modelcontextprotocol/clientCapabilities": {}
    }
  }
}

Response

JSON-RPC response envelope, carrying either a result or an error.

jsonrpc'2.0' required

JSON-RPC protocol version, always "2.0"

resultobject

The method result, present on success

Example response

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32602,
    "message": "unknown tool: mcp_deepwiki_missing_tool"
  }
}

Changes

Changed in 2 of the 77 revisions of this API.45

  • a31ede1097b144See the full diff
    • ▲

      added the new required header request parameter MCP-Protocol-Version

      new-required-request-parameter

    • ▲

      added the new required header request parameter Mcp-Method

      new-required-request-parameter

    • ▲

      removed the enum value initialize of the request property

      request-property-enum-value-removed

    • ▲

      removed the enum value notifications/initialized of the request property

      request-property-enum-value-removed

    • ○

      added the new optional header request parameter Mcp-Name

      new-optional-request-parameter

    • ○

      added the new server/discover enum value to the request property

      request-property-enum-value-added

    • ○

      added the non-success response with the status

      response-non-success-status-added

    • ○

      added the non-success response with the status

      response-non-success-status-added

    • ○

      endpoint added

      endpoint-added