Phase 5: Model Context Protocol (MCP) · 75 min · Python · MCP SDK · Anthropic SDK
MCP Client Integration
The MCP client merges tool sets from all servers into one unified interface — the model sees tools, not servers.
Hiring signal: Building a working MCP client that aggregates multiple servers and routes tool calls correctly demonstrates systems thinking, not just API knowledge. This is what a senior AI engineer actually implements when a team says 'we need our agent to use our internal tools.'
What you will learn
- Build an MCPClientManager that connects to multiple servers and merges their tool lists
- Implement a ToolRegistry that maps tool names to servers and resolves naming conflicts
- Wire the full agentic loop: Anthropic API tool calls route through the registry to the correct MCP server
The Problem
You've built MCP servers. Now you need to consume them from your own agents — not through Claude Desktop, but programmatically. An autonomous research agent needs to call tools from a database server, a filesystem server, and a web search server. The agent shouldn't know or care that these tools come from three different processes.
This is the MCP client's job: connect to servers, discover tools at runtime, merge tool definitions into one list, and route each model tool call to the correct server. The model sees a single unified tool interface. The client handles all the plumbing.
This lesson builds the client layer from scratch: MCPClientManager, ToolRegistry, and the full agentic loop.
Dynamic tool discovery at startup
The client doesn't hardcode which tools exist. It calls tools/list on each connected server at startup, merges the results, and passes them to the model. This means new tools added to a server become automatically available the next time the agent starts — no code changes required.
MCP Client Lifecycle
The full lifecycle, step by step:
- Connect — establish transport connection to each server (stdio subprocess or HTTP)
- Initialize — exchange protocol versions (client sends
initialize, server responds with capabilities) - Discover — call
tools/list on each server; collect all tool definitions - Aggregate — merge all tool definitions into one list; build a registry mapping tool names to servers
- Run model — pass merged tool list to the Anthropic API as the
tools parameter - Route — when model returns
tool_use, look up tool name in registry → find server → call tools/call - Return result — add the result as a
tool_result message and continue the loop - Repeat until
stop_reason == "end_turn"
The client owns steps 1-4 (infrastructure) and 6-7 (routing). The Anthropic API handles the model side.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Dynamic Tool Discovery, Multi-Server Tool Routing, Handling Tool Name Conflicts, Build It, What to Practice — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy