Skip to main content

run

Function run 

Source
pub fn run() -> Result<()>
Expand description

Run the MCP server until stdin closes.

Threading model (Goal 2.1):

  • Main thread: reads stdin line-by-line, parses JSON-RPC, calls handle_request to compute a response, hands it to the writer via the mpsc channel.
  • Writer thread: single owner of stdout. Drains responses + push notifications from the channel, writes each as one line + flush. Single writer = no interleaving between responses and notifications.
  • Watcher thread: holds an InboxWatcher::from_head (starts at EOF — each MCP session only sees fresh events). Polls every 2s. For each new inbox event, checks the shared subscription set; if any matching wire://inbox/<peer> or wire://inbox/all URI is subscribed, pushes a notifications/resources/updated message into the channel.