Module sse

Source
Expand description

SSE (Server-Sent Events) transport for the MCP server.

§MCP SSE Protocol

  • GET /sse — establish SSE stream, receive endpoint event with POST URL
  • POST /messages?session_id=<id> — send JSON-RPC requests

§Thread safety

rusqlite::Connection is not Send+Sync, so we can’t share it across async tasks. Instead, we open a fresh read-only connection per request inside spawn_blocking. Since SQLite reads take <1ms and the connection open is ~0.5ms, this overhead is negligible for an SSE server that handles maybe 1-5 requests/second.

§Reference

MCP SSE spec: https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse

Structs§

AppState 🔒
Shared application state (thread-safe — no rusqlite in here).

Functions§

handle_message 🔒
POST /messages?session_id= — receive JSON-RPC, respond via SSE.
handle_sse 🔒
GET /sse — establish SSE connection, return event stream.
run_sse
Run the MCP server in SSE mode (async, multi-session).

Type Aliases§

SessionMap 🔒
Per-session state: an SSE sender channel.