Skip to main content

Module mcp

Module mcp 

Source
Expand description

Model Context Protocol (MCP) server for grr.

Hand-rolled JSON-RPC 2.0 over stdio — no SDK crate: a tool-only server needs five methods. Newline-delimited requests in, one response line per request out, logs to stderr ONLY (stdout is the MCP stream, the same discipline as the rest of grr).

  • initialize — protocol-version negotiation + capabilities (the handshake revisions, up to 2025-11-25)
  • server/discover — 2026-07-28’s mandatory replacement for the handshake: revisions served, capabilities, identity, no prior call
  • notifications/initialized — a notification; never answered
  • tools/list — every method in the Discovery index as a tool
  • tools/call — one method invocation through the shared call path
  • ping — an empty result (2026-07-28 dropped ping; a server that serves several revisions keeps answering it for the older ones)

Tool names are the dotted method ids grr api call takes (gmail.users.messages.list), so an agent reaches every method Google publishes through the same resolution the CLI uses. Errors never kill the server: a tool failure is an isError result (MCP’s tool-error contract), a protocol failure a JSON-RPC error object.

{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25"}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
{"jsonrpc":"2.0","id":3,"method":"tools/call",
 "params":{"name":"gmail.users.messages.list","arguments":{"userId":"me","dry_run":true}}}

Structs§

McpServer
One server instance: one credential, one safety profile, every tool. The stdio loop is single-tasked, so no Arc is needed.

Functions§

serve
The stdio loop: newline-delimited JSON-RPC in, one response line per request out. Generic over the reader/writer so tests can run the whole handshake in-process. EOF on stdin (the client closed the session) is a clean shutdown.