Agents and Tool Use · Making It Safe · lesson 4 of 7
MCP and tool discovery
about 16 minutes · free · runs in your browser
Tools you did not hard-code
Hard-coding a tool list works until you have four agents and eleven tools, at which point every agent needs redeploying to gain a capability. MCP — the Model Context Protocol — standardises the alternative: a server advertises the tools it offers, a client asks for them at startup, and the agent works with whatever it is given.
The protocol details are not the interesting part. The interesting part is what changes: the tool list becomes runtime data from an external source, and everything you assumed about it stops being guaranteed.
- Two servers can advertise a tool with the same name. One will shadow the other.
- A server can advertise a tool your agent must not be allowed to call.
- The list can change between runs, so a name that worked yesterday may be gone.
So a client that merges tool lists must resolve collisions deliberately rather than letting a later entry silently win.
Your turn: write merge_tools(servers) where servers is a list of
(name, tools) pairs. Namespace each tool as server.tool so two servers can offer
search without one erasing the other, and return the merged dictionary.
You start from this, and edit it in the browser:
def merge_tools(servers):
"""Merge tools from several servers, namespaced as 'server.tool'."""
return {}