-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: fix(declarative): Fix MCP tool connection not passed from YAML to Azure AI agent creation API #3248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
There was a problem hiding this 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 a bug where MCP (Model Context Protocol) tool connection configurations defined in YAML weren't being passed through to the Azure AI agent creation API. The fix adds support for passing connection information via additional_properties when creating MCP tools from declarative YAML definitions.
Changes:
- Added connection handling in declarative YAML parser to set
headersoradditional_propertiesonHostedMCPToolbased on connection type - Updated Azure AI tool converters to extract
project_connection_idfromadditional_propertiesand use it in preference to headers - Added comprehensive unit tests for all connection types (API key, remote, reference, anonymous)
- Added declarative MCP tool sample demonstrating both API key and Azure AI Foundry connection patterns
- Updated sample documentation README
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
python/uv.lock |
Dependency lock file updates (removed s390x wheels for greenlet, updated regex package version) |
python/samples/getting_started/declarative/mcp_tool_yaml.py |
New sample demonstrating MCP tool configuration with API key and Azure Foundry connection authentication |
python/samples/README.md |
Added Declarative section with links to new and existing samples |
python/packages/declarative/tests/test_declarative_loader.py |
Comprehensive tests for MCP tool connection handling covering all connection types |
python/packages/declarative/agent_framework_declarative/_loader.py |
Core fix: parse tool connection info and set headers/additional_properties; added async agent creation methods for provider-based approach |
python/packages/azure-ai/agent_framework_azure_ai/_shared.py |
Extract project_connection_id from additional_properties when converting tools to/from Azure AI format |
python/packages/azure-ai/agent_framework_azure_ai/_client.py |
Extract project_connection_id from additional_properties in _prepare_mcp_tool method |
Comments suppressed due to low confidence (1)
python/packages/declarative/tests/test_declarative_loader.py:705
- The helper method accesses
agent.default_optionsdirectly without verifying it exists. Per the C# unit test guidelines that apply broadly, tests should validate expected structure. Consider adding a check or comment explaining why this is safe.
def _get_mcp_tools(self, agent):
"""Helper to get MCP tools from agent's default_options."""
from agent_framework import HostedMCPTool
tools = agent.default_options.get("tools", [])
return [t for t in tools if isinstance(t, HostedMCPTool)]
Motivation and Context
project_connection_id(programmatic) andconnection.name(declarative) patternsDescription
Contribution Checklist