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:
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 theMcp-Session-Idresponse header.notifications/initialized— the client acknowledges (a notification: no response).tools/list— the server returns the tool definitions (filtered by the caller’s authz).tools/call— the server authorizes, proxies the call to the upstream, and returns the result.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§
- Compiled
Mcp - The compiled MCP gateway (DW-087): the tool table, session
policy, and reserved path. Built at
AiRuntimecompile time from theai.mcpconfig block; immutable once built. - Compiled
McpPrompt - AI-11 (#200): One compiled MCP static prompt template.
- Compiled
McpPrompt Argument - AI-11 (#200): One compiled prompt argument definition.
- Compiled
McpResource - AI-11 (#200): One compiled MCP static resource. Served inline (no upstream proxy).
- Compiled
McpTool - One compiled MCP tool (DW-087): the resolved upstream URL, the HTTP method, the timeout, and the optional authz attachment.
- Json
RpcRequest - One JSON-RPC 2.0 request (DW-087).
idis None for notifications. - McpHandle
Result - The result of handling one JSON-RPC request (DW-087): the response body (JSON) and optional analytics/observability outcomes the dataplane records.
- McpTool
Call Outcome - 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).