Integrate agent tools using an MCP server and client
Unit 3 of 6 · Module 9: Integrate MCP Tools with Azure AI Agents
Before you start
Short explainers for ideas this lesson builds on. Watch these first if they're new to you.
Go deeper
Unlocks when you've watched the lesson.
Read this lesson
The MCP server
To connect tools to an agent dynamically, you need two pieces: an MCP server and an MCP client. The server is a registry, the catalog of tools your agent can use. In Python, you create one with FastMCP, and give it a name. Then you mark your functions with the at mcp dot tool decorator. FastMCP reads each function's type hints and docstring, and generates the tool definition for you: its name, what it does, and the inputs it expects. Those definitions are sent to any client that connects: over the network with HTTP, or, for a server on the same machine, over standard input and output, as you'll do in the lab. And because the definitions live on the server, you can add or update tools at any time, without changing or redeploying the agent.
The MCP client
The client is the bridge between the MCP server and your agent in Foundry Agent Service. It starts an MCP client session and connects to the server. Then it does three jobs. It discovers the available tools, by calling session dot list tools. It generates Python function stubs that wrap those tools. And it registers those functions with your agent. From then on, the agent can call any tool in the catalog as if it were one of its own functions, with no hardcoded logic.
Wiring it into the agent
Here's how a tool actually runs. The client invokes an MCP tool with session dot call tool, passing the tool's name and its arguments. Each tool is wrapped in an async function, one the agent can call and wait on, which makes that call for it. Those functions are bundled into a function tool, which becomes part of the agent's toolset, ready for any user request. So, end to end: the server hosts tools decorated with at mcp dot tool. The client connects, and fetches the definitions with list tools. Each tool gets an async wrapper that calls call tool. The wrappers are bundled into a function tool, and registered in the agent's toolset. Now the agent can use your tools through plain conversation, with tool management kept separate from agent logic, so your system adapts as new tools arrive.
Facts from Microsoft's documentation: Connect agents to MCP server endpoints (CC BY 4.0), rewritten in Loop's own words and examples. Narration, animation, and quiz by Loop. Microsoft, Azure, and Microsoft Foundry are trademarks of Microsoft. Loop is independent and not affiliated with or endorsed by Microsoft.