Module mcp

Module mcp 

Source
Expand description

MCP gateway (DW-087): a hand-rolled Model Context Protocol server/router over JSON-RPC 2.0.

dwara exposes configured tools on a reserved HTTP path (default /mcp). The gateway is a ROUTER, not a tool executor: each tool names an upstream HTTP endpoint, and tools/call proxies the call (POST JSON body, get JSON response). AuthN is enforced on every request (the existing security/authn module); AuthZ is per-tool (the existing security/authz module). Agent sessions are state-store backed (the mcp_sessions table); tool calls are correlated in analytics (the mcp_tool_calls table).

§Protocol

MCP is JSON-RPC 2.0 over HTTP. The lifecycle:

  1. initialize — the client sends its protocol version and client info; the server creates a session, responds with its protocol version, capabilities, and server info, and returns the session id in the Mcp-Session-Id response header.
  2. notifications/initialized — the client acknowledges (a notification: no response).
  3. tools/list — the server returns the tool definitions (filtered by the caller’s authz).
  4. tools/call — the server authorizes, proxies the call to the upstream, and returns the result.
  5. shutdown — the server deletes the session.

§Dependency direction

ai depends on config only. The HTTP call reuses the same hyper_util client pattern as the DW-083 semantic cache and DW-085 routing policy (no new dependencies). The handler returns results; the dataplane records analytics/observability.

Structs§

CompiledMcp
The compiled MCP gateway (DW-087): the tool table, session policy, and reserved path. Built at AiRuntime compile time from the ai.mcp config block; immutable once built.
CompiledMcpPrompt
AI-11 (#200): One compiled MCP static prompt template.
CompiledMcpPromptArgument
AI-11 (#200): One compiled prompt argument definition.
CompiledMcpResource
AI-11 (#200): One compiled MCP static resource. Served inline (no upstream proxy).
CompiledMcpTool
One compiled MCP tool (DW-087): the resolved upstream URL, the HTTP method, the timeout, and the optional authz attachment.
JsonRpcRequest
One JSON-RPC 2.0 request (DW-087). id is None for notifications.
McpHandleResult
The result of handling one JSON-RPC request (DW-087): the response body (JSON) and optional analytics/observability outcomes the dataplane records.
McpToolCallOutcome
The outcome of an MCP tool call (DW-087): the result the dataplane records in analytics and returns to the client.

Functions§

json_rpc_error_pub
Build a JSON-RPC error response (public, for the dataplane’s session-management error paths).
json_rpc_result_pub
Build a JSON-RPC success response (public, for the dataplane’s authz-filtered tools/list and denied tools/call paths).
parse_error_response
Build a JSON-RPC parse error response (no id available).