Skip to content

MCP Servers API ​

Connect to external MCP (Model Context Protocol) servers and execute tools through the control plane. The control plane acts as an MCP proxy, supporting both direct execution and the full MCP protocol via SSE transport.

Direct Tool Execution ​

List Server Tools ​

GET /api/client/v1/mcp/:serverKey/execute

Returns MCP server metadata and its available tools.

Path Parameters ​

ParameterTypeRequiredDescription
serverKeystringYesMCP server key

Response ​

json
{
  "server": {
    "key": "tavily-search",
    "name": "Tavily Search",
    "status": "active",
    "totalRequests": 42,
    "createdAt": "2026-01-20T12:00:00.000Z"
  },
  "tools": [
    {
      "name": "search",
      "description": "Search the web using Tavily",
      "inputSchema": {
        "type": "object",
        "properties": {
          "query": { "type": "string" }
        },
        "required": ["query"]
      }
    }
  ]
}

Execute Tool ​

POST /api/client/v1/mcp/:serverKey/execute

Execute a specific tool on the MCP server.

Request ​

json
{
  "tool": "search",
  "arguments": {
    "query": "latest AI news"
  }
}

Parameters ​

FieldTypeRequiredDescription
toolstringYesName of the tool to execute
argumentsobjectNoTool arguments (default: {})

tool must be a tool the server lists: a name from tools/list, or the tool's original name if it has been renamed. Any other name is rejected, and so is a tool the server has disabled. After a server's upstream adds tools, refresh the server's tools so they are listed.

For servers built from an OpenAPI spec, the arguments are matched against the operation. Only parameters the operation declares are sent upstream; other argument names are ignored. Path parameters are required, must be non-empty strings or numbers, and cannot be relative path segments (. or .., also when percent-encoded) or contain control characters. The request always goes to the configured upstream base URL, under the operation's path.

Response ​

json
{
  "result": {
    "results": [
      { "title": "...", "url": "...", "content": "..." }
    ]
  },
  "metadata": {
    "tool": "search",
    "server": "tavily-search",
    "latencyMs": 1523
  }
}

MCP Protocol (SSE Transport) ​

The control plane implements the MCP protocol over streamable HTTP and the SSE transport, so standard MCP clients can connect. It speaks the revisions 2024-11-05, 2025-03-26, 2025-06-18 and 2025-11-25 (see Protocol version).

Open SSE Stream ​

GET /api/client/v1/mcp/:serverKey/sse

Opens a Server-Sent Events stream. The server sends an endpoint event containing the path the client should POST JSON-RPC messages to.

Response Headers ​

Content-Type: text/event-stream
Cache-Control: no-cache, no-transform
X-Mcp-Session-Id: <session-id>

Initial Event ​

event: endpoint
data: /api/client/v1/mcp/tavily-search/message?sessionId=abc-123

data is always a path, never an absolute URL. MCP clients resolve it against the URL they opened the stream on, so it is right whatever hostname they used to reach the gateway; it does not depend on APP_URL or on the request's Host and X-Forwarded-* headers.

By default the gateway keeps a stream open with a : keepalive comment every 25 seconds, closes one that has received no message for 30 minutes, and refuses a new one (429 or 503, with a Retry-After header and a JSON body) when its limits on open streams are reached; see MCP gateway limits.

A sessionId must be one the gateway issued to the same API token for the same server. Any other value (an unknown id, one whose stream has ended, one another token opened) is answered 404 with JSON-RPC error -32001 (Session not found). The body must be a JSON object; anything else is answered 400 with -32600 (or -32700 when it is not JSON at all).

Send JSON-RPC Message ​

POST /api/client/v1/mcp/:serverKey/message?sessionId=<id>

Send MCP JSON-RPC messages. Responses are pushed through the SSE stream when a session is active, or returned directly in the HTTP body for stateless mode.

Supported Methods ​

MethodDescription
initializeInitialize MCP session (returns capabilities and server info)
notifications/initializedClient acknowledgment (no response)
pingHealth check
tools/listList available tools with schemas
tools/callExecute a tool by name with arguments

Initialize ​

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": { "protocolVersion": "2025-06-18" }
}

Response:

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2025-06-18",
    "capabilities": {
      "tools": { "listChanged": false }
    },
    "serverInfo": {
      "name": "cognipeer-mcp-gateway",
      "version": "1.0.0"
    },
    "instructions": "Call search first; pass the documentId it returns to read_document."
  }
}

instructions is present only when the server has some (see Server instructions).

Protocol version ​

initialize answers with the protocolVersion the client asked for when the server speaks it, and with 2025-11-25 otherwise (the client then decides whether to go on). Later requests over streamable HTTP name their revision in the MCP-Protocol-Version header; a request without it is taken to speak 2025-03-26.

The revision decides the shape of a tools/call result. From 2025-06-18 on, a tool that returns a JSON object answers with it in structuredContent, next to its text, and a link to a resource arrives as a resource_link block. An older client gets the text alone, and the link as a Markdown link.

List Tools (JSON-RPC) ​

json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list"
}

Response:

json
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "tools": [
      {
        "name": "search",
        "title": "Search",
        "description": "Search the web",
        "inputSchema": { "type": "object", "properties": { "query": { "type": "string" } } },
        "annotations": {
          "title": "search",
          "readOnlyHint": true,
          "destructiveHint": false,
          "idempotentHint": true,
          "openWorldHint": false
        }
      }
    ]
  }
}

Every tool is returned with a complete annotations block (title, readOnlyHint, destructiveHint, idempotentHint, openWorldHint). Strict clients — OpenAI's MCP connector among them — reject servers that omit these hints. Values come from the tool definition when present; otherwise they are derived (read-only for GET/HEAD OpenAPI operations, read-only for internal Knowledge Base / Agent Observability tools and for the Browser tools that only observe the page, and the conservative "not read-only, potentially destructive" default elsewhere).

To override a hint or reword a tool, open the MCP server's Tools tab in the dashboard and use the row action, or PATCH the server directly:

bash
curl -X PATCH "https://your-cognipeer-host/api/client/v1/mcp/<serverKey>" \
  -H "Authorization: Bearer cpeer_..." -H "Content-Type: application/json" \
  -d '{
        "toolAnnotations": {"search": {"readOnlyHint": true, "openWorldHint": false}},
        "toolDescriptions": {"search": "Search the product handbook and return matching passages."}
      }'

Both maps are stored per server and survive tool rediscovery. Send null for a tool ({"toolAnnotations":{"search":null}}) to drop its override and go back to the discovered definition. Description overrides also apply everywhere else the tool is surfaced — the tools REST endpoints and agents that use this server.

Each tool also carries a top-level title, its display name. It is the tool's own title (an upstream MCP server's, or an OpenAPI operation's summary), and the tool name when there is none. A title set in toolAnnotations overrides it.

Server instructions ​

initialize returns instructions: text that tells the model how the server's tools fit together — which tool to call first, what an ID from one tool is passed to, limits and scope. MCP clients may add it to the model's system prompt.

By default a server returns what its source supplies:

SourceInstructions
Remote MCP / stdioThe upstream server's own instructions, read at discovery and on Refresh tools
Knowledge Base, Agent Observability, BrowserWritten by Cognipeer for the provider's tools
CompositeOne ## <member name> section per active member that has instructions
OpenAPINone

To write your own, open the server's Edit form and fill in Instructions, or PATCH the server. Your text replaces the source's; send null or an empty string to go back to it. The limit is 8,000 characters.

bash
curl -X PATCH "https://your-cognipeer-host/api/client/v1/mcp/<serverKey>" \
  -H "Authorization: Bearer cpeer_..." -H "Content-Type: application/json" \
  -d '{"instructions": "Call search first; pass the documentId it returns to read_document."}'

The server record returns both texts: instructions (yours) and discoveredInstructions (the source's).

Call Tool (JSON-RPC) ​

json
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": { "query": "AI news" }
  }
}

Response:

json
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "content": [
      { "type": "text", "text": "{ ... search results ... }" }
    ],
    "isError": false
  }
}

Error Codes ​

CodeMeaning
-32700Parse error (invalid JSON)
-32600Invalid request (missing method)
-32601Method not found
-32602Invalid params — the tools/call names a tool the server does not list, or has no name
-32001MCP server not found, or (message endpoint) session not found
-32002MCP server disabled
-32603Internal error

A call to a listed tool that fails — including one with a missing or invalid argument — is not a protocol error. It returns a normal result with "isError": true and the reason in the text content, so the model can read it and retry with corrected arguments:

json
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "content": [{ "type": "text", "text": "Missing required path parameter \"id\"" }],
    "isError": true
  }
}

Stateless Mode ​

If no sessionId query parameter is provided to the message endpoint, responses are returned directly in the HTTP body instead of being pushed through SSE. This is useful for simple integrations that don't need persistent sessions.

bash
curl -X POST https://gateway.example.com/api/client/v1/mcp/tavily-search/message \
  -H "Authorization: Bearer cpeer_your_token" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'

OAuth 2.0 upstreams ​

A server whose upstream authentication is OAuth 2.0 (upstreamAuth.type: "oauth2") is connected from the dashboard; the client API gateway above then calls the upstream with the stored connection. A call that needs a connection that is missing or expired fails with "OAuth sign-in required". The settings and the screens are described in MCP servers. The dashboard API (a signed-in session, not an API token) has these routes:

RouteWhat it does
POST /mcp/oauth/discoverFinds a server's authorization server from its URL (RFC 9728 and RFC 8414).
GET /mcp/oauth/callbackWhere the authorization server sends the browser back.
GET /mcp/:id/oauth/connectionThe connection's status. A token is never returned.
POST /mcp/:id/oauth/connectAuthorization code: returns where to sign in. Client credentials: connects.
DELETE /mcp/:id/oauth/connectionDisconnects; the grant is revoked where the server offers it.
POST /mcp/:id/oauth/testLists the upstream's tools with the connection.
GET /mcp/:id/oauth/user-connectionsThe people's own connections of a server (MCP admins).
DELETE /mcp/:id/oauth/user-connections[/:userId]Removes everyone's connection, or one person's.
GET /users/me/mcp-connectionsThe caller's own connections, per server.
POST /users/me/mcp-connections/:serverId/connectWhere the caller signs in with their own account.
DELETE /users/me/mcp-connections/:serverIdDisconnects the caller's own connection.

Errors ​

StatusDescription
400Missing tool field, a body that is not a JSON object, a tool the server does not list, or invalid JSON-RPC
401Invalid API token
403MCP server is disabled
404MCP server not found, or unknown session
429 / 503Too many open SSE streams (GET …/sse); retry after the Retry-After interval
500Internal server error
502Upstream tool execution failed

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub