Day 1: Why MCP – host, client, server and your first server
Goal: understand the architecture of MCP, write a first server with the Python SDK, talk to it by hand over stdio and capture what a real client sends · Duration: approx. 2 h · Prerequisite: Day 0 (project
~/mcpawith SDK 2.3.0)
Where we start
# on cp1
cd ~/mcpa# on cp1, in ~/mcpa
uv run mcp versionExpected:
MCP version 2.3.0
If the project is missing, create it as in Day 0, Drill 7:
uv init --bare --python 3.12 . and
uv add "mcp[cli]==2.3.0" in ~/mcpa.
Introduction
Yesterday you did by hand what an application has to do so that a language model can use a tool: describe it, recognize the request, execute it, return the result. Today you learn how MCP splits this work between two sides – and you build one side, the server, yourself.
You write it with the official Python SDK in fewer than 20 lines. Then you talk to it without any help: you type the protocol messages yourself and send them to the program via standard input. Finally you write a small client and capture what it really sends. You will see: it sends exactly what you typed by hand before. This knowledge is worth its weight in gold in the exam, because many questions revolve around which message carries which fields when.
Today you learn:
- which problem MCP solves and what it explicitly does not cover,
- the three roles host, client and server and how they relate,
- the primitives of MCP: tools, resources, prompts on the server side, follow-up requests on the client side – and who controls each of them,
- the two layers of the protocol: data layer (JSON-RPC) and transport layer (stdio, HTTP),
- to write a server with
MCPServerand understand how a Python function becomes a tool with a schema, - to use the methods
server/discover,tools/listandtools/callby hand, - to write a client with
Clientand capture its traffic.
Background
The picture for today: the hotel gets a front desk
Yesterday you were the bellhop who handled every wish of the guest on foot. Today the hotel gets organized. At the entrance sits the front desk (the host): it talks to the guest (the language model and the human behind it), keeps track of the conversation and decides what is allowed. For each outside contractor there is a separate house line (a client): one to the laundry, one to the taxi company. Over its house line the laundry never learns where the taxi is driving.
Every contractor (server) presents its offers by fixed rules: bookable services (tools), an information folder to read (resources) and forms for frequent requests (prompts). How an order sounds on the phone is the same for everyone – that is the protocol. Whether the laundry is in the building (stdio, a subprocess) or across town (HTTP) changes nothing about the order.
The terms
| Term | Meaning | in the picture |
|---|---|---|
| Host | the human’s application, talks to the model, decides what is allowed | front desk |
| Client | part of the host for exactly one server | house line to one contractor |
| Server | program that offers capabilities | outside contractor |
| Tool | model-controlled action | bookable service |
| Resource | application-controlled data as context | information folder |
| Prompt | user-controlled template | form |
| stdio / Streamable HTTP | local / remote transport | contractor in the building / across town |
server/discover |
asks what a server can do | “What do you offer?” |
Remember: One front desk, one house line per contractor, and each contractor only hears its own line.
What MCP is – and what it isn’t
The Model Context Protocol is an open protocol that
defines how applications that use language models get access to tools,
data and templates. It was published at the end of 2024 and since 2026
has been developed further by the Agentic AI Foundation under the
umbrella of the Linux Foundation. The specification lives at
modelcontextprotocol.io/specification; each version is
named after a date. This course and the exam are based on
2026-07-28.
For the exam it is also important what MCP does not cover:
- Which model is used and how to talk to it – that remains the host’s business.
- How the model decides whether to call a tool. MCP only supplies the descriptions.
- What a tool does internally. Whether a server queries a database or runs a command is its own business; MCP only defines what the call and the result look like.
- The user interface. How a host displays tools or asks for consent is not prescribed by the specification – it only requires that the host can do it.
Host, client, server
MCP knows three roles:
- The host is the application a human works with: a chat program, an IDE, an agent. It talks to the language model, manages the conversation, displays results and decides what is allowed. The host is the trusted authority – it represents the human.
- A client is the part of the host that talks to exactly one server. If a host connects to three servers, it has three clients. Each client holds its own connection and knows only its server.
- A server is a program that offers capabilities – tools, data, templates. It can run locally as a subprocess or be reachable remotely over HTTP. A server never sees the whole conversation and never the other servers; it only sees its client’s requests.
This separation is no accident. It ensures that a server that, for example, connects the ticket system cannot read what another server delivers about the HR database. The merging happens exclusively in the host, and that is where the human sits.
The primitives
MCP divides what a server offers into three primitives (basic building blocks). They differ mainly in who decides when they are used:
| Primitive | Who controls | Purpose | Example |
|---|---|---|---|
| Tools | the model | perform actions, compute values | freier_speicher, ticket_anlegen |
| Resources | the application | provide data as context | contents of a log file, a configuration |
| Prompts | the human | templates for recurring tasks | “write an incident report” |
Tools are called model-controlled because the model itself decides whether and when to call them. Resources are application-controlled: the host decides which data it gives the model. Prompts are user-controlled: a human selects them, for example via a menu or a slash command. This mapping is a popular exam question.
The client side also offers something, namely follow-up requests that the server can direct via the client to the human or the model:
- Elicitation – the server asks the human for input, for example a confirmation,
- Sampling – the server asks the host’s model for a response,
- Roots – the server asks which directories it should use.
Sampling and roots have been marked deprecated since 2026-07-28; they remain valid for at least another twelve months. Day 10 covers all three.
Two layers: data and transport
MCP is built in two layers:
- The data layer defines which messages exist and
what they look like. All messages are JSON-RPC 2.0:
JSON objects with a method (for example
tools/call), parameters and an identifier that matches the response to the request. Day 2 takes JSON-RPC apart. - The transport layer defines how these messages get
from A to B. The specification knows two standard transports:
- stdio: the client starts the server as a subprocess and writes messages to its standard input, one per line. Responses come back via standard output. This is the transport for local servers.
- Streamable HTTP: the client sends each message as an HTTP POST to an address of the server. This is the transport for remote servers (Day 8).
The data layer is the same for both transports. A server that works over stdio works with the same messages over HTTP as well.
What changed with 2026-07-28
When you read older guides, you encounter a
handshake: the client first sent an
initialize request, both sides negotiated version and
capabilities, then came the notifications/initialized
notification, and only then did work begin. Over HTTP there was also a
session ID.
That no longer exists since 2026-07-28. The protocol
is now stateless: every request carries in a
_meta field which protocol version the client speaks and
which capabilities it has. A server must not rely on what was in earlier
requests. Anyone who wants to know in advance what a server can do calls
the new method server/discover – it is
mandatory for every server, but optional for clients. Today you see all
of this in real messages.
The Python SDK
You could write a server without a library: read lines from standard
input, parse JSON, print responses. The official Python
SDK does this for you. Its most important class for servers is
called MCPServer. You write ordinary Python functions and
mark them as a tool with a decorator – a line with
@ above the function. The SDK then reads the function name,
parameters, their types and the docstring (the text in triple quotes)
and builds the tool description including JSON Schema from them. For
clients there is the class Client.
Drill 1: The first server
Where you are: on cp1, in the directory
~/mcpa/tag01.What you have afterwards: the file
leitstand.py, an MCP server with one tool.
The server of this course is called Leitstand (control room). It supplies operating data of the machine it runs on – today the free disk space, more in the coming days.
Step 1 – create the directory.
# on cp1
mkdir -p ~/mcpa/tag01# on cp1
cd ~/mcpa/tag01Step 2 – write the server. Create the file in the editor:
# on cp1, in ~/mcpa/tag01
nano leitstand.pyimport shutil
from mcp.server import MCPServer
mcp = MCPServer(
name="leitstand",
version="1.0.0",
instructions="Werkzeuge für den Betrieb der Labor-Rechner: Plattenplatz, Laufzeit, Dienste.",
)
@mcp.tool()
def freier_speicher(pfad: str = "/") -> int:
"""Liefert den freien Plattenplatz unter einem Pfad in GB."""
return shutil.disk_usage(pfad).free // 1024**3
if __name__ == "__main__":
mcp.run()Save with Ctrl+O and Enter, quit with Ctrl+X. Go through the file line by line:
import shutilloads a module from the Python standard library; its functiondisk_usagereturns total, used and free space of a file system in bytes.from mcp.server import MCPServerfetches the server class from the SDK.MCPServer(…)creates the server. The three arguments:name– the name the server introduces itself with to clients,version– the version of your server (not of the protocol),instructions– free text explaining what the server is good for (here: tools for operating the lab machines – disk space, uptime, services). Hosts can pass it to the model so that it uses the server better.
@mcp.tool()is the decorator. It registers the function below it as a tool. The parentheses belong to it –toolis a function that first creates the actual decorator; in it you could later override the name or title.def freier_speicher(pfad: str = "/") -> int:– from this line the SDK reads:- the name of the tool:
freier_speicher, - a parameter
pfad(path) of typestr(string) with the default value"/"– because there is a default value, the parameter is optional, - the return type
int(integer).
- the name of the tool:
- The docstring
"""Liefert …"""(“returns the free disk space under a path in GB”) becomes the tool’s description – the text from which the model recognizes what the tool is good for (Day 0, Challenge). shutil.disk_usage(pfad).free // 1024**3converts free bytes to gigabytes:1024**3is 1024 to the power of 3,//is integer division.if __name__ == "__main__":is true when the file is started directly (not imported). Thenmcp.run()starts the server. Without an argument,runuses the stdio transport: the server reads messages from standard input and writes responses to standard output.
Check:
# on cp1, in ~/mcpa/tag01
uv run python -c "import leitstand; print(leitstand.mcp.name)"python -c "…" runs the text in quotes as a Python
program. It imports your file – because of the if __name__
line the server does not start – and prints the name.
Expected:
leitstand
Remember: Function name, types and docstring – that is all the SDK needs to turn a function into a bookable service with schema and description.
Save your progress? Sign up for free
Drill 2: Messages by hand
Where you are: on cp1, in the directory
~/mcpa/tag01.What you have afterwards: the file
nachrichten.jsonland the server’s three responses.
Now you talk to the server as if you were a client. You write three
requests into a file, one per line – that is what the stdio transport
requires. Files with one JSON object per line often have the extension
.jsonl (“JSON Lines”).
Step 1 – write the requests.
# on cp1, in ~/mcpa/tag01
nano nachrichten.jsonl{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{},"io.modelcontextprotocol/clientInfo":{"name":"von-hand","version":"1.0"}}}}
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{},"io.modelcontextprotocol/clientInfo":{"name":"von-hand","version":"1.0"}}}}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"freier_speicher","arguments":{"pfad":"/"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{},"io.modelcontextprotocol/clientInfo":{"name":"von-hand","version":"1.0"}}}}Each request sits on exactly one line – nano must not wrap it.
The lines are long but built the same way. Take the third one apart:
"jsonrpc":"2.0"– every message names the JSON-RPC version; there is only this one."id":3– the request’s identifier. The response carries the same identifier, so the client can match responses to requests, even if they arrive in a different order."method":"tools/call"– the desired operation: call a tool."params"– the method’s parameters:"name":"freier_speicher"– which tool,"arguments":{"pfad":"/"}– its arguments, matching the schema,"_meta"– metadata that every request must carry since 2026-07-28:io.modelcontextprotocol/protocolVersion– the protocol version the client speaks (required),io.modelcontextprotocol/clientCapabilities– what the client can do, for example pass follow-up requests on to the human;{}means “nothing special” (required),io.modelcontextprotocol/clientInfo– name and version of the client (recommended).
The long keys prefixed with io.modelcontextprotocol/ are
reserved names: everything that starts with this prefix
belongs to the protocol. Your own metadata gets its own prefix.
The first two lines call server/discover (what can you
do?) and tools/list (which tools do you have?). They need
no parameters other than _meta.
Step 2 – send to the server. This command is a chain, but every link has a job: the pipe in front of the server is the transport here – exactly how a client writes to the standard input of a stdio server.
# on cp1, in ~/mcpa/tag01
(cat nachrichten.jsonl; sleep 3) | uv run python leitstand.py | jq -c .cat nachrichten.jsonlprints the three lines.sleep 3waits three seconds. The parentheses( … ; … )group both commands so that their entire output goes into the pipe. Why the wait? As soon as the input ends, a stdio server exits – without the pause it would have no time to answer the last request.uv run python leitstand.pystarts the server; its standard input is the pipe.jq -c .prints each response compactly on one line (-c= compact,.= the whole object).
Expected (wrapped; your number at 59
will be different):
{"jsonrpc":"2.0","id":1,"result":{"cacheScope":"private","capabilities":{"prompts":{"listChanged":true},
"resources":{"listChanged":true,"subscribe":true},"tools":{"listChanged":true}},"instructions":"Werkzeuge
für den Betrieb der Labor-Rechner: Plattenplatz, Laufzeit, Dienste.","resultType":"complete",
"supportedVersions":["2026-07-28"],"ttlMs":0,"_meta":{"io.modelcontextprotocol/serverInfo":
{"name":"leitstand","version":"1.0.0"}}}}
{"jsonrpc":"2.0","id":2,"result":{"cacheScope":"private","resultType":"complete","tools":[{"description":
"Liefert den freien Plattenplatz unter einem Pfad in GB.","inputSchema":{"type":"object","properties":
{"pfad":{"default":"/","title":"Pfad","type":"string"}},"title":"freier_speicherArguments"},"name":
"freier_speicher","outputSchema":{"properties":{"result":{"title":"Result","type":"integer"}},
"required":["result"],"title":"freier_speicherOutput","type":"object"}}],"ttlMs":0,"_meta":
{"io.modelcontextprotocol/serverInfo":{"name":"leitstand","version":"1.0.0"}}}}
{"jsonrpc":"2.0","id":3,"result":{"content":[{"text":"59","type":"text"}],"isError":false,
"resultType":"complete","structuredContent":{"result":59},"_meta":{"io.modelcontextprotocol/serverInfo":
{"name":"leitstand","version":"1.0.0"}}}}
Step 3 – read the responses. Each response carries
the id of its request and a result field. It
contains a lot that you need to recognize in the exam:
Response 1 (server/discover):
supportedVersions– the protocol versions the server supports. A client picks one of them. Here only2026-07-28.capabilities– what the server offers:tools,resources,prompts. The SDK reports all three, even though you only have one tool so far.listChanged: truemeans: the server can report when the list changes (Day 9).instructions– your text from the constructor._metawithio.modelcontextprotocol/serverInfo– name and version of the server. The specification recommends sending them in every response; the SDK does so.
In all three responses:
resultType: "complete"– new since 2026-07-28 and required in every response.completemeans: this is the final result. The other possible value,input_required, means “I first need a follow-up request answered” (Day 10).ttlMsandcacheScope– caching hints: how many milliseconds the result stays valid (0= don’t cache) and whether it is the same for all users (public) or only for this one (private). Day 6 uses them. The response totools/calldoesn’t have them, because tool results must not be cached.
Response 2 (tools/list): the tool with
name, description and two schemas. Compare
them with your Python line:
inputSchema–pfad: str = "/"became a propertypfadof typestringwithdefault: "/". Because there is a default value,requiredis missing.outputSchema–-> intbecame an object with a propertyresultof typeinteger. The SDK wraps simple return values in an object because an output schema is supposed to describe an object.
Response 3 (tools/call): the result comes
twice:
content– a list of content blocks for the model, here a text block with"59",structuredContent– the same result as a JSON object, matching theoutputSchema, intended for programs.isError: false– the call succeeded.
Why twice? Older clients only know content. The
specification therefore recommends also delivering structured results as
text. Day 3 goes deeper.
If it doesn’t work
- Only two responses: the pause was too short; the
server was terminated before it could respond. Increase
sleep 3tosleep 5. parse error: Invalid numeric literalfromjq: something other than JSON arrived on standard output – see Drill 4.- No response, only an error message from the server:
usually a line in
nachrichten.jsonlis not valid JSON. Check withjq -c . nachrichten.jsonl.
Remember: Since 2026-07-28 every request carries version and capabilities itself in
_meta, and every response says withresultTypewhether it is final. No handshake, no memory.
Save your progress? Sign up for free
Drill 3: A client in Python
Where you are: on cp1, in the directory
~/mcpa/tag01.What you have afterwards:
client.py, a client that starts and uses the server itself.
Typing messages by hand is instructive, but not a way to work. For
that the SDK provides the class Client.
# on cp1, in ~/mcpa/tag01
nano client.pyimport asyncio
from mcp import Client, StdioServerParameters
server = StdioServerParameters(command="uv", args=["run", "python", "leitstand.py"])
async def main() -> None:
async with Client(server) as client:
tools = await client.list_tools()
for tool in tools.tools:
print("Werkzeug:", tool.name, "-", tool.description)
result = await client.call_tool("freier_speicher", {"pfad": "/"})
print("Ergebnis:", result.structured_content)
asyncio.run(main())What happens here:
import asyncio– the library for asynchronous programs. The SDK is asynchronous: while it waits for a response, the program can do other things. Asynchronous functions are defined withasync defand called withawait.StdioServerParameters(command=…, args=[…])describes how the server is started: the programuvwith the argumentsrun python leitstand.py. The client starts the server itself as a subprocess – exactly how hosts do it with local servers.async with Client(server) as client:opens the connection and closes it again at the end of the block, even on errors. On closing, the client terminates the subprocess.await client.list_tools()sendstools/list. The result has a fieldtools, a list of tools withnameanddescription.await client.call_tool("freier_speicher", {"pfad": "/"})sendstools/callwith name and arguments as a dictionary. The result has the fields from Drill 2; the SDK writes them in Python style (structured_contentinstead ofstructuredContent).asyncio.run(main())starts the asynchronous functionmainand waits until it finishes.
# on cp1, in ~/mcpa/tag01
uv run python client.pyExpected (Werkzeug = tool,
Ergebnis = result):
Werkzeug: freier_speicher - Liefert den freien Plattenplatz unter einem Pfad in GB.
Ergebnis: {'result': 59}
Remember: The client starts a local server itself and stops it again – the front desk calls the in-house laundry only as long as it needs it.
Save your progress? Sign up for free
Drill 4: Capturing what the client sends
Where you are: on cp1, in the directory
~/mcpa/tag01.What you have afterwards: two capture files with the real traffic between SDK client and server.
Which messages does the client really send? You put the program
tee in between. tee passes on everything it
reads unchanged and writes a copy to a file – like a T-piece in a water
pipe.
Step 1 – a copy of the client with capture.
# on cp1, in ~/mcpa/tag01
nano client_mitschnitt.pyThe file is like client.py; the lines in green are the
ones that differ:
import asyncio
from mcp import Client, StdioServerParameters
server = StdioServerParameters(
command="sh",
args=["-c", "tee an-server.jsonl | uv run python leitstand.py | tee vom-server.jsonl"],
)
async def main() -> None:
async with Client(server) as client:
tools = await client.list_tools()
for tool in tools.tools:
print("Werkzeug:", tool.name, "-", tool.description)
result = await client.call_tool("freier_speicher", {"pfad": "/"})
print("Ergebnis:", result.structured_content)
asyncio.run(main())The only change is how the server is started: instead of
uv directly, the client starts the shell sh,
and -c passes it a whole command line. In this line the
first tee writes everything the client sends to
an-server.jsonl and passes it on to the server. The second
tee writes everything the server responds to
vom-server.jsonl and passes it back to the client. The
client notices nothing.
Step 2 – run it.
# on cp1, in ~/mcpa/tag01
uv run python client_mitschnitt.pyExpected:
Werkzeug: freier_speicher - Liefert den freien Plattenplatz unter einem Pfad in GB.
Ergebnis: {'result': 59}
To the client everything looks as before.
Step 3 – read the capture.
# on cp1, in ~/mcpa/tag01
jq -c . an-server.jsonlExpected (wrapped):
{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":
"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"mcp","version":"0.1.0"},
"io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":
"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"mcp","version":"0.1.0"},
"io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"freier_speicher","arguments":{"pfad":"/"},
"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":
{"name":"mcp","version":"0.1.0"},"io.modelcontextprotocol/clientCapabilities":{}}}}
These are exactly your three messages from Drill 2 –
except that the client introduces itself as mcp. Two
observations:
- The client calls
server/discoverfirst. It doesn’t have to, but the SDK does so to check whether the server speaks the new version. If a server doesn’t answer, the client falls back to the oldinitializehandshake. This way new clients can talk to old servers. - There is no handshake and no
initializednotification. Each request carries version and capabilities itself. If you sent the second line on its own, the server would answer it just the same.
vom-server.jsonl contains the three responses you know
from Drill 2. Look at them with
jq -c . vom-server.jsonl.
If it doesn’t work
The most common mistake with stdio servers of all: writing
something other than protocol messages to standard output. To
try it out, add print("Berechne", pfad) (“calculating”) as
the first line of the function freier_speicher and start
client.py. You see:
pydantic_core._pydantic_core.ValidationError: 1 validation error for union[JSONRPCRequest,JSONRPCNotification,JSONRPCResponse,JSONRPCError]
Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Berechne /', input_type=str]
The client read the line Berechne / as a protocol
message and could not parse it as JSON. The Python SDK skips such lines
and continues; other clients drop the connection. The specification’s
rule is clear: a stdio server may write only valid MCP
messages to standard output. For your own messages there is
standard error (stderr):
import sys
…
print("Berechne", pfad, file=sys.stderr)
file=sys.stderr redirects the output to stderr. The
client passes it through to your terminal, and the protocol stays clean.
Remove the print line again afterwards.
Remember: The standard output of a stdio server carries only MCP messages. Everything else belongs on stderr – no chatting on the house line.
Save your progress? Sign up for free
Exercise: A second tool (20 min)
Extend leitstand.py with a tool laufzeit
(uptime) without parameters that returns for how many days the machine
has been running (rounded to two decimal places). Hint: the first number
in the file /proc/uptime is the uptime in seconds. Call the
tool with a copy of client.py.
Solution
Insert before the line if __name__ == "__main__"::
@mcp.tool()
def laufzeit() -> float:
"""Liefert, seit wie vielen Tagen dieser Rechner läuft."""
with open("/proc/uptime") as datei:
sekunden = float(datei.read().split()[0])
return round(sekunden / 86400, 2)
with open(…) as datei:opens the file and closes it automatically at the end of the block.datei.read().split()[0]reads the content (for example1234.56 4567.89), splits it at spaces and takes the first piece;float(…)turns it into a number.round(sekunden / 86400, 2)– a day has 86,400 seconds; round to two places.-> floatbecomes"type": "number"in theoutputSchema.
Copy the client with cp client.py client_uebung.py and
change the call in it to
await client.call_tool("laufzeit", {}) – a tool without
parameters gets an empty dictionary.
# on cp1, in ~/mcpa/tag01
uv run python client_uebung.pyExpected (your uptime will be different):
Werkzeug: freier_speicher - Liefert den freien Plattenplatz unter einem Pfad in GB.
Werkzeug: laufzeit - Liefert, seit wie vielen Tagen dieser Rechner läuft.
Ergebnis: {'result': 0.02}
Save your progress? Sign up for free
Challenge: Wrong calls (15 min)
Send the server two faulty calls by hand: one for a tool
neustart (restart) that doesn’t exist, and one for
freier_speicher with the path /gibtsnicht
(“doesn’t exist”). How does the server report the two errors? Compare
with what the specification requires (background below in the
solution).
Solution
# on cp1, in ~/mcpa/tag01
nano falsch.jsonl{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"neustart","arguments":{},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}
{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"freier_speicher","arguments":{"pfad":"/gibtsnicht"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}# on cp1, in ~/mcpa/tag01
(cat falsch.jsonl; sleep 5) | uv run python leitstand.py 2>/dev/null | jq -c .2>/dev/null discards standard error – the server
writes a long Python traceback there for the second error, which would
only get in the way here.
Expected:
{"jsonrpc":"2.0","id":4,"result":{"content":[{"text":"Unknown tool: neustart","type":"text"}],"isError":true,"resultType":"complete","_meta":{"io.modelcontextprotocol/serverInfo":{"name":"leitstand","version":"1.0.0"}}}}
{"jsonrpc":"2.0","id":5,"result":{"content":[{"text":"Error executing tool freier_speicher","type":"text"}],"isError":true,"resultType":"complete","_meta":{"io.modelcontextprotocol/serverInfo":{"name":"leitstand","version":"1.0.0"}}}}
Both errors come as a successful JSON-RPC response
with isError: true and an explanation in
content. The specification, however, distinguishes two
kinds of errors:
- Protocol errors – the request itself is wrong:
unknown tool, broken structure. They are reported as JSON-RPC errors,
that is, with an
errorfield instead ofresult. For an unknown tool the specification explicitly names the code-32602(Invalid params) and the messageUnknown tool: …. - Execution errors – the request was fine, but the
tool failed: wrong input values, a service doesn’t respond, a file is
missing. They are reported with
isError: truein the result so that the model can read the message and try again with different values.
So the second case is reported correctly. The first is not: Python
SDK 2.3.0 treats an unknown tool as an execution error. In practice this
is harmless, because the model still learns that the tool doesn’t exist.
In the exam the specification counts: unknown tool = protocol
error -32602. Also remember the message of the
second error: “Error executing tool” doesn’t help the model much. Day 5
shows how to write error messages a model can actually work with.
Save your progress? Sign up for free
Checkpoint
# on cp1, in ~/mcpa/tag01
(head -1 nachrichten.jsonl; sleep 3) | uv run python leitstand.py | jq -r '.result.supportedVersions[0]'head -1 sends only the first line
(server/discover); jq -r prints the first
entry of supportedVersions without quotes.
Expected:
2026-07-28
# on cp1, in ~/mcpa/tag01
uv run python client.pyExpected: two lines, the last one
Ergebnis: {'result': …} with your number.
# on cp1, in ~/mcpa/tag01
jq -r .method an-server.jsonlExpected:
server/discover
tools/list
tools/call
Exam questions
1. A host is connected to four MCP servers. How many MCP clients does it contain?
- one that serves all four servers
- two, one each for local and remote servers
- four, one per server
- as many as the model calls tools
2. For a prompt (primitive), who decides when it is used?
- the language model
- the server
- the human who selects it
- the client automatically when connecting
3. Which statement about protocol version 2026-07-28 is correct?
- Every connection begins with
initializeandnotifications/initialized.
- Every connection begins with
- Every request carries protocol version and client capabilities in
_meta.
- Every request carries protocol version and client capabilities in
- The version is negotiated once per session via an HTTP header.
- Servers must remember the client’s capabilities from earlier requests.
4. A stdio server writes debug messages to standard
output with print(). What is the consequence?
- Nothing; clients ignore everything except JSON.
- The messages appear in the host’s chat.
- The client reads them as protocol messages; depending on the client there are errors or disconnects.
- The operating system terminates the server.
5. A client calls tools/call for a tool
the server doesn’t know. According to the specification, how should the
server respond?
- with a result with
isError: true
- with a result with
- with a JSON-RPC error with code
-32602
- with a JSON-RPC error with code
- with an empty result and
resultType: "complete"
- with an empty result and
- not at all; the client detects it by timeout
Solutions
- C. Each client holds a connection to exactly one server; the host contains as many clients as servers it uses.
- C. Prompts are user-controlled. Tools are controlled by the model (A), resources by the application.
- B. Since 2026-07-28 there is no handshake and there are no sessions anymore (A and C describe the old state); servers must specifically not rely on earlier requests (D).
- C. Only MCP messages may appear on a stdio server’s standard output; messages belong on stderr.
- B. An unknown tool is a protocol error.
isError: true(A) is intended for errors during execution. Python SDK 2.3.0 answers with A here – in the exam the specification applies.
Interview Note
“Why does a host have a separate client per server?” – Isolation. Each server only sees its client’s requests, not the conversation and not the other servers. The host merges the results and decides what the model gets to see. This way a compromised or curious server cannot grab another server’s data – provided the host doesn’t pass it on itself.
Enterprise Note
Local stdio servers run with the rights of the user who starts the
host – they can do everything that user can do. A tool like
freier_speicher with a freely selectable path already
allows probing arbitrary directories. Organizations therefore keep lists
of approved servers, start local servers in sandboxes or containers, and
prefer remote servers over HTTP with authorization for shared systems
(Day 12).
Summary
- MCP defines how applications find and use tools, data and templates – not which model they use or how the model decides.
- The host represents the human and talks to the model; it contains one client per server; a server offers capabilities and only sees its client.
- Server primitives: tools (model-controlled), resources (application-controlled), prompts (user-controlled). Client side: elicitation, plus the deprecated sampling and roots.
- Data layer JSON-RPC 2.0, transports stdio and Streamable HTTP.
- Since 2026-07-28 no handshake: every request carries
_metawith protocol version and client capabilities;server/discoverreveals what a server can do; every response carriesresultType. MCPServerbuilds a tool withinputSchemaandoutputSchemafrom function name, types and docstring; results come ascontentandstructuredContent.- Only protocol messages belong on a stdio server’s standard output.
- Unknown tool = protocol error
-32602, failed execution =isError: true.
Commands at a glance
For review: all commands and SDK calls of this day with the parameters you used.
| Command / call | What it does | Parameters |
|---|---|---|
MCPServer(name=…, version=…, instructions=…) |
creates a server | name, own version, hint text for hosts |
@mcp.tool() |
turns a function into a tool | name, types and docstring become name, schema and description |
mcp.run() |
starts the server | without argument: stdio transport |
nano <file> |
create or change a file in the editor | Ctrl+O save, Ctrl+X quit |
(cat <file>; sleep 3) \| uv run python <server.py> |
sends messages by hand over stdio | sleep keeps the input open |
jq -c . · jq -r '<path>' |
compact JSON · one value without quotes | -c one line, -r raw |
StdioServerParameters(command=…, args=[…]) |
describes how the client starts the server | program and arguments |
async with Client(<server>) as client: |
opens and closes the connection | URL, stdio parameters or server object |
await client.list_tools() |
tools/list |
– |
await client.call_tool(<name>, {<arguments>}) |
tools/call |
name, arguments as dictionary |
sh -c "tee a \| <server> \| tee b" |
captures the stdio traffic | tee writes a copy to a file |
print(…, file=sys.stderr) |
message on stderr instead of stdout | stdout belongs to the protocol |
2>/dev/null |
discards the error output | – |