Skip to content

fix: use functools.wraps to preserve function signatures in tool decorator#65

Open
jfenal wants to merge 1 commit into
xing5:mainfrom
jfenal:pr/tool-wrapper-fix
Open

fix: use functools.wraps to preserve function signatures in tool decorator#65
jfenal wants to merge 1 commit into
xing5:mainfrom
jfenal:pr/tool-wrapper-fix

Conversation

@jfenal
Copy link
Copy Markdown

@jfenal jfenal commented Feb 23, 2026

Summary

Fixes MCP tool calling errors by using @functools.wraps to 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:

  • Function name is preserved
  • Docstring is preserved
  • Type annotations are preserved
  • Parameter signature is correctly exposed to MCP

This allows MCP to properly determine which parameters each wrapped function accepts.

Test Plan

  • Verified tools can be called without "args" errors
  • Confirmed MCP can introspect tool signatures correctly
  • All existing functionality preserved

🤖 Created with assistance from Claude Code

…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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 functools import to support signature preservation
  • Modified the tool decorator to wrap functions with @functools.wraps(func) before passing them to mcp.tool()
  • Cleaned up trailing whitespace in the tool decorator docstring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants