Skip to content

Python: Fix azurefunctions MCP tool invocation to use correct agent - #3339

Merged
Gavin Aguiar (gavin-aguiar) merged 3 commits into
mainfrom
gaaguiar/mcp_fix
Jan 22, 2026
Merged

Python: Fix azurefunctions MCP tool invocation to use correct agent #3339
Gavin Aguiar (gavin-aguiar) merged 3 commits into
mainfrom
gaaguiar/mcp_fix

Conversation

@gavin-aguiar

Copy link
Copy Markdown
Contributor

Motivation and Context

Summary

Fixed an issue for MCP tool invocations to route to the correct agent based on the thread id.

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.

CopilotAI review requested due to automatic review settings January 21, 2026 18:12
@gavin-aguiarGavin Aguiar (gavin-aguiar) changed the title Fix azurefunctions MCP tool invocation to use correct agent entity based Fix azurefunctions MCP tool invocation to use correct agent Jan 21, 2026
@markwallace-microsoftMark Wallace (markwallace-microsoft) added the python Usage: [Issues, PRs], Target: Python label Jan 21, 2026
@github-actionsgithub-actionsBot changed the title Fix azurefunctions MCP tool invocation to use correct agent Python: Fix azurefunctions MCP tool invocation to use correct agent Jan 21, 2026
@markwallace-microsoft

Mark Wallace (markwallace-microsoft) commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azurefunctions/agent_framework_azurefunctions
_app.py3748377%197–198, 203–204, 422, 430–431, 451–453, 459–461, 467–469, 502–503, 563–564, 613–614, 619, 699, 702, 711–713, 715–717, 719, 721, 732, 734–737, 739, 741–742, 744, 751–752, 754–755, 757–758, 760, 764, 774–776, 778–779, 781–783, 790, 792–793, 795, 816, 821, 833, 909, 921, 928–930, 975, 989, 1000–1002, 1004–1007, 1032, 1039, 1041, 1044
_models.py1551292%212, 215, 218, 230, 233, 252, 255, 260, 265, 282, 341, 360
TOTAL17482270484%

Python Unit Test Overview

TestsSkippedFailuresErrorsTime
3229213 💤0 ❌0 🔥1m 4s ⏱️

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 an issue in the MCP tool invocation flow where the agent entity routing was incorrectly using the agent name embedded in the threadId parameter instead of the agent_name parameter passed to the handler function. The fix ensures that MCP tool invocations always route to the correct agent entity based on the invoked agent, not the agent name potentially stored in the thread ID from a previous conversation.

Changes:

  • Modified thread ID parsing logic to extract only the session key from thread_id while always using the agent_name parameter for entity routing
  • Added comprehensive test coverage for the scenario where thread_id contains a different agent name than the invoked agent

Reviewed changes

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

FileDescription
python/packages/azurefunctions/agent_framework_azurefunctions/_app.pyUpdated _handle_mcp_tool_invocation to parse thread_id differently - extracting only the key portion while using the agent_name parameter for the entity name
python/packages/azurefunctions/tests/test_app.pyAdded test case test_handle_mcp_tool_invocation_ignores_agent_name_in_thread_id to verify the fix works correctly when thread_id contains a different agent name

Comment threadpython/packages/azurefunctions/agent_framework_azurefunctions/_app.py Outdated
Comment threadpython/packages/azurefunctions/agent_framework_azurefunctions/_app.py Outdated
Comment threadpython/packages/azurefunctions/tests/test_app.py
Comment threadpython/packages/azurefunctions/agent_framework_azurefunctions/_app.py Outdated
Merged via the queue into main with commit b072df3Jan 22, 2026
23 checks passed
@larohra
Laveesh Rohra (larohra) deleted the gaaguiar/mcp_fix branch January 22, 2026 23:43
Aris Nguyen (arisng) pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…icrosoft#3339)
* MCP tool fix for azurefunctions
* Moving logic to check for thread id
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pythonUsage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@gavin-aguiar@markwallace-microsoft@larohra@hallvictoria