Skip to content

Commit e29a177

Browse files
Merge pull request #51218 from buzahid/ai-agents
New Module - Integrate MCP Tools with Azure AI Agents
2 parents b3a17b5 + 66cfff7 commit e29a177

File tree

14 files changed

+238
-0
lines changed

14 files changed

+238
-0
lines changed

learn-pr/paths/develop-ai-agents-on-azure/index.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ modules:
3131
- learn.wwl.develop-ai-agent-with-semantic-kernel
3232
- learn.wwl.orchestrate-sk-multi-agent-solution
3333
- learn.wwl.develop-multi-agent-azure-ai-foundry
34+
- learn.wwl.connect-agent-to-mcp-tools
3435
trophy:
3536
uid: learn.wwl.develop-ai-agent-on-azure.trophy
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.connect-agent-to-mcp-tools.introduction
3+
title: Introduction
4+
metadata:
5+
title: Introduction
6+
description: "Learn how to integrate Model Context Protocol (MCP) tools with Azure AI Agents."
7+
ms.date: 06/13/2025
8+
author: buzahid
9+
ms.author: buzahid
10+
ms.topic: unit
11+
durationInMinutes: 2
12+
content: |
13+
[!include[](includes/1-introduction.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.connect-agent-to-mcp-tools.understand-mcp-tool-discovery
3+
title: Understand MCP tool discovery
4+
metadata:
5+
title: Understand MCP Tool Discovery
6+
description: "Learn how Model Context Protocol (MCP) servers host functions that can be discovered by LLMs."
7+
ms.date: 06/13/2025
8+
author: buzahid
9+
ms.author: buzahid
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/2-understand-mcp-tool-discovery.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.connect-agent-to-mcp-tools.mcp-client-server-setup
3+
title: Integrate agent tools using an MCP server and client
4+
metadata:
5+
title: Integrate Agent Tools Using an MCP Server and Client
6+
description: "Learn how to expose Model Context Protocol (MCP) tools through a server and register them to an Azure AI Agent."
7+
ms.date: 06/13/2025
8+
author: buzahid
9+
ms.author: buzahid
10+
ms.topic: unit
11+
durationInMinutes: 5
12+
content: |
13+
[!include[](includes/3-mcp-client-server-setup.md)]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.connect-agent-to-mcp-tools.exercise
3+
title: Exercise - Connect MCP tools to Azure AI Agents
4+
metadata:
5+
title: Exercise - Connect MCP Tools to Azure AI Agents
6+
description: "Build a Model Context Protocol (MCP) client-server application that dynamically registers tools to an Azure AI Agent."
7+
ms.date: 06/13/2025
8+
author: buzahid
9+
ms.author: buzahid
10+
ms.topic: unit
11+
durationInMinutes: 30
12+
content: |
13+
[!include[](includes/4-exercise.md)]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.connect-agent-to-mcp-tools.knowledge-check
3+
title: Module assessment
4+
metadata:
5+
title: Module Assessment
6+
description: "Check your learning on connecting Model Context Protocol (MCP) tools to Azure AI Agents."
7+
ms.date: 06/13/2025
8+
author: buzahid
9+
ms.author: buzahid
10+
ms.topic: unit
11+
durationInMinutes: 3
12+
content: |
13+
quiz:
14+
questions:
15+
- content: "What role does the MCP server play in the MCP agent tool integration?"
16+
choices:
17+
- content: "Runs the AI agent and processes user prompts directly."
18+
isCorrect: false
19+
explanation: "Incorrect. The server hosts tools; the agent processes prompts."
20+
- content: "Manages network connections between multiple agents."
21+
isCorrect: false
22+
explanation: "Incorrect. The server focuses on tool hosting, not agent networking."
23+
- content: "Hosts tool definitions and makes them available for discovery by the client."
24+
isCorrect: true
25+
explanation: "Correct. The MCP server acts as a central registry for tool definitions."
26+
- content: "How does an MCP client retrieve available tools from the MCP server?"
27+
choices:
28+
- content: "By calling `session.list_tools()` to get the current tool catalog."
29+
isCorrect: true
30+
explanation: "Correct. The client uses `list_tools()` to discover tools dynamically."
31+
- content: "By reading a static JSON file from the server directory."
32+
isCorrect: false
33+
explanation: "Incorrect. Tools are discovered dynamically, not via static files."
34+
- content: "By subscribing to server events via a WebSocket connection."
35+
isCorrect: false
36+
explanation: "Incorrect. The client uses direct calls, not event subscriptions, to list tools."
37+
- content: "Why should MCP tools be wrapped in async functions on the client-side?"
38+
choices:
39+
- content: "To allow the agent to wait for user input."
40+
isCorrect: false
41+
explanation: "Incorrect. The tools do not prevent the agent from receiving user input."
42+
- content: "To enable asynchronous invocation so the agent can call tools without blocking."
43+
isCorrect: true
44+
explanation: "Async functions let the agent invoke tools efficiently."
45+
- content: "To convert the functions into REST API endpoints automatically."
46+
isCorrect: false
47+
explanation: "Incorrect. Wrapping tools in async functions does not generate REST endpoints."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### YamlMime:ModuleUnit
2+
uid: learn.wwl.connect-agent-to-mcp-tools.summary
3+
title: Summary
4+
metadata:
5+
title: Summary
6+
description: "Reflect on what you learned about Model Context Protocol (MCP) agent tools."
7+
ms.date: 06/13/2025
8+
author: buzahid
9+
ms.author: buzahid
10+
ms.topic: unit
11+
durationInMinutes: 1
12+
content: |
13+
[!include[](includes/6-summary.md)]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AI agents are capable of performing a wide range of tasks, but many tasks still require them to interact with tools outside the large language model. Agents may need to access APIs, databases, or internal services. Manually integrating and maintaining these tools can quickly become complex, especially as your system grows, or changes frequently.
2+
3+
Model Context Protocol (MCP) servers can help solve this problem by integrating with AI agents. Connecting an Azure AI Agent to a Model Context Protocol (MCP) server can provide your agent with a catalog of tools accessible on demand. This approach makes your AI solution more robust, scalable, and easier to maintain.
4+
5+
Suppose you're working for a retailer that specializes in cosmetics. Your team wants to build an AI assistant that can help manage inventory by checking product stock levels and recent sales trends. Using an MCP server, you can connect the assistant to a set of tools that can make inventory assessments and provide recommendations to the team.
6+
7+
In this module, you learn how to set up an MCP server and client, and connect tools to an Azure AI Agent dynamically. You also practice creating your own AI MCP tool solution with Azure AI Foundry Agent Service.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
As AI agents become more capable, the range of tools and services they can access also grows. However, registering new tools, managing, updating, and integrating them can quickly become complex and time-consuming. Dynamic tool discovery helps solve this problem by enabling agents to find and use tools automatically at runtime.
2+
3+
## What is dynamic tool discovery?
4+
5+
Dynamic tool discovery is a mechanism that allows an AI agent to discover available external tools without needing hardcoded knowledge of each one. Instead of manually adding or updating every tool your agent can use, the agent queries a centralized Model Context Protocol (MCP) server. This server acts as a live catalog, exposing tools that the agent can understand and call.
6+
7+
This approach means:
8+
9+
- Tools can be added, updated, or removed centrally without modifying the agent code.
10+
- Agents can always use the latest version of a tool, improving accuracy and reliability.
11+
- The complexity of managing tools shifts away from the agent and into a dedicated service.
12+
13+
## How does MCP enable dynamic tool discovery?
14+
15+
An MCP server hosts a set of functions that are exposed as tools using the `@mcp.tool` decorator. Tools are a primitive type in the MCP that enables servers to expose executable functionality to clients. A client can connect to the server and fetch these tools dynamically. The client then generates function wrappers that are added to the Azure AI Agent's tool definitions. This setup creates a flexible pipeline:
16+
17+
- The MCP server hosts available tools.
18+
- The MCP client dynamically discovers the tools.
19+
- The Azure AI Agent uses the available tools to respond to user requests.
20+
21+
## Why use dynamic tool discovery with MCP?
22+
23+
This approach provides several benefits:
24+
25+
- Scalability: Easily add new tools or update existing ones without redeploying agents.
26+
- Modularity: Agents can remain simple, focusing on delegation rather than managing tool details.
27+
- Maintainability: Centralized tool management reduces duplication and errors.
28+
- Flexibility: Supports diverse tool types and complex workflows by aggregating capabilities.
29+
30+
Dynamic tool discovery is especially useful in environments where tools evolve rapidly or where many teams manage different APIs and services. Using tools allows AI agents to adapt to changing capabilities in real time, interact with external systems securely, and perform actions that go beyond language generation.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
To dynamically connect tools to your Azure AI Agent, you first need a functioning Model Context Protocol (MCP) setup. This includes both the MCP server, which hosts your tool catalog, and the MCP client, which fetches those tools and makes them usable by your agent.
2+
3+
## What is the MCP Server?
4+
5+
The MCP server acts as a registry for tools your agent can use. You can initialize your MCP server using `FastMCP("server-name")`. The FastMCP class uses Python type hints and document strings to automatically generate tool definitions, making it easy to create and maintain MCP tools. These definitions are then served over HTTP when requested by the client. Because tool definitions live on the server, you can update or add new tools at any time, without having to modify or redeploy your agent.
6+
7+
## What is the MCP Client?
8+
9+
The MCP client acts as a bridge between your MCP server and the Azure AI Agent Service. The client initializes an MCP client session and connects to the server. Afterwards, it performs three key tasks:
10+
11+
- Discovers available tools from the MCP server using `session.list_tools()`.
12+
- Generates Python function stubs that wrap the tools.
13+
- Registers those functions with your agent.
14+
15+
This allows the agent to call any tool listed in the MCP catalog as if it were a native function, all without hardcoded logic.
16+
17+
## Register tools with an Azure AI Agent
18+
19+
When an MCP client session is initialized, the client can dynamically pull in tools from the MCP server. An MCP tool can be invoked using `session.call_tool(tool_name, tool_args)`. The tools should each be wrapped in an async function so that the agent is able to invoke them. Finally, those functions are bundled together and become part of the agent's toolset and are available during runtime for any user request.
20+
21+
**Overview of MCP agent tool integration**
22+
23+
- The **MCP server** hosts tool definitions decorated with `@mcp.tool`.
24+
- The **MCP client** initializes an MCP client connection to the server.
25+
- The **MCP client** fetches the available tool definitions with `session.list_tools()`.
26+
- Each tool is wrapped in an async function that invokes `session.call_tool`
27+
- The tool functions are bundled into `FunctionTool` that makes them usable by the agent.
28+
- The `FunctionTool` is registered to the agent's toolset.
29+
30+
Now your agent is able to access and invoke your tools through natural language interaction. By setting up the MCP server and client, you create a clean separation between tool management and agent logic—enabling your system to adapt quickly as new tools become available.

0 commit comments

Comments
 (0)