-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: fix(core): filter out internal args when passing kwargs to MCP tools #3292
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
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 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_idto the filter list in_auto_invoke_functionto prevent it from being passed to all tools - Added
conversation_idto the filter list in MCP'scall_toolmethod as an additional safety net - Added explanatory comments documenting why
conversation_idshould 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:
- The code changes are correct and consistent with existing patterns
- The comments are clear and accurate
- The filtering approach is appropriate
- There's an existing test for agent-as-tool conversation_id filtering, which shows this pattern is well-understood
- 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.
|
Handled in #3294. |
Motivation and Context
When Azure AI returns a response with a
conversation_id, it gets stored inkwargsfor server-side conversation management. However, thisconversation_idwas being forwarded to tools that accept**kwargs, causing MCP servers to receive unexpected arguments likeconversation_id='resp_0aee1...'.conversation_idwas incorrectly passed to MCP tools when usingAzureAIClientresp_0aee1...) was being sent as a tool argument instead of the actual parametersAdded
conversation_idto the filter list in two places:_tools.py:_auto_invoke_function- Primary fix that filtersconversation_idfromruntime_kwargs_mcp.py:call_tool- Safety net filter in the MCP tool's call methodThis is consistent with the fix in #3266 for agent-as-tool scenarios.
Description
Contribution Checklist