Skip to content

Mcp

Implements the Model Context Protocol over JSON-RPC 2.0. All operations go through a single POST /mcp endpoint, differentiated by the request body.

  • Spec: modelcontextprotocol.io
  • MIME: application/json
  • Serializer: McpSerializer
  • Routing: Body-matched (single endpoint)
import crate.protocols.mcp.policy;
auto crateRouter = router.crateSetup!Mcp;
crateRouter.add(userCrate);

All operations use POST /mcp with a JSON-RPC body. The params.name field determines the operation:

Tool NameOperation
list_usersList all
get_userGet one
create_userCreate
replace_userReplace
update_userUpdate fields
delete_userDelete
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_user",
"arguments": { "id": "abc123" }
},
"id": 1
}

MCP registers additional protocol-level operations via onRouterInit:

EndpointBody MatchPurpose
POST /mcpmethod: "initialize"Protocol handshake
POST /mcpmethod: "tools/list"List available tools
GET /mcp/sseServer-Sent Events stream
GET /.well-known/oauth-protected-resourceOAuth 2.1 metadata

The tools list is populated lazily via onRouterReady after all models are registered.

  • Resources: Only tools are exposed; no MCP resource endpoints
  • Prompts: No prompt support
  • Sampling: No sampling / LLM model endpoints
  • Notifications: Server-to-client via SSE only; no client-initiated notifications
  • Progress tracking: No progress reporting mechanism
  • Logging: No structured logging API
  • Cancellation: No request cancellation
auto crateRouter = router.crateSetup!(McpPolicy!(PolicyConfig("/tools")));
// Endpoint at POST /tools/mcp