Build an MCP server
Stage 5 of 5v1 · 8f4ab190

Harden the protocol

Distinguish JSON-RPC errors, tool errors, and notifications.

Three failure classes

Complete the server without terminating the process after a bad message.

  • Unreadable JSON: error -32700, id null, and message Parse error.
  • Unknown method with an id: error -32601 and message Method not found.
  • Known tool with invalid arguments: an MCP result with a text block and isError:true.

A notification has no id. Recognize notifications/initialized, update internal state if useful, and write no response. Then continue processing messages.

Acceptance criteria

  • One error does not prevent processing the next line.
  • Protocol errors preserve the id when present.
  • Notifications generate no bytes on stdout.