#330 AI agents and MCP 6.8 min
Too Many MCP Tools: Shortlist, Validate and Log (Python)
A plain keyword router put the right tool in a list of 5 for 28 of 30 made-up requests.
Fix two bad calls
Copy the code folder first. In labelled.py, in CALLS, change "nights": "two" to "nights": 2 and change "amount": 450000 to "amount": 450. Predict how many of the eight calls will pass the check, and what the counts line will say. Run python run.py check and python run.py log.
A hint
Each fix removes one problem message. Compare the number of invalid args in the counts line with the original 5.
Send a fractional number of nights
In labelled.py change "nights" to the value 2.5 in the search_hotels call. Predict the message for that call. Run python run.py check and read the line for travel.search_hotels.
A hint
The schema asks for an integer. The message names the field, the type wanted and the value it got.
Show only three tools
In router.py change k=5 to k=3 in the shortlist function. Predict whether the right tool will be found less often, and what happens to the words in the list. Run python run.py measure. The row labels will still say 5.
A hint
A shorter list is smaller, but misses more. I saw 23 of 30 and 27 words for the first list and 24 of 30 for the second.
Ask a question that matches no tool
In run.py, in the score_demo function, change REQUESTS[8][0] to REQUESTS[18][0], which asks whether it will rain in Leeds. Predict the scores in the list. Run python run.py score. Then explain why the video says not to trust a shortlist when every score is zero.
A hint
None of the words in the request appear in any tool description. I saw billing tools with a score of 0.00.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
No model is run, so model accuracy is not measured: the example only checks whether the right tool is in a keyword-router shortlist. Tools, thirty requests and the right-tool labels are made up; the server step made no difference here and a bigger catalogue was not tried. No real MCP server or client is used; the tools are plain Python dicts in the MCP tool shape.
Up next in AI agents and MCP
More in AI agents and MCP
- #01 Local AI Agent in Python: No API Key (Ollama)
- #12 Multi-Agent Patterns in Plain Python: Pipeline, Router, Loop
- #22 OpenAI Agents SDK vs LangGraph vs Plain Python
- #23 Agent Memory: What to Keep and What to Forget
- #24 Approval Gates for Risky Agent Actions
- #25 Tool Errors: Retries, Fallbacks and Made-Up Answers