fix: add explicit type annotation for call_tool decorator#1826
Merged
Kludex merged 3 commits intomodelcontextprotocol:mainfrom Jan 6, 2026
Merged
Conversation
Replace `Callable[..., Awaitable[...]]` with a concrete `CallToolHandler` type alias that specifies the exact expected function signature `(str, dict[str, Any]) -> Awaitable[...]`. This enables static type checkers (mypy/pyright) to validate decorated functions without requiring `# type: ignore` comments, making the `py.typed` marker actually useful. Fixes modelcontextprotocol#1822 Github-Issue: modelcontextprotocol#1822
There was a problem hiding this comment.
Pull request overview
This pull request improves type clarity in the call_tool decorator by introducing a CallToolHandler type alias. The change makes the function signature more explicit and easier to read by extracting the inline type definition into a reusable type alias.
- Added a
CallToolHandlertype alias that explicitly defines handler function signatures withstranddict[str, Any]parameters - Updated the
call_tooldecorator to use the new type alias, replacing the previous inlineCallable[..., Awaitable[...]]definition
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
maxisbey
reviewed
Jan 5, 2026
Kludex
approved these changes
Jan 6, 2026
call_tool decorator
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.
This pull request introduces a type alias to clarify and simplify the function signature of handlers registered with
call_toolin theserver.pymodule. The main change is the introduction and use of theCallToolHandlertype alias, which improves code readability and maintainability.Type hinting and handler signature improvements:
CallToolHandlertype alias to explicitly define the expected function signature for call tool handler functions inserver.py.call_tooldecorator to use the newCallToolHandlertype alias, replacing the previous inline type definition for better clarity and consistency.