Writing · 16 November 2026 · 5 min read
Build a tiny MCP server in an afternoon
One Python file, one tool that looks up an order in a CSV, and what actually goes over the wire when a model calls it. Run on the current MCP spec, with the two mistakes that cost the most time.
This is the answer to an MCP tool call, as it came back from a server built for this post (trimmed at the end):
{"jsonrpc":"2.0","id":2,"result":{"content":[{"text":"A-1001 for Rao Traders: shipped (updated 2026-11-12)","type":"text"}],"isError":false,"resultType":"complete", ...}}
One line of JSON in, one line out. MCP (the Model Context Protocol) sounds bigger than it is. It's a standard way for an AI app like Claude Code or VS Code to ask a separate program "what can you do?" and then "do it, with these arguments". The separate program is the server. Here is one small enough to read in a minute, and what happens when it runs.
The whole server
The task is something a support bot really needs: look up an order's status. The data is a three-row CSV with made-up orders (order_id,customer,status,updated). This uses the official Python SDK, mcp version 2.3.0, the current release on PyPI on 16 November 2026:
import csv
from pathlib import Path
from mcp.server import MCPServer
ORDERS = Path(__file__).with_name("orders.csv")
mcp = MCPServer("orders")
@mcp.tool()
def order_status(order_id: str) -> str:
"""Look up the current status of one order by its ID, e.g. A-1002."""
with ORDERS.open(newline="") as f:
for row in csv.DictReader(f):
if row["order_id"] == order_id.strip().upper():
return f"{row['order_id']} for {row['customer']}: {row['status']} (updated {row['updated']})"
return f"No order found with ID {order_id}"
if __name__ == "__main__":
mcp.run()
That's the server. mcp.run() with no arguments uses the stdio transport: the AI app starts this file as a child process and talks to it over standard input and output.
Two things in there matter more than they look. The type hint order_id: str becomes the tool's input schema, and the docstring becomes its description. When a client asks for the tool list, it gets this back:
{"name": "order_status",
"description": "Look up the current status of one order by its ID, e.g. A-1002.",
"inputSchema": {"type": "object",
"properties": {"order_id": {"title": "Order Id", "type": "string"}},
"required": ["order_id"]}}
That description is the only thing the model reads when deciding whether to call your tool. "Gets order" is a worse description than one with an example ID in it, and no amount of server code makes up for a vague one.
Calling it without any AI
You don't need a model to test this. The same package includes a client. This script starts the server, lists its tools and makes a few calls:
import asyncio
from mcp import Client, StdioServerParameters
async def main():
params = StdioServerParameters(command="python", args=["server.py"])
async with Client(params) as client:
r = await client.call_tool("order_status", {"order_id": "a-1003"})
print([c.text for c in r.content], r.is_error)
asyncio.run(main())
On the box it ran on, the full script took about 1.2 seconds, most of it Python starting up. Lowercase a-1003 found the order because the tool upper-cases the input. An unknown ID returned the "No order found" text with isError false, which is a choice: the call worked, there just wasn't an order. Sending the wrong argument name (order instead of order_id) came back with isError true and a Pydantic message saying order_id was a required field. The SDK checks arguments against the schema before your function runs.
The other route is MCP Inspector, the official testing tool. Its CLI mode runs a single call from the terminal:
npx @modelcontextprotocol/inspector --cli python server.py \
--method tools/call --tool-name order_status --tool-arg order_id=A-1003
That returned the same order. One caveat: Inspector 2.15.0 lists Node 22.23 or newer as a requirement, and this run was on Node 20. It worked, with engine warnings. The browser version of Inspector (mcp dev server.py in the Python SDK) wasn't tried here.
What goes over the wire
If you read an MCP tutorial from 2025, it will start with an initialize handshake. That's gone. The spec revision dated 2026-07-28 made the protocol stateless. Every request now carries the protocol version and the client's capabilities in a _meta field, and servers must answer a server/discover request that lists the versions and features they support.
So you can talk to the server by hand. Pipe a single JSON line into python server.py, with a tools/call method, the tool name, the arguments and that _meta block, and the response at the top of this post comes back. It includes content (what the model sees), structuredContent (the same value as JSON, for code) and the new required resultType field.
Doing this by hand is how the first time-waster showed up. Two requests piped in with printf got only one answer, because stdin closed and the server shut down before handling the second. Keep stdin open while you test, or just use the client.
The mistake that breaks stdio servers
The spec's stdio page is blunt about it: the server must not write anything to stdout that isn't a valid MCP message. Stdout is the wire.
So a print("debug: ping called") inside a tool is a protocol bug, not a debug line. In a test server with exactly that, the Python client logged a validation error ("Invalid JSON: expected value at line 1 column 1", with the debug text as the input) and then still got the tool's answer. This client recovered. It wasn't tested whether every host does the same, so don't count on it. Log to stderr instead, which the spec allows for exactly this purpose.
What this doesn't cover
This is a local server on one machine. It has no authentication, because stdio servers run with whatever access the person who launched them has. A remote server that other people connect to over HTTP needs the spec's authorization rules, and that's a separate post later in this series. Resources and prompts, the other two things a server can offer, weren't used here either. Connecting the server to Claude Desktop or Cursor through their config files wasn't tested for this post.
Try it this week
Pick one lookup your team does by hand ten times a day, like an order status, a stock count or a ticket owner. Write it as a single tool with a description that includes an example input. Call it with the client script above before you connect any AI to it. If the tool's answers are wrong when you call it directly, a model calling it won't fix that.
explainer
Found this useful? Pass it on.