Skip to main content

Module dispatch

Module dispatch 

Source
Expand description

MCP method dispatch: decode an incoming JSON-RPC frame, route it to its handler, and produce the outgoing frame(s).

Pure + panic-free: every path returns a value; malformed input yields a JSON-RPC parse-error response. This is the unit the connection loop (server::serve_connection) drives; keeping it pure makes the protocol contract testable without a socket.

I1 handles initialize / tools/list / prompts/list and emits notifications/tools/list_changed after the client’s initialized notification. tools/call is stubbed (reads I2, writes I3, diff I4).

Structs§

DispatchContext
The state the dispatcher needs to answer tools/call: the read tools’ ReadContext + the write bus. Built once at server spawn and shared (behind an Arc) across connections. The I1 methods (initialize / tools/list / prompts/list) ignore it.

Enums§

Outgoing
A frame the server should send back to the agent in response to an incoming frame.

Functions§

dispatch_frame
Decode + route one incoming frame, returning the frames to send back.
handle_request
Route one request to its MCP response.
is_blocking_tool_call
True if frame is a tools/call request for the blocking openDiff tool — the only tool whose handler (crate::mcp::diff::open_diff) awaits an unbounded, user-paced verdict with no timeout. The connection dispatches these on their OWN task so the per-connection read loop is never blocked by a pending review: it keeps polling the socket + shutdown signal (so a dropped connection or :claude-code-stop is observed promptly and the pending review can be rejected), and other tool calls still flow. Every non-blocking tool stays inline + ordered. Malformed / non-matching frames return false (dispatched inline, where the parse error is reported).