Skip to content

Commit f882357

Browse files
authored
Python: fix(core): filter out internal args when passing kwargs to MCP tools (microsoft#3292)
* fix(core): filter conversation_id when passing kwargs to MCP tools * Filter out options too * Fix uv.lock conflict
1 parent 2288628 commit f882357

4 files changed

Lines changed: 278 additions & 190 deletions

File tree

python/packages/core/agent_framework/_mcp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,12 @@ async def call_tool(self, tool_name: str, **kwargs: Any) -> list[Content] | Any
754754
# Filter out framework kwargs that cannot be serialized by the MCP SDK.
755755
# These are internal objects passed through the function invocation pipeline
756756
# that should not be forwarded to external MCP servers.
757+
# conversation_id is an internal tracking ID used by services like Azure AI.
758+
# options contains metadata/store used by AG-UI for Azure AI client requirements.
757759
filtered_kwargs = {
758-
k: v for k, v in kwargs.items() if k not in {"chat_options", "tools", "tool_choice", "thread"}
760+
k: v
761+
for k, v in kwargs.items()
762+
if k not in {"chat_options", "tools", "tool_choice", "thread", "conversation_id", "options"}
759763
}
760764

761765
# Try the operation, reconnecting once if the connection is closed

python/packages/core/agent_framework/_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,7 @@ async def _auto_invoke_function(
15501550
parsed_args: dict[str, Any] = dict(function_call_content.parse_arguments() or {})
15511551

15521552
# Filter out internal framework kwargs before passing to tools.
1553+
# conversation_id is an internal tracking ID that should not be forwarded to tools.
15531554
runtime_kwargs: dict[str, Any] = {
15541555
key: value
15551556
for key, value in (custom_args or {}).items()

python/packages/core/agent_framework/_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"FinishReason",
3434
"Role",
3535
"TextSpanRegion",
36-
"TextSpanRegion",
3736
"ToolMode",
3837
"UsageDetails",
3938
"add_usage_details",

0 commit comments

Comments
 (0)