Integrate MCP Tools with Azure AI Agents
Integrate MCP Tools with Azure AI Agents
Why Tool Discovery Matters
-
As AI agents become more powerful, they need access to many tools and services
-
Manually:
-
Registering tools
-
Updating integrations
-
Managing authentication
becomes complex and time-consuming
-
-
Dynamic tool discovery solves this problem
Microsoft Connector Protocol (MCP)
What is MCP?
-
MCP = Microsoft Connector Protocol
-
A standard way for AI agents to:
-
Discover tools
-
Authenticate securely
-
Use tools dynamically at runtime
-
Advantages of MCP for AI Agents
1. Dynamic Tool Discovery
-
AI agents automatically receive:
-
List of available tools
-
Tool descriptions and capabilities
-
-
No hardcoded APIs in agent code
-
“Integrate once” approach
-
Reduces maintenance when tools change
2. Interoperability Across LLMs
-
MCP works with multiple LLMs
-
You can:
-
Switch models
-
Test different LLMs
without rewriting integrations
-
3. Standardized Security
-
MCP provides consistent authentication
-
No need to manage:
-
Multiple API keys
-
Different auth methods per tool
-
-
Easier to scale AI agent deployments securely
What is Dynamic Tool Discovery?
-
A mechanism where an AI agent:
-
Does not have hardcoded tool knowledge
-
Queries an MCP server at runtime
-
-
The MCP server acts as a live tool catalog
Key Benefits of Dynamic Tool Discovery
-
Tools can be:
-
Added
-
Updated
-
Removed
without changing agent code
-
-
Agents always use the latest tool versions
-
Tool complexity is handled by the server, not the agent
How MCP Enables Dynamic Tool Discovery
MCP Architecture Flow
-
MCP Server
-
Hosts tools (functions)
-
Tools are exposed using
@mcp.tooldecorator
-
-
MCP Client
-
Connects to the MCP server
-
Dynamically fetches available tools
-
-
Azure AI Agent
-
Receives tool definitions
-
Uses tools to fulfill user requests
-
MCP Tools
-
Tools are a primitive type in MCP
-
Represent executable functionality
-
Client generates function wrappers
-
These wrappers are added to:
-
Azure AI Agent’s tool definitions
-
Key Benefits
-
Scalability
Add or update tools without redeploying agents -
Modularity
Agents focus on decision-making, not tool logic -
Maintainability
Centralized tool management reduces errors -
Flexibility
Supports multiple tools, APIs, and complex workflows
When MCP is Especially Useful
-
Rapidly evolving tools and APIs
-
Multiple teams managing different services
-
Agents that need to:
-
Adapt in real time
-
Interact securely with external systems
-
Perform actions beyond text generation
-
Summary
-
MCP enables dynamic, secure, scalable tool usage
-
Agents become adaptive and future-proof
-
Tool management shifts from agent code to a central MCP service
Integrate Agent Tools Using an MCP Server and Client
Purpose
-
To dynamically connect tools to an Azure AI Agent
-
Uses Model Context Protocol (MCP)
-
Requires:
-
MCP Server → hosts tools
-
MCP Client → fetches and registers tools for the agent
-
MCP Server:
Role
-
Acts as a tool registry/catalog
-
Stores all the tools the agent can use
Initialization
Key Features
-
Uses:
-
Python type hints
-
Docstrings
-
-
Automatically generates tool definitions
-
Tool definitions are:
-
Served over HTTP
-
Centralized on the server
-
Benefits
-
Tools can be:
-
Added
-
Updated
-
Removed
without modifying or redeploying the agent
-
-
Clean separation between tools and agent logic
MCP Client:
Role
-
Acts as a bridge between:
-
MCP Server
-
Azure AI Agent Service
-
Responsibilities
After initializing a session, the MCP client:
-
Discovers tools
-
Uses
session.list_tools()
-
-
Generates Python function stubs
-
Wraps each tool
-
-
Registers tools with the agent
-
Makes them usable at runtime
-
Registering Tools with an Azure AI Agent
Tool Invocation
-
MCP tools are called using:
Important Requirements
-
Each tool must be wrapped in an async function
-
Enables the agent to:
-
Invoke tools during conversation
-
Use them like native functions
-
Making Tools Available to the Agent
Process
-
Wrapped async functions are bundled into a FunctionTool
-
The FunctionTool is:
-
Registered with the agent’s toolset
-
-
Tools are available at runtime for user requests
MCP Agent Tool Integration Flow
-
MCP server hosts tools using
@mcp.tool -
MCP client connects to the MCP server
-
The client fetches tools using
session.list_tools() -
Each tool is wrapped in an async function
-
Async functions call tools via
session.call_tool -
Tool functions are bundled into
FunctionTool -
FunctionTool is registered with the agent
-
Agent invokes tools using natural language
Key Benefits of This Architecture
-
Dynamic – No hardcoded tools
-
Scalable – Add tools without redeploying agents
-
Modular – Tool logic separate from agent logic
-
Maintainable – Centralized tool management
-
Flexible – Agent adapts as new tools become available
Summary
By integrating an MCP server and client:
-
Tool management becomes centralized
-
Agents become adaptive and extensible
-
Systems evolve easily as new tools are introduced
Use Azure AI Agents with MCP Servers
Purpose
-
Enhance Microsoft Foundry agents by connecting them to MCP servers
-
MCP servers provide:
-
External tools
-
Contextual data
-
-
Extends agent capabilities beyond built-in functions
Key Advantage
-
Azure AI Agent Service supports remote MCP servers
-
Agents can quickly connect to MCP servers and use tools
-
No need to manually manage MCP client sessions
How MCP Integration Works (Simplified)
When using Microsoft Foundry Agent Service:
-
You do NOT need to:
-
Create an MCP client session
-
Manually wrap or register function tools
-
-
Instead:
-
Create an MCP Tool object
-
Attach the MCP server details during the agent run
-
This allows using multiple MCP servers in a single agent, based on need
Integrating Remote MCP Servers
Requirements
-
Remote MCP server endpoint
Example: -
Microsoft Foundry agent
-
Configured to use MCP tools
-
Connecting Multiple MCP Servers
-
Add each MCP server as a separate tool
-
Each MCP tool includes:
| Property | Description |
|---|---|
| server_label | Unique identifier (e.g., GitHub) |
| server_url | MCP server URL |
| allowed_tools (optional) | Tools the agent is allowed to access |
MCP Tool Headers
Custom Headers Support
-
MCP tools can include headers for:
-
Authentication (API keys, OAuth tokens)
-
Other required server headers
-
Important Notes
-
Headers are:
-
Included in tool_resources during each run
-
Not stored between runs
-
Invoking MCP Tools Automatically
Key Difference
-
No need to:
-
Wrap tools
-
Call
session.call_tool
-
-
Tools are invoked automatically when needed
Steps to Use MCP Tools in an Agent Run
-
Create an McpTool object with:
-
server_label -
server_url
-
-
Apply headers using:
-
update_headers
-
-
Set approval mode using:
-
set_approval_mode
-
Approval Modes
-
always(default)
Developer approval is required for every tool call -
never
No approval required
-
Create a ToolSet
-
Add the McpTool to the ToolSet
-
Create an agent run
-
Specify the toolset property
Handling Tool Approval (requires_action)
-
If approval is required:
-
Run status becomes requires_action
-
-
In
requires_action, you get:-
Tool name
-
MCP server details
-
Arguments to be passed
-
Approval Flow
-
Review the tool and arguments
-
Decide whether to approve
-
Submit approval using:
-
call_id -
approve = true
-
Results
-
When the run completes:
-
Tool results appear in the agent response
-
-
Agent uses tools naturally via language-based reasoning
Key Benefits of MCP with Azure AI Agents
-
Richer, context-aware agents
-
Secure external tool access
-
Multiple MCP servers per agent
-
Dynamic tool availability
-
No redeployment when tools change
Summary
-
MCP integration enables powerful, flexible, and scalable AI agents
-
As MCP ecosystem grows:
-
Agents become smarter
-
Workflows become more dynamic
-
Tool usage becomes seamless
-
Comments
Post a Comment