-
Notifications
You must be signed in to change notification settings - Fork 0
Fix MCP tools to ignore extra parameters from remote clients #1
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
Co-authored-by: egallis31 <18443524+egallis31@users.noreply.github.com>
|
@copilot [11/22/25 04:17:31] Error validating tool 'read_neo4j_cypher': 2 validation |
I've investigated this issue extensively. The errors show that MCP clients are sending parameters in a flat structure (e.g., My initial implementation using Pydantic BaseModel with I've tried multiple approaches to make tools ignore extra parameters while keeping the flat parameter structure:
The root cause: FastMCP creates TypeAdapters from function signatures with Pydantic's default Questions:
I can proceed with the BaseModel approach (which requires wrapping parameters), but this will be a breaking change for existing clients. Let me know how you'd like to proceed.
I've successfully implemented a solution that allows tools to ignore extra parameters while maintaining backward compatibility. Solution: Wraps each tool's Changes in commit b3e4d81:
The solution filters parameters at runtime based on each tool's function signature, so only expected parameters are passed to validation. Extra parameters are logged at debug level and silently ignored. |
- Implemented filtering wrapper that intercepts tool.run() to remove unknown parameters - Preserves flat parameter structure (backward compatible) - All existing tests pass + new test for extra parameter handling - Solution wraps get_tool() to lazily apply filtering to each tool Co-authored-by: egallis31 <18443524+egallis31@users.noreply.github.com>
Co-authored-by: egallis31 <18443524+egallis31@users.noreply.github.com>
- Use default_factory for mutable dict defaults - Add type annotation for wrapped_tools set Co-authored-by: egallis31 <18443524+egallis31@users.noreply.github.com>
Description
MCP tools fail when remote clients send additional parameters due to Pydantic V2's default
extra='forbid'behavior. This breaks compatibility with clients that include metadata or context fields likesessionId,action,chatInput, andtoolCallId.Changes
Implemented a filtering wrapper that intercepts tool execution to remove unknown parameters before validation:
Solution:
_wrap_tool_to_filter_params()function that wraps each tool'srun()methodcreate_mcp_server()to interceptget_tool()and lazily apply filteringinspectImplementation:
This approach:
get_tool()Type of Change
Complexity
Complexity: Runtime parameter filtering with function signature inspection.
How Has This Been Tested?
Added
test_tools_ignore_extra_parametersverifying all three tools (get_neo4j_schema, read_neo4j_cypher, write_neo4j_cypher) handle unexpected fields likesessionId,action,chatInput, andtoolCallIdcorrectly. All 9 integration tests pass (8 existing + 1 new).Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.