Sub topic 10
Debugging with the MCP Inspector
This chapter assumes you can run a Python MCP server over stdio, as in the previous chapter on writing a minimal server. You should also know the basic JSON-RPC message shapes (request, response, notification) and how the initialize handshake works. You need Node.js installed, because the Inspector runs through npx.
Why debug outside the assistant
When a tool fails inside a coding assistant, you see one symptom: the tool is missing, the model ignores it, or a call returns an error. Many things could be causing that. The server may crash on startup. The config may point at the wrong path. The schema may be malformed. The model may simply have chosen not to call the tool.
The MCP Inspector removes the model and the assistant from the picture. It acts as a bare-bones MCP client. It launches your server, performs the handshake, and lets you list and call the server's tools, resources and prompts by hand. If a feature works in the Inspector and fails in the assistant, the problem is in the configuration or in the model's behavior. If it fails in the Inspector too, the problem is in your server.
Test the server alone first, then add the assistant.
Starting the Inspector
Pass the same command you would put in the command and args fields of an mcpServers entry:
npx @modelcontextprotocol/inspector python server.pyThe Inspector starts a small local proxy. The proxy launches your server as a child process and speaks stdio to it. It also serves a web page, and the terminal prints the address to open. Recent versions print a URL that includes a session token. Open that exact URL, because the proxy rejects requests without the token.
If the server needs environment variables, set them in the shell before the command:
API_TOKEN="test-token" npx @modelcontextprotocol/inspector python server.pyYou can also set command, arguments and environment variables in the web UI's connection panel. Matching what your assistant's config does is the point. A server that works with your shell's environment may fail under the assistant, which often passes only the variables listed in env.
What happens when you click Connect
The Inspector goes through the same lifecycle any client does. Watching it once makes later failures easier to read.
A failure at each step points to a different cause:
| Step that fails | Typical cause |
|---|---|
| Spawn | Wrong command, missing interpreter, wrong working directory, missing dependency |
| `initialize` | Server crashes on import, or writes non-protocol text to stdout |
| `tools/list` | Server did not declare the `tools` capability, or a schema error |
| `tools/call` | Bug in the tool function, bad arguments, or an unhandled exception |
Reading the Inspector's panels
The layout varies a little between versions, but these parts are consistent.
- Connection panel. Holds the transport, command, arguments and environment. The status shows connected or the reason it could not connect.
- Tools, Resources and Prompts tabs. Each lists what the server exposes. Selecting an item shows its name, description and input schema. Tools get a form generated from the schema, and you press a button to run them.
- Notifications and logs. Shows messages the server sends that have no request, such as log messages and list-changed notifications. Server stderr output also appears here.
- History. Records each request and response. This is where you read raw JSON-RPC.
The Tools tab is the quickest check on a tool's quality. The name, description and schema you see are exactly what the model will see. A vague description such as "does stuff" or an argument with no type will be just as unclear to the model as it is to you.
Checking a tool call by hand
Take the calculator server from the previous chapter. In the Tools tab you select add, enter a = 2 and b = 3, and run it. In the history you should find the request the Inspector sent:
{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "add", "arguments": {"a": 2, "b": 3}}}The matching response carries a result with the same id. The result content is a list of typed items, and the text for this call is "5". If you see the id in the request but no response, the server is hung or crashed. If the response has an error member instead of result, the failure is at the protocol level.
Two kinds of error
MCP separates failures into two categories, and the difference matters when you read the history.
- Protocol errors are JSON-RPC
errorresponses. They mean the request itself was invalid: an unknown tool name, malformed parameters, or a method the server does not support. An unknown tool name typically comes back with code-32602(invalid params). - Tool execution errors are normal
resultresponses with"isError": trueand an explanation in the content. They mean the tool ran and failed, for example because of a divide by zero or an upstream API timeout.
This split exists so the model can read tool execution errors and try again, for example with different arguments. Protocol errors usually indicate a bug in the client or server.
Here is a server with a tool that can fail, and logging that does not break the protocol:
import logging
import sys
from mcp.server.fastmcp import FastMCP
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
log = logging.getLogger("calculator")
mcp = FastMCP("calculator")
@mcp.tool()
def divide(a: float, b: float) -> float:
"""Divide a by b."""
log.info("divide called with a=%s b=%s", a, b)
if b == 0:
raise ValueError("b must not be zero")
return a / b
if __name__ == "__main__":
mcp.run()Run it in the Inspector, call divide with b = 0, and look at the result. FastMCP catches the exception and returns it as a tool execution error, so you get a normal response with isError set to true, not a crashed connection. The log line appears in the Inspector's log area, because it went to stderr.
The stdout rule
The most common stdio failure for new server authors is writing to stdout. On the stdio transport, stdout carries only protocol messages, one JSON-RPC message per line. A stray print("starting up") inserts a line that is not valid JSON-RPC. The client may drop it, report a parse error, or disconnect.
The symptoms are confusing. The server seems to start, then the connection closes during initialize, or the first call never completes. The fix:
- Send logs and debug output to stderr, as in the example above.
- In Python, use
print(..., file=sys.stderr)or theloggingmodule configured for stderr. - In JavaScript, use
console.error, notconsole.log. - Check imported libraries too. Some write banners or progress bars to stdout when they load.
A debugging checklist
Work from the outside in, and stop at the first step that fails.
- Run the command directly. In a terminal, run the exact command and arguments from your config. A stdio server should start and wait silently for input. An immediate traceback or "command not found" tells you the problem. Press Ctrl+C to stop it.
- Connect with the Inspector. If it cannot connect, read the error text and any stderr output. Check the interpreter, the paths and the dependencies.
- Confirm capabilities. Check that the tabs for what you expect (Tools, Resources, Prompts) have content. An empty list with a successful connection usually means the server registered nothing, for example because the decorators ran in a code path that was never reached.
- Inspect each schema. Read names, descriptions and types. Fix anything the model would find ambiguous.
- Call each tool with good and bad input. Try normal values, boundary values and invalid ones. Check that errors are clear and that the server stays alive afterwards.
- Compare with the assistant's config. Make sure the command, arguments, working directory and
envmatch what you tested. Use absolute paths in the config. Assistants often launch servers from a different working directory than your terminal. - Check the assistant's own logs. Most assistants record when a server fails to start or to initialize. Look there if the Inspector works but the assistant does not.
When the Inspector works and the assistant does not
If the server passes every check above, look at these causes:
- Different environment. A GUI application may not inherit your shell's
PATH.npx,pythonoruvmay resolve to a different version or not be found at all. Using full paths forcommandavoids this. - Missing secrets. The token you exported in your shell is not in the config's
envblock. - Configuration needs a restart. Many assistants read the server list only at startup. Restart the assistant, or use its reload command, after editing the config.
- Approval prompts. The assistant may ask for permission before the first tool call, and the call waits until you answer.
- The model chose not to call it. The tool is available but the description does not match the task. Rewrite the description to say when to use the tool, and test again with a prompt that names the task plainly.
Inspecting beyond tools
The same approach works for the other primitives.
- For a resource, list resources, read one, and check the URI, the MIME type and the content. Test URI templates with several values.
- For a prompt, list prompts, fill in the arguments, and check the messages that come back. This is the exact text the assistant would insert into the conversation.
Recent Inspector versions also include a command-line mode, which lets you script calls in a test or CI job. Check the Inspector's README for the flags in your installed version, since they have changed between releases.
Summary of habits
- Test the server in the Inspector before connecting it to an assistant.
- Keep stdout clean on stdio. Log to stderr.
- Read raw JSON-RPC in the history when behavior is unclear.
- Distinguish protocol errors from tool execution errors.
- Treat the schema and description as part of the interface the model uses, and review them in the Tools tab.
Exercise
Your stdio server connects in the Inspector, but every tools/call hangs and the history shows a parse error after you added a line near the top of server.py that says print("server ready"). What is wrong, and what two ways can you fix it?
Show answer
The print writes plain text to stdout, which on the stdio transport must carry only JSON-RPC messages, so the client sees an invalid line and the stream breaks. Fix it by sending the message to stderr, for example print("server ready", file=sys.stderr), or by using the logging module configured with stream=sys.stderr. Removing the line also works.
Exercise
In the Inspector history, one call to divide returns a response with "isError": true, and another call to a tool named divde returns a JSON-RPC error object. Which is a tool execution error, which is a protocol error, and why does the difference matter?
Show answer
The isError: true result is a tool execution error: the tool ran and failed (for example, division by zero), and the model can read the message and retry with different arguments. The error object for divde is a protocol error: the request named a tool that does not exist. It points to a bug in the client or a typo, not a failure inside a tool.