fix: use functools.wraps to preserve function signatures in tool decorator#65
Open
jfenal wants to merge 1 commit into
Open
fix: use functools.wraps to preserve function signatures in tool decorator#65jfenal wants to merge 1 commit into
jfenal wants to merge 1 commit into
Conversation
…rator MCP's tool calling mechanism was failing with "unexpected keyword argument 'args'" errors because the tool decorator wasn't properly preserving function signatures. This fix adds @functools.wraps to the wrapper function, which ensures that the function's name, docstring, annotations, and signature are correctly preserved for MCP's introspection. Without this fix, MCP cannot properly determine which parameters the wrapped function accepts, leading to parameter passing errors at runtime.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes MCP tool calling errors by adding @functools.wraps to preserve function signatures in the custom tool decorator. The Google Sheets MCP server uses a custom @tool() decorator to conditionally register tools based on configuration. The fix ensures that when tools are registered with MCP, their function signatures and metadata are properly preserved for MCP's introspection mechanisms.
Changes:
- Added
functoolsimport to support signature preservation - Modified the tool decorator to wrap functions with
@functools.wraps(func)before passing them tomcp.tool() - Cleaned up trailing whitespace in the tool decorator docstring
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes MCP tool calling errors by using
@functools.wrapsto properly preserve function signatures in the tool decorator wrapper.Problem
MCP's tool calling mechanism was failing with "unexpected keyword argument 'args'" errors because the custom tool decorator wasn't preserving function signatures for MCP's introspection.
Solution
Added
@functools.wraps(func)to the wrapper function, ensuring that:This allows MCP to properly determine which parameters each wrapped function accepts.
Test Plan
🤖 Created with assistance from Claude Code