fix: detect context on callable tool objects#2817
Open
fengjikui wants to merge 1 commit into
Open
Conversation
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.
Fixes #1974.
Summary
find_context_parameter()previously inspected callable object instances directly withtyping.get_type_hints(). For instances that implement__call__, those type hints live on the bound__call__method, so actx: Contextparameter was not detected. That meant callable-object tools exposedctxas a required external tool argument instead of letting the framework inject it.This updates context detection to inspect
fn.__call__for callable objects while preserving the existing path for regular functions and methods. It also adds regression coverage for both schema generation and runtime context injection on callable-object tools.Validation
uv run --frozen pytest tests/server/mcpserver/test_tool_manager.py -quv run --frozen ruff check src/mcp/server/mcpserver/utilities/context_injection.py tests/server/mcpserver/test_tool_manager.pyuv run --frozen ruff format --check src/mcp/server/mcpserver/utilities/context_injection.py tests/server/mcpserver/test_tool_manager.pyuv run --frozen pyrightenv -u ALL_PROXY -u HTTP_PROXY -u HTTPS_PROXY -u all_proxy -u http_proxy -u https_proxy ./scripts/testgit diff --checkThis PR was prepared with AI assistance and manually validated with the checks above.