Skip to content

Conversation

@moonbox3
Copy link
Contributor

Motivation and Context

When Azure AI returns a response with a conversation_id, it gets stored in kwargs for server-side conversation management. However, this conversation_id was being forwarded to tools that accept **kwargs, causing MCP servers to receive unexpected arguments like conversation_id='resp_0aee1...'.

  • Fixes bug where conversation_id was incorrectly passed to MCP tools when using AzureAIClient
  • The response ID (e.g., resp_0aee1...) was being sent as a tool argument instead of the actual parameters

Added conversation_id to the filter list in two places:

  1. _tools.py:_auto_invoke_function - Primary fix that filters conversation_id from runtime_kwargs
  2. _mcp.py:call_tool - Safety net filter in the MCP tool's call method

This is consistent with the fix in #3266 for agent-as-tool scenarios.

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.

@moonbox3 moonbox3 self-assigned this Jan 19, 2026
@moonbox3 moonbox3 added the agents Issues related to single agents label Jan 19, 2026
@moonbox3 moonbox3 added the mcp label Jan 19, 2026
Copilot AI review requested due to automatic review settings January 19, 2026 23:31
@moonbox3 moonbox3 requested review from dmytrostruk and eavanvalkenburg and removed request for Copilot January 19, 2026 23:32
@moonbox3 moonbox3 moved this to In Review in Agent Framework Jan 19, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 19, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py3776283%115, 175, 184, 248, 258–259, 280, 370, 392–395, 405, 440, 442, 446–447, 449–450, 453–454, 457–458, 504, 519, 537, 578, 684, 697–702, 724, 743, 746–748, 763–764, 770–772, 791, 800, 803–805, 820–821, 825–829, 846–850, 990
   _tools.py7596990%232, 278, 329, 331, 359, 529, 561–562, 664, 666, 686, 704, 718, 730, 735, 737, 744, 777, 833–835, 876, 901–910, 917–918, 920–921, 925, 961, 971, 1212, 1548, 1627–1631, 1752, 1754, 1821, 1916, 1922, 1966–1967, 1980–1981, 2028, 2114, 2155–2156, 2184–2186, 2228–2229, 2239, 2296–2297, 2304–2305
TOTAL17477267284% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3158 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 pull request fixes a bug where conversation_id was incorrectly being passed to MCP tools when using Azure AI Client. The conversation_id is an internal tracking identifier used for server-side conversation management and should not be forwarded to external tools.

Changes:

  • Added conversation_id to the filter list in _auto_invoke_function to prevent it from being passed to all tools
  • Added conversation_id to the filter list in MCP's call_tool method as an additional safety net
  • Added explanatory comments documenting why conversation_id should be filtered

Reviewed changes

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

File Description
python/packages/core/agent_framework/_tools.py Filters conversation_id from runtime kwargs before passing to tools in _auto_invoke_function
python/packages/core/agent_framework/_mcp.py Filters conversation_id from kwargs when calling MCP tools as a safety net

Now let me check if there are any issues with the changes:

The changes look correct and follow the established pattern. The filtering is consistent with similar filtering done in _agents.py for the agent-as-tool scenario (line 474). However, I notice that the PR description mentions "All unit tests pass, and I have added new tests where possible" but I don't see any new test files in the diff. Let me verify if this is a concern by checking the test coverage more thoroughly.

Based on my review:

  1. The code changes are correct and consistent with existing patterns
  2. The comments are clear and accurate
  3. The filtering approach is appropriate
  4. There's an existing test for agent-as-tool conversation_id filtering, which shows this pattern is well-understood
  5. While there don't appear to be new tests specifically for MCP tool conversation_id filtering in this PR, the fix is straightforward and follows established patterns

The changes are minimal, focused, and address the stated bug. The lack of new tests for the MCP-specific case is a minor concern but not a blocker given the simplicity of the fix and the existence of similar tests for the agent-as-tool case.

@moonbox3 moonbox3 enabled auto-merge January 20, 2026 00:37
@moonbox3 moonbox3 changed the title Python: fix(core): filter conversation_id when passing kwargs to MCP tools Python: fix(core): filter out internal args when passing kwargs to MCP tools Jan 20, 2026
@moonbox3
Copy link
Contributor Author

Handled in #3294.

@moonbox3 moonbox3 closed this Jan 20, 2026
auto-merge was automatically disabled January 20, 2026 10:59

Pull request was closed

@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Issues related to single agents mcp python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AzureAIClient based Agent with local mcp tools fails to send the right param value

3 participants