Sub topic 11
Testing with the MCP Inspector
This chapter assumes you have a working FastMCP server like the one from "Your first tool", can run Python and npx in a terminal, and know that MCP messages are JSON-RPC over a transport. You will test the server before you connect it to a host.
Why test before connecting a host
A host such as Claude Desktop hides most of what happens. If a tool fails, you may only see that the model did not use it. The MCP Inspector is a developer tool that acts as a plain MCP client. It launches your server, shows the raw messages, and lets you call tools by hand. That removes the model from the loop, so you can tell a server bug apart from a model decision.
Start the Inspector
Install the SDK and run the Inspector against your server script. npx downloads the Inspector on first use, so Node.js must be installed.
pip install "mcp[cli]"
npx @modelcontextprotocol/inspector python server.pyThe Inspector starts a local web page and prints its address in the terminal. Open it in a browser. It starts your script as a subprocess over stdio, the same way a host would.
What to check
Work through the tabs in this order.
- Connect. Confirm the status shows connected. If it does not, the server failed during startup or wrote something other than protocol messages to stdout. Check the terminal for a Python traceback.
- Tools. Choose List Tools. Check that each tool name, description, and input schema matches what you intended.
- Call a tool. Select a tool, fill in the form, and run it. Try a valid call first.
- Resources and Prompts. Do the same for any resources, resource templates, and prompts you registered.
- Notifications and history. Review the log of requests and responses to see the actual JSON.
Read the schema the model will see
For list_deploys, the Inspector should show environment as an enum with staging and production, and limit as an integer with a minimum of 1 and a maximum of 20. If the schema is missing a constraint, the model will not know about it either. Fix the type hints, not the Inspector.
Test the failure cases
Valid calls only prove half the behavior. Try these:
| Test | Input | Expected result |
|---|---|---|
| Unknown value | `get_service_owner` with `service` set to `payments` | An error result that names the unknown service |
| Out of range | `list_deploys` with `limit` set to 50 | Rejected by schema validation before your code runs |
| Wrong type | `limit` set to `"five"` | Rejected by schema validation |
| Missing resource | `runbook://unknown` | The text "No runbook found." |
An error that returns to the Inspector with a clear message means the server stayed alive. If the process exits, you have an unhandled failure at startup or in a code path outside the tool handler.
Common problems
- Connection fails right away. Run
python server.pydirectly. If it exits with an error, fix that first. - Wrong Python environment. The Inspector runs the
pythonon your PATH. If the SDK is installed elsewhere, use the full path to that interpreter. - Changes do not appear. The server is a subprocess started at connect time. Disconnect and reconnect after you edit the code.
- Tool missing from the list. Check that the
@mcp.tool()decorator is present and that the module reaches the code that registers it.
Exercise
You call list_deploys in the Inspector with limit set to 50 and see a validation error. Your function body never ran. Why, and what does this tell you about where to put input limits?
Show answer
The Annotated[int, Field(ge=1, le=20)] hint becomes a JSON Schema maximum of 20, and the SDK validates arguments against it before calling your function. Limits that can be expressed in the type hints belong there, because the model also sees them in the schema and the server rejects bad input without extra code.