Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Dec 6, 2025

Follow-up to #2563 which fixed the signature handling in create_function_without_params. PR #2563 added unit tests for the utility function itself, but lacked integration tests for the actual user-facing scenario from #2524.

These tests ensure decorated functions with functools.wraps and Context parameters work correctly across all object types:

  • Tools: Both ToolManager-level and idiomatic @mcp.tool + Client
  • Prompts: Prompt.from_function with decorated functions
  • Resource Templates: ResourceTemplate.from_function with decorated functions
def custom_decorator(func):
    @functools.wraps(func)
    async def wrapper(*args, **kwargs):
        return await func(*args, **kwargs)
    return wrapper

@mcp.tool
@custom_decorator
async def my_tool(ctx: Context, query: str) -> str:
    return f"query: {query}"

Closes #2524

Follow-up to PR #2563 which fixed the signature handling in
create_function_without_params. These tests ensure the fix
works end-to-end for all object types that support Context injection.
@marvin-context-protocol marvin-context-protocol bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. tests labels Dec 6, 2025
@jlowin jlowin merged commit 0cf12fa into main Dec 6, 2025
12 checks passed
@jlowin jlowin deleted the test/functools-wraps-regression-2524 branch December 6, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError: 'ctx' when registering Context-dependent tool wrapped by async decorator (fastmcp>=2.13.2)

2 participants