Building an MCP Server: Stateless Python and TypeScript
A modern MCP server does not remember a handshake. It validates the metadata on every request, runs one handler, and returns one typed result. Implement mandatory server/discover for MCP 2026-07-28. Validate protocol version and client capabilities on every request. Expose tools, resources, and prompts with deterministic list ordering. Return resultType, server identity, and cache hints on the correct results. Serve the same stateless contract over newline-delimited stdio in Python and TypeScript. A server that stores client capabilities after the first message is easy to build and hard to operate. The same process may serve sequential clients. A remote request may land on a different worker. A stale capability declaration can leak behavior across authorization boundaries. MCP 2026-07-28 solves the protocol part of that problem by making every request self-describing. Your application can still keep durable notes, jobs, or explicit state handles. What it cannot keep is hidden protocol state that changes how a later request is decoded. This lesson builds a notes server twice. The Python and TypeScript versions use only their standard libraries for the protocol core. Both expose the same methods and enforce the same wire contract. Three stdio rules still matter: Write only JSON-RPC messages to stdout. Send diagnostics to stderr. Delimit messages with a newline and flush each response. Exit promptly when stdin reaches EOF. The…
Building an MCP Server: Stateless Python and TypeScript: A modern MCP server does not remember a handshake. It validates the metadata on every request, runs…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.