Sub topic 8
Following a tool call from prompt to result
This chapter traces one request through every layer of an MCP setup, from the sentence you type to the answer you read. It assumes you know the host, client and server roles, the three primitives (tools, resources, prompts), the JSON-RPC message shapes, and how a server is listed in mcpServers. Here you will see how those pieces work together, and where a call can fail.
The scenario
You have a small calculator server connected to your coding assistant. It exposes one tool named add, which takes two integers. You type:
What is 2 plus 3? Use the calculator.The assistant answers "5". Between those two events, at least eight distinct steps happen. Some happen once per session and some happen on every call.
Setup steps that happen before your prompt
Two things must be true before the model can even consider calling add.
- The host has started the server and completed the initialization handshake. The client sent
initialize, the server replied with its capabilities (includingtools), and the client sent thenotifications/initializednotification. - The client has asked the server what it offers by sending
tools/list, and has stored the answer.
The tools/list response contains, for each tool, a name, a description and an inputSchema. The schema is JSON Schema. For add it looks like this:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "add",
"description": "Add two integers.",
"inputSchema": {
"type": "object",
"properties": {
"a": { "type": "integer" },
"b": { "type": "integer" }
},
"required": ["a", "b"]
}
}
]
}
}The host usually does this listing when the session starts, not when you ask your question. That is why a server you add to the configuration often needs a restart or a reload before its tools appear.
The full round trip
The diagram shows the flow for one call. The model never talks to the server directly. The host sits in the middle and decides what the model sees and what gets executed.
Step 1: The host builds the model request
When you press enter, the host assembles a request to the model. It includes your prompt, the conversation so far, and the definitions of every available tool. Each definition is the name, description and inputSchema taken from tools/list.
This is the only way the model learns that add exists. The model does not know about MCP. It only sees a list of functions it may ask the host to run. The tool descriptions are therefore part of the prompt, and they use up context tokens on every request.
Step 2: The model decides to call a tool
The model reads your prompt and the tool list and chooses to respond with a structured tool call instead of plain text. It produces the tool name and an arguments object that should match the schema:
{ "name": "add", "arguments": { "a": 2, "b": 3 } }The exact wire format differs between model providers, but the content is the same: a name and arguments. The model generates this. It is a prediction, not a guarantee, so the arguments can be wrong, missing or of the wrong type.
Step 3: The host checks permission
Most assistants pause here and show you the tool name and arguments. You can approve once, approve for the session, or deny. Some hosts allow you to pre-approve specific tools in configuration.
This step is a decision made by the host, not by the MCP protocol. The protocol has no built-in approval message. A host that auto-approves everything will run whatever the model asks for. The security chapter covers when that is acceptable.
Step 4: The client sends `tools/call`
After approval, the MCP client that manages the connection to this server sends a JSON-RPC request:
{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "add", "arguments": {"a": 2, "b": 3}}}The id lets the client match the response to this request, which matters when several calls are in flight. Over stdio, this line is written to the server process's standard input. Over Streamable HTTP, it is the body of an HTTP POST.
Step 5: The server runs the tool
The server finds the function registered under add, validates the arguments against its schema, runs the code, and builds a response. For the FastMCP example, the SDK does the validation and conversion from the Python return value to the protocol result.
Step 6: The server returns a result
A successful response carries a content array. Each item has a type, most often text:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [{ "type": "text", "text": "5" }],
"isError": false
}
}The content can also include images, embedded resources and other types. A tool can return several items in one result.
Step 7: The host returns the result to the model
The host adds the tool result to the conversation and calls the model again. The model now sees: your prompt, its own tool call, and the result 5. It writes the final text, usually without calling anything else.
Step 8: You see the answer
The host displays the model's text. Many hosts also show a collapsed view of the tool call so you can inspect the arguments and raw result.
Calls can repeat
The model is called again after each tool result, and it may request another tool call instead of answering. A task like "read these three files and summarize them" can produce three tools/call requests, each followed by a model call. This loop continues until the model produces plain text or the host stops it.
Each loop iteration adds the tool call and its result to the conversation. Large results, such as a 5,000-line file, make every later model request bigger and slower.
Two kinds of failure
Errors in MCP come in two forms, and they are handled differently.
| Kind | What it is | How it appears | Who sees it |
|---|---|---|---|
| Protocol error | The request itself is invalid: unknown tool name, malformed arguments, server crash | A JSON-RPC `error` object with a `code` and `message` | Usually the host, which may show it or pass a summary to the model |
| Tool execution error | The tool ran but failed: file not found, API returned 500, bad input value | A normal `result` with `"isError": true` and an explanation in `content` | The model, which can read the message and try again |
Here is a tool execution error:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [{ "type": "text", "text": "Division by zero is not allowed." }],
"isError": true
}
}This design is deliberate. An error written in clear language inside the result lets the model correct itself, for example by changing the arguments. A protocol error is more likely to end the attempt.
In the Python SDK, raising an exception inside a tool function normally produces a result with isError set to true, with the exception message as the text.
Where things go wrong
Most failed calls fall into one of these categories. Check them in this order, from the earliest step to the latest.
- The tool never appears. The server did not start, the handshake failed, or
tools/listreturned nothing. The model cannot call what it was never told about. - The model does not choose the tool. The description is vague, or another tool seems a better match. Rewrite the description to say what the tool does and when to use it.
- The model sends bad arguments. The schema is loose, or a field name is ambiguous. Use precise types,
requiredfields, and parameter descriptions. - The host blocks the call. You denied approval, or a policy forbids the tool.
- The call times out. Hosts set time limits. A slow tool may be cancelled even though the server is still working.
- The server writes to the wrong place. With stdio, the server's standard output carries protocol messages only. A stray
print()in the server corrupts the stream. Log to standard error instead. - The result is too large. The response is valid but floods the context. Return summaries, paginate, or let the model request ranges.
Watching a call yourself
You can reproduce steps 4 to 6 without a model. The MCP Inspector starts your server and lets you list tools and call them by hand:
npx @modelcontextprotocol/inspector python server.pyIf a call works in the Inspector but fails in the assistant, the problem is above the server: the configuration, the model's choice of arguments, or host permissions. If it fails in both, the problem is in the server.
Summary of responsibilities
| Step | Performed by | Protocol message |
|---|---|---|
| List tools | Client, answered by server | `tools/list` |
| Choose a tool and arguments | Model | None (host and model API) |
| Approve the call | Host and user | None |
| Execute the tool | Server | `tools/call` |
| Report failure or success | Server | `result` or `error` |
| Write the final answer | Model | None |
Only two of these steps use MCP messages for the call itself. The rest happen in the host and the model API, which is why behavior varies between assistants even when they use the same server.
Exercise
A tool returns {"result": {"content": [{"type": "text", "text": "File not found: notes.txt"}], "isError": true}}. Is this a protocol error or a tool execution error? What does the model do with it, and why is that useful?
Show answer
It is a tool execution error, because the server returned a normal JSON-RPC result with isError set to true instead of an error object. The host passes the message to the model, which can read it and respond, for example by checking the file name, listing the directory, or telling you the file is missing. A protocol error would more likely end the attempt without giving the model a readable explanation.
Exercise
Your Python stdio server works when you run it by hand, but the assistant reports a parse error right after starting it. You added print("starting up") near the top of the file. What is the cause, and what is the fix?
Show answer
Over stdio, standard output carries the JSON-RPC messages, so the line "starting up" is read as an invalid message. Remove the print, or write the text to standard error, for example with print("starting up", file=sys.stderr) after import sys, or use the logging module, which writes to standard error by default.
Exercise
The add tool shows up in the Inspector and works there. In your assistant the model never uses it, even when you ask for a sum. Name two likely causes outside the server code and one change to the server that might help.
Show answer
Likely causes are that the host has not reloaded its configuration so the tool was never listed to the model, or that the host's permission settings hide or block the tool. A server-side change that might help is a clearer description, such as "Add two integers and return their sum. Use this for any addition request."