Lesson 07.02 · Phase 07 · Model Context Protocol

The protocol: JSON-RPC over stdio

An MCP connection is a child process and two pipes. Each line on stdout is one JSON-RPC message, and anything else on stdout corrupts the stream. Learn the four message kinds, the error codes and the framing, and every SDK becomes readable.

Learning objectives

  • Frame JSON-RPC 2.0 messages as newline-delimited JSON and classify them as request, notification, response or error.
  • Spawn a server as a child process and exchange messages over its stdin and stdout, with logs on stderr.
  • Return the right error codes: parse error, invalid request, method not found, invalid params, unsupported protocol version.
  • Match responses to requests by id when they arrive out of order, follow progress notifications, and cancel a request.

Lesson 1 called servers as Python objects. Real MCP servers are separate programs, often in another language, started by the host. The host needs a way to send them a request and get the answer back, with no network setup, no ports, and nothing to configure except a command line.

Loading the full lesson…