Skip to content

Conversation

@gavin-aguiar
Copy link
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.

@gavin-aguiar gavin-aguiar requested a review from a team as a code owner January 21, 2026 18:12
Copilot AI review requested due to automatic review settings January 21, 2026 18:12
@gavin-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
@github-actions github-actions bot 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
Copy link
Member

markwallace-microsoft commented Jan 21, 2026

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

Tests Skipped Failures Errors Time
3229 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 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.

File Description
python/packages/azurefunctions/agent_framework_azurefunctions/_app.py Updated _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.py Added 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

@gavin-aguiar gavin-aguiar added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit b072df3 Jan 22, 2026
23 checks passed
@larohra larohra deleted the gaaguiar/mcp_fix branch January 22, 2026 23:43
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.

5 participants