Skip to content

The MCP Handshake

Lives in src/provider/mcp.

A hand-rolled, dependency-free client for Fastmail’s official MCP endpoint (Streamable HTTP): captures the server-issued mcp-session-id header and echoes it on every later call, sends the dual Accept: application/json, text/event-stream header the server requires, parses SSE data: frames by taking the last JSON line, unwraps structuredContent (falling back to the text body), and converts isError results into typed transport errors.

A faithful, typed port of the session script reference/mcp.mjs that did all 9,400+ mutations.

Fastmail wraps even single results in SSE frames — and the MCP token is a distinct credential from the JMAP token.