Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Motivation and Context

MCP call_tool() and get_prompt() methods were attempting to serialize framework-internal arguments like response_format (a Python type), causing serialization failures when these parameters were passed through the function invocation pipeline.

Description

Added filtering to exclude non-serializable framework kwargs before passing to MCP SDK:

  • call_tool method: Added response_format to existing exclusion set and improved formatting for readability
  • get_prompt method: Added same filtering logic (previously missing)

Framework kwargs now filtered:

{"chat_options", "tools", "tool_choice", "thread", "conversation_id", "options", "response_format"}

Tests added:

  • test_mcp_tool_filters_framework_kwargs() - validates tool call filtering
  • test_mcp_prompt_filters_framework_kwargs() - validates prompt call filtering

Both tests verify that only actual tool/prompt parameters are passed to MCP session, while framework kwargs are stripped.

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.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>.NET: Python: [Bug]: MCP tool call fails with non-serializable arguments (response_format)</issue_title>
<issue_description>### Description

Bug Description

When calling an MCP tool with additional parameters like response_format, the call_tool method in _mcp.py fails because these non-serializable arguments are not filtered out before being passed to session.call_tool().

Expected Behavior

The filtered_kwargs should exclude non-serializable arguments before calling session.call_tool().

Suggested Fix

Add response_format to the exclusion list around line 762 in _mcp.py.

Code Sample

Error Messages / Stack Traces

2026-01-27 00:57:23,667 DEBUG agent_framework: Function arguments: {'code': 'import pypsa\n\n# Create an empty network\nnetwork = pypsa.Network()\n\n# Add buses to the network\nnetwork.add("Bus", "Bus 1", x=0, y=0)\nnetwork.add("Bus", "Bus 2", x=1, y=0)\nnetwork.add("Bus", "Bus 3", x=2, y=0)\n\n# Add lines between buses\nnetwork.add("Line", "Line 1", bus0="Bus 1", bus1="Bus 2", length=1.0, x=0.1, r=0.01)\nnetwork.add("Line", "Line 2", bus0="Bus 2", bus1="Bus 3", length=1.0, x=0.1, r=0.01)\n\n# Add a generator at Bus 1\nnetwork.add("Generator", "Generator 1", bus="Bus 1", p_nom=100, marginal_cost=50)\n\n# Add a load at Bus 3\nnetwork.add("Load", "Load 1", bus="Bus 3", p_set=50)\n\n# Save the network as a NetCDF file for further analysis\nnetwork_path = get_output_path("small_power_grid.nc", "powergrid")\nnetwork.export_to_netcdf(network_path)\n\nprint(f"Power grid saved to: {network_path}")', 'timeout': 1500, 'response_format': <class 'core.agent.response_models.AgentResponse'>, 'thread': <agent_framework._threads.AgentThread object at 0x72738273a660>}
2026-01-27 00:57:23,667 DEBUG agent_framework: Failed to call tool 'execute_powergrid_code'.
Traceback (most recent call last):
File "/home/danrongzhang/agora/agora/AgoraAgentMAF/.venv/lib/python3.13/site-packages/agent_framework/_mcp.py", line 768, in call_tool
result = await self.session.call_tool(tool_name, arguments=filtered_kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/danrongzhang/agora/agora/AgoraAgentMAF/.venv/lib/python3.13/site-packages/mcp/client/session.py", line 383, in call_tool
result = await self.send_request(
^^^^^^^^^^^^^^^^^^^^^^^^
...<8 lines>...
)
^
File "/home/danrongzhang/agora/agora/AgoraAgentMAF/.venv/lib/python3.13/site-packages/mcp/shared/session.py", line 263, in send_request
request_data = request.model_dump(by_alias=True, mode="json", exclude_none=True)
File "/home/danrongzhang/agora/agora/AgoraAgentMAF/.venv/lib/python3.13/site-packages/pydantic/main.py", line 464, in model_dump
return self.pydantic_serializer.to_python(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
self,
^^^^^

Package Versions

agent-framework 1.0.0b260123

Python Version

python 3.13.2

Additional Context

No response</issue_description>

<agent_instructions>Analyse this error and update the issue with your findings</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix MCP tool call failure due to non-serializable arguments Fix MCP tool/prompt calls failing with non-serializable framework arguments Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: Python: [Bug]: MCP tool call fails with non-serializable arguments (response_format)

2 participants