JSON-RPC 2.0 Over Newline-Delimited Stdio

The transport between a model client and a tool server is JSON-RPC over stdio. Hand-rolling it once teaches you what every framing layer is paying for.

Build 1.5 hr Python

Prerequisites: Phase 13 lessons 01-07, Phase 14 lesson 01

#Learning Objectives

  • Speak JSON-RPC 2.0 framed as newline-delimited JSON over stdin and stdout.
  • Map the five standard error codes (-32700, -32600, -32601, -32602, -32603) and surface them with the right semantics.
  • Distinguish requests, responses, notifications, and batches without inventing new envelope keys.
  • Handle one parse error per line without poisoning the rest of the stream.
  • Build a self-terminating demo using io.BytesIO so the lesson runs without spawning a child process.
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.