Skip to content

Commit 0dcebc6

Browse files
authored
Python: Filter framework kwargs from MCP tool invocations (#2870)
* Filter framework kwargs from MCP tool invocations * Fixes
1 parent e0ff153 commit 0dcebc6

File tree

1 file changed

+9
-1
lines changed
  • python/packages/core/agent_framework

1 file changed

+9
-1
lines changed

python/packages/core/agent_framework/_mcp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,16 @@ async def call_tool(self, tool_name: str, **kwargs: Any) -> list[Contents]:
685685
raise ToolExecutionException(
686686
"Tools are not loaded for this server, please set load_tools=True in the constructor."
687687
)
688+
# Filter out framework kwargs that cannot be serialized by the MCP SDK.
689+
# These are internal objects passed through the function invocation pipeline
690+
# that should not be forwarded to external MCP servers.
691+
filtered_kwargs = {
692+
k: v for k, v in kwargs.items() if k not in {"chat_options", "tools", "tool_choice", "thread"}
693+
}
688694
try:
689-
return _mcp_call_tool_result_to_ai_contents(await self.session.call_tool(tool_name, arguments=kwargs))
695+
return _mcp_call_tool_result_to_ai_contents(
696+
await self.session.call_tool(tool_name, arguments=filtered_kwargs)
697+
)
690698
except McpError as mcp_exc:
691699
raise ToolExecutionException(mcp_exc.error.message, inner_exception=mcp_exc) from mcp_exc
692700
except Exception as ex:

0 commit comments

Comments
 (0)