Skip to content

Python: Fix local MCP tools with AzureAIProjectAgentProvider#3315

Merged
giles17 merged 2 commits intomicrosoft:mainfrom
giles17:azureai_local_mcp_fix
Jan 21, 2026
Merged

Python: Fix local MCP tools with AzureAIProjectAgentProvider#3315
giles17 merged 2 commits intomicrosoft:mainfrom
giles17:azureai_local_mcp_fix

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Jan 20, 2026

Motivation and Context

Fixes an issue where MCPStreamableHTTPTool (and other local MCP tools) were not working with AzureAIProjectAgentProvider. The agent would respond using its training data instead of calling the MCP server tools.

The Azure AI Responses API requires tools to be defined on the agent at creation time - they cannot be passed at request time like with OpenAI's API. Local MCP tools (MCPTool) were being filtered out during agent creation because to_azure_ai_tools() only recognized HostedMCPTool, not local MCPTool instances.

Resolves #3303

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings January 20, 2026 23:50
@github-actions github-actions bot changed the title Fix local MCP tools with AzureAIProjectAgentProvider Python: Fix local MCP tools with AzureAIProjectAgentProvider Jan 20, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 20, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _project_provider.py110991%126–127, 204, 300, 344, 377, 426–428
TOTAL17455269884% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3186 213 💤 0 ❌ 0 🔥 1m 4s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where local MCP tools (MCPTool) were not working with AzureAIProjectAgentProvider. The Azure AI Responses API requires tools to be defined on the agent at creation time, but local MCP tools were being filtered out because the system only recognized HostedMCPTool instances.

Changes:

  • Modified create_agent to detect and connect MCP tools before agent creation, extracting their functions for Azure AI
  • Updated _merge_tools to include MCPTool instances alongside AIFunction instances for ChatAgent runtime handling
  • Added comprehensive unit tests covering MCP tool integration scenarios
  • Updated the sample to demonstrate proper MCP tool usage with context manager pattern

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
python/packages/azure-ai/agent_framework_azure_ai/_project_provider.py Core fix: Separates MCP tools from other tools, connects them early to discover functions, and passes functions to Azure AI while preserving original MCP tool instances for ChatAgent
python/packages/azure-ai/tests/test_provider.py Adds MockMCPTool helper class and two comprehensive test cases validating MCP tool connection and function discovery
python/samples/getting_started/agents/azure_ai/azure_ai_with_local_mcp.py Updates sample to extract MCP tool initialization and adds agent context manager for proper cleanup (contains duplicate print statement)

@giles17 giles17 enabled auto-merge January 21, 2026 03:56
@giles17 giles17 added this pull request to the merge queue Jan 21, 2026
Merged via the queue into microsoft:main with commit 88e0ee1 Jan 21, 2026
23 checks passed
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…soft#3315)

* azureai v2 local mcp fix

* addressed copilot comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: Official Sample azure_ai_with_local_mcp.py Does Not Work - MCPStreamableHTTPTool Not Executing with AzureAIProjectAgentProvider

3 participants

Comments