Skip to main content

Module mcp

Module mcp 

Source
Expand description

MCP JSON-RPC 2.0 ↔ ATD translation.

SP-streamable-http §4.2: ATD-native Request::Hello / Request::ToolList / Request::RunTool (atd-protocol::messages.rs:34-52) does not appear on the HTTP wire. Instead the listener translates the four MCP methods (initialize, notifications/initialized, tools/list, tools/call) into ATD operations, then dispatches via atd_runtime::dispatch::run_tool for tool calls. Bytes returned from Tool::call are byte-identical to the UDS path — the parity test in tests/e2e_parity.rs is the regression guard.

Structs§

JsonRpcError
JsonRpcRequest
Incoming JSON-RPC envelope (MCP POST /mcp body). jsonrpc is retained for downstream introspection but the listener does not branch on it — MCP rev 2025-06-18 pins it to "2.0".
JsonRpcResponse
Outgoing JSON-RPC envelope. result and error are mutually exclusive — exactly one is Some per MCP 2025-06-18.

Functions§

error_response
Convenience builder for a JSON-RPC error response paired with an HTTP status. SP-streamable-http §5.6 codifies the (status, code) pairs: origin → 403/-32001; missing bearer → 401/-32002; unknown method → 200/-32601; capability denied / broker error / internal → 200/-32603.
error_response_with_headers
error_response with optional response headers (e.g. WWW-Authenticate, Retry-After). SP-token-broker-phase2 §4.4 requires distinct headers for each bearer-auth error class so adopter-side UIs can distinguish “expired” / “revoked” / “unknown” without re-parsing the message body.
handle_initialize
Build the initialize reply. Echoes serverInfo (name + version), an empty capabilities.tools map, and — when a TokenBroker is wired — the broker’s accepted_token_formats() as an experimental hint (SP-token-broker-phase2 §8.2 last entry).
handle_initialized_notification
notifications/initialized is one-way per MCP; we return an empty JSON-RPC result so the client’s request future resolves cleanly.
handle_tools_call
tools/call — the load-bearing path.
handle_tools_list
tools/list — wraps Registry::summaries filtered by visibility into the MCP { tools: [...] } shape. Each entry exposes {name, description, inputSchema, ...atd_fields...} so MCP clients see the standard fields and ATD-aware clients still see the full definition. Mirrors celia-cli/src/http_server.rs:437-455 with the ATD ToolSummary payload preserved.
ok_response
JSON-RPC success envelope.
wrap_tool_response
Translate an ATD Response (from run_tool) into the MCP wire shape the HTTP listener returns. Mirrors celia-cli/src/http_server.rs:497-525 for the success / execution_failed branches; non-result Response variants (capability denied, broker error, internal) map to the JSON-RPC error envelope per SP-streamable-http §5.6.