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

  1. MCP Server

    • Hosts tools (functions)

    • Tools are exposed using @mcp.tool decorator

  2. MCP Client

    • Connects to the MCP server

    • Dynamically fetches available tools

  3. 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

FastMCP("server-name")

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:

  1. Discovers tools

    • Uses session.list_tools()

  2. Generates Python function stubs

    • Wraps each tool

  3. Registers tools with the agent

    • Makes them usable at runtime


Registering Tools with an Azure AI Agent

Tool Invocation

  • MCP tools are called using:

session.call_tool(tool_name, tool_args)

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

  1. MCP server hosts tools using @mcp.tool

  2. MCP client connects to the MCP server

  3. The client fetches tools using session.list_tools()

  4. Each tool is wrapped in an async function

  5. Async functions call tools via session.call_tool

  6. Tool functions are bundled into FunctionTool

  7. FunctionTool is registered with the agent

  8. 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

  1. Remote MCP server endpoint
    Example:

    https://api.githubcopilot.com/mcp/
  2. Microsoft Foundry agent

    • Configured to use MCP tools


Connecting Multiple MCP Servers

  • Add each MCP server as a separate tool

  • Each MCP tool includes:

PropertyDescription
    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

  1. Create an McpTool object with:

    • server_label

    • server_url

  2. Apply headers using:

    • update_headers

  3. Set approval mode using:

    • set_approval_mode

Approval Modes

  • always (default)
    Developer approval is required for every tool call

  • never
    No approval required

  1. Create a ToolSet

  2. Add the McpTool to the ToolSet

  3. Create an agent run

  4. 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

  1. Review the tool and arguments

  2. Decide whether to approve

  3. 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

Popular posts from this blog

AI-900-3,4

AI-900 12,13

AI-900 10,11