learning-it by example

#28 AI agents and MCP 5.3 min

Build an MCP Client That Uses Many Servers in Python

I gave two MCP servers a tool called search each. Merge their tools by name, and one of them vanishes.

1. The MCP specification says a tool name is unique only inside its own server. What does it suggest a client does when two servers each offer a search tool?
2. A Python MCP hub lists six tools from a bike shop server and an airline server, and both servers have a tool called search. Without the server prefixes, how many distinct tool names would there be?
3. In a Python MCP hub that combines several servers, how does the hub send a call such as flights__book_flight to the right server?
4. In one run of a Python test with llama3.2 on Ollama (temperature 0, six easy questions), how many questions got the right first tool when the model saw the tools of both servers?
5. Which limit of a small Python MCP hub that connects to several servers is stated plainly?

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

  1. Count the unique tool names

    Copy the code folder first. In a Python prompt build this list: shop__opening_hours, shop__service_price, shop__search, flights__search_flights, flights__book_flight, flights__search. Take the part of each name after the first double underscore, make a set of those parts and print its length. Predict the number first. We got 5 out of 6.

    A hint

    Use name.split('__', 1)[1] for each name.

  2. Merge by name and lose a tool

    Using the same six names, build a dictionary from the bare tool name to the server name, looping over the list in order. Print the length of the dictionary and which server the search entry belongs to. Predict both. We got 5 and flights. Write one sentence on which server's search tool silently disappeared.

    A hint

    Later keys overwrite earlier ones in a dictionary, so the first search was replaced.

  3. Why split only at the first double underscore

    In a Python prompt compare 'shop__my__tool'.split('__', 1) with 'shop__my__tool'.split('__'). Predict both results, then run them. We got ['shop', 'my__tool'] and ['shop', 'my', 'tool']. Explain which one hub.py needs in call and why.

    A hint

    The server name is the part before the first double underscore. The rest is the tool name.

  4. Predict a seventh tool

    In shop_server.py add a new tool called stock_level that takes an item name and returns a number, written like the other tools with a docstring. Predict what the first two lines printed by python compare.py will say about the number of tools and the unique names. Then run it with the packages and Ollama from the video and compare. This is a prediction task: we did not run the servers.

    A hint

    Think about whether search still appears twice. Do not expect the tool choice score to stay the same without checking.

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

What this does not show

Two made up servers and six easy questions with tool names that explain themselves. Only the first tool the model chose was checked, not its arguments. The hub has no approval step, no timeouts and no call log.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos