Skip to main content

Module mcp

Module mcp 

Source
Expand description

Minimal MCP (Model Context Protocol) stdio server (SPEC §0.2/§7.4): lets an agent inspect and correct its own routing — read the audit traces, and submit feedback — over JSON-RPC 2.0.

Hand-rolled over serde_json (newline-delimited JSON-RPC on stdin/stdout). The surface is three methods — initialize, tools/list, tools/call — so a dependency-free handler we can unit-test by value beats pulling in an async MCP framework. handle_rpc is the pure core; serve_stdio is the thin transport loop around it.

Functions§

handle_rpc
Handle one JSON-RPC message. Returns the response for a request, or None for a notification (a message with no id, which must not be answered). Tool calls touch the trace store at db_path; everything else is pure.
serve_stdio
Serve MCP over stdio: read newline-delimited JSON-RPC from stdin, write responses to stdout. Blocks until stdin closes. Synchronous by design — one request in flight at a time.