Module DD-22 — MCP: Building Production Tool Servers

MCP: Building Production Tool Servers

The wire protocol that turns hardcoded tool registries into discoverable, versioned, independently-deployable services. The platform turn. JSON-RPC 2.0, stdio/HTTP+SSE, tools/resources/prompts, capability negotiation, JSON Schema validation, registry/discovery, production failure modes. With a real TypeScript MCP server.

50
minutes
8
artifacts
7
sub-sections
A tool is a function the model can call. A tool server is a process that exposes tools, resources, and prompts over a wire protocol — discoverable, versioned, independently deployable. MCP is that wire protocol. This deep-dive builds production tool servers: the lifecycle, the capability negotiation, the schema validation, the registry, and the failure modes that turn a clever integration into a production outage.
Key Claims
Load-Bearing Claims

The platform turn. Pi's four tools are compiled-in function references. Adding one means editing source, shipping a build, restarting. MCP externalizes tools into services. A vendor ships a server; the agent discovers it at runtime. This is the structural difference between a personal harness and a platform.

Three primitives, three trust boundaries. Tools (model-initiated, untrusted input, schema-validated). Resources (user/client-initiated, semi-trusted). Prompts (user-initiated, server-authored, trusted). Confusing them — exposing as a tool what should be a resource — is a security bug: the model can now act autonomously when it shouldn't.

Capability negotiation is the contract. The initialize handshake exchanges what both sides support. The session may only use the intersection. A client built once works against every server — present, future, third-party — using whatever subset both offer.

JSON Schema is the validation boundary, not documentation. additionalProperties: false is a security control — it prevents a steered model from injecting unexpected fields (e.g., a hidden bcc on send_email). The server re-validates on every call. Never trust the model or the client to validate.

Three error classes, three recovery paths. Unknown tool (model stops calling), validation failure (model retries with fixed args), execution failure (model retries or reports). Each returns a distinguishable isError payload. Conflating them produces a confused loop.

The four production failure modes: stdout corruption (a console.log on stdio breaks the stream), schema drift (version mismatch across servers), subscription flood (volatile resource drowns the context), no graceful shutdown (orphaned requests and leaked resources). Each has a known fix.

After This Module
01
State the MCP thesis and explain why externalizing tools is the difference between a personal harness and a platform.
02
Describe the three primitives (tools, resources, prompts), two transports (stdio, HTTP+SSE), and the JSON-RPC 2.0 envelope.
03
Walk the full server lifecycle: initialization, capability negotiation, message loop, graceful shutdown.
04
Write a JSON Schema for tool input and explain why additionalProperties: false is a security control.
05
Implement a production MCP server in TypeScript with schema validation, three-class error handling, stderr logging, and SIGTERM-driven graceful shutdown.
06
Explain the registry/discovery pattern and how capability negotiation enables version-drift tolerance.
07
Diagnose the four production failure modes and name the fix for each.
Artifacts
01
Teaching Document
Teaching document — 7 sub-sections covering the MCP thesis, the protocol (JSON-RPC 2.0 + stdio/HTTP+SSE + three primitives), the server lifecycle, JSON Schema as validation boundary, a full production TypeScript server, registry/discovery/version drift, resources and the subscription flood, production patterns and the C4 E07 connection; with anti-patterns, key terms, references
READ
02
Diagrams
6 Mermaid diagrams — Pi-registry vs MCP-server (the externalization), three trust boundaries, server lifecycle, capability negotiation intersection, validation boundary (3 error classes), production failure modes; design-system colors
READ
03
Slide Deck
10 slides — reveal.js, dark theme, design-system teal; thesis, three primitives, trust boundaries, lifecycle, capability negotiation, validation boundary, three error classes, production operations, platform turn
READ
04
Teaching Script
Verbatim teaching transcript with [SLIDE N] cues, ~2,700 words across 10 slides
READ
05
Flashcards
22 flashcards (TSV) — mix of recall, application, analysis; covers primitives, transports, lifecycle, capability negotiation, validation, error classes, failure modes, registry, production patterns
TEST
06
Exam
15 questions, 20/40/40 Bloom distribution (3 recall / 6 application / 6 analysis), 70% pass; validated JSON with rationale per question
TEST
07
Lab Spec
Build a TypeScript MCP server — runnable lab with the official SDK: two tools, JSON Schema validation, three-class error model, graceful shutdown, test client exercising the full lifecycle; stdout corruption demo, capability negotiation experiment, 5 stretch goals (resource, prompt, subscription debouncing, idempotency key, HTTP+SSE transport)
DO
08
Module Web Page
Single-file HTML hub
HERE