learning-it by example

#31 AI agents and MCP 6.1 min

Debug an MCP Server with the MCP Inspector

A tool on my MCP server failed with an error a model could do nothing with. The Inspector's command line mode showed me that error exactly as a model would get it.

1. What two kinds of errors does the MCP specification describe for tools?
2. In the MCP Inspector command line run on the small shop server, how many problems did the checks count on the first server and on the fixed server?
3. Why was the error for an unknown product code useless to a model on the first shop server?
4. Which part of the MCP Inspector did the video not run, and say it shows the same exchange with buttons?
5. How does the fixed stock_level tool help a model when the product code is unknown?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Predict the problem count

    Copy the code folder first. Read server.py and run.py. Without running anything, predict which tool the report will call NO description, and which call will count as opaque. Then add a one-line docstring to refund in server.py and predict the new 'problems' number for server.py. The video's unedited run printed problems: 2 for server.py, so your predicted number is for the edited file (a run with the docstring added printed problems: 1). Afterwards delete the docstring again.

    A hint

    A problem is a tool with no description, or an error that says nothing but the name of the tool.

  2. Add a product and predict the message

    In server_fixed.py add one more entry to STOCK, for example "LOCK-3": 9. Predict the full text of the error that stock_level gives for the SKU NOPE now, including the order of the known SKUs. The code sorts them. The Inspector needs Node and npm, so work this out by reading the code. Note that run.py shows only the first 40 characters of the message, so a real run would cut the list short.

    A hint

    Look at how the f-string builds the list: ', '.join(sorted(STOCK)).

  3. Why is the bad refund not a problem?

    Read the opaque function in run.py. The call refund(order_id=abc, amount=5) is an error on both servers, yet it is not counted as a problem. Write one or two sentences saying why, using the check the function makes.

    A hint

    The video's run shows the error text starts with a validation message, not just the tool name.

  4. Add a fifth call to the report

    In run.py add the call ("stock_level", {"sku": "BELL-2"}) to the tries list. Predict the line it will print for each server and whether the problems count changes. If you have Node 22 and have run npm install as in the video, run python run.py and compare with your prediction.

    A hint

    BELL-2 is in the STOCK dictionary, so it is a known product.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Two small made-up tools over standard input and output. Only the Inspector's command line mode was run (Inspector 2.12.0 on Node 22.14.0, which is older than the documentation asks for), not the web page or the terminal interface. The two checks are my own and no language model was used.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos