Skip to content

Conversation

stevenh
Copy link

@stevenh stevenh commented Sep 24, 2025

Use the original function's globals for type hint resolution when dealing with wrapped functions. This ensures that any type hints defined in the original function's module are correctly resolved.

This also includes adding common typing names for resiliency.

Fixes #1391

Motivation and Context

Fixes tool handling for wrapped methods that use annotations.

How Has This Been Tested?

Test is included.

Breaking Changes

This should be fully backwards compatible.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Tries to ensure success even if standard typing types are missing.

@stevenh stevenh requested review from a team and ochafik September 24, 2025 00:02
Copy link
Contributor

@maxisbey maxisbey left a comment

Choose a reason for hiding this comment

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

@maxisbey maxisbey added the needs more work Not ready to be merged yet, needs additional changes. label Oct 3, 2025
@stevenh
Copy link
Author

stevenh commented Oct 3, 2025

Thanks @maxisbey will do that.

@stevenh stevenh force-pushed the fix/wrapped_annotations branch from 66290b6 to 088335d Compare October 3, 2025 21:50
Use the original function's __globals__ for type hint resolution
when dealing with wrapped functions. This ensures that any type hints
defined in the original function's module are correctly resolved.

This also includes adding common typing names for resiliency.

Fixes modelcontextprotocol#1391
@stevenh stevenh force-pushed the fix/wrapped_annotations branch from 088335d to 57fe5ba Compare October 3, 2025 21:50
@stevenh
Copy link
Author

stevenh commented Oct 3, 2025

Is this what you had in mind @maxisbey ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more work Not ready to be merged yet, needs additional changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrapped tools using annotations fail
2 participants