Skip to content

Conversation

@moonbox3
Copy link
Contributor

Motivation and Context

  • Fixed bug where MCP tool connections defined in YAML weren't being passed through to the Azure AI agent creation API
  • Added support for both project_connection_id (programmatic) and connection.name (declarative) patterns

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 16, 2026 07:40
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Jan 16, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 16, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _client.py1804276%239–242, 247, 250–253, 258, 261–262, 265, 272, 382, 408–411, 454, 491, 493, 498, 500–501, 504–507, 509, 511–512, 514–522, 524
   _shared.py29611860%102–103, 106–108, 111–116, 118, 149, 151, 153, 155, 200, 288–291, 294–296, 299–300, 310, 317–319, 345–354, 359, 407, 423–425, 427–444, 452–455, 458–459, 462–469, 474–475, 481–483, 486–487, 489, 501, 503–504, 507–510, 513, 515–516, 518–526, 528, 564, 566–569, 571, 577, 583, 587, 602, 605–606, 608
TOTAL17444269484% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3154 213 💤 0 ❌ 0 🔥 1m 3s ⏱️

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 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 headers or additional_properties on HostedMCPTool based on connection type
  • Updated Azure AI tool converters to extract project_connection_id from additional_properties and 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_options directly 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)]

@moonbox3 moonbox3 enabled auto-merge January 16, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: loading declarative agent from yaml fails with oauth mcp because HostedMCPTool discards connection entirely

2 participants