Model Context Protocol (MCP) Context Economics
Explore how to build MCP servers and connect them to AI agent clients using shared tool definitions. You’ll measure registry and response taxes, compare static and deferred tool registration, evaluate prompt cache effects, and route real model tool calls through MCP.
We'll cover the following...
In the last two lessons, we split the incident review across several workers. Each worker uses some of the same tools: the investigator searches runbooks, the validator reads metrics, and the auditor reads notes. So far, every tool has been defined in Python inside our own code. If several workers, or several teams’ agents, need the same tools, each one ends up with its own copy of every schema, and a single change has to be made everywhere.
The Model Context Protocol (MCP) solves this. It’s an open standard for connecting agents to tools and data. A server exposes tools once, and any client, such as our coordinator, a worker, or another team’s agent, connects and reads the same definitions. MCP servers can also offer resources (data to read) and prompts, but we’ll focus on tools.
Serving tools this way has a cost. In this lesson, we’ll build three small MCP servers, list their tools from a real client, and measure two costs: what connected servers add to every request, and what an oversized tool response adds to every call. Then we’ll weigh a common way to cut the first cost against what it does to the prompt cache.
Build three MCP servers
We’ll use the official mcp Python package. Its FastMCP class turns ordinary Python functions into MCP tools. Each function’s name becomes the tool’s name, its docstring becomes the description, and its type hints become the input schema.
Our first server exposes the runbook tools. It wraps the search we’ve used since Chapter 1 and a read_note tool, without rewriting either.
In the code above:
Line 5: We create a server named
oncall-docs. We set its log level to warnings only, so it doesn’t print a line for every request.Lines 9–12: We turn
search_documents()into an MCP tool with the@mcp.tool()decorator. It calls the existing keyword search.Lines 15–18: We turn
read_note()into a tool that returns a note’s text, or an error for an unknown ID.Lines 21–22: We start the server over stdio, so a client can launch it as a subprocess and talk to it through standard input and output. ...