fix: MCP tools/call fails with missing 'request' positional argument#669
Open
gambletan wants to merge 2 commits intoLightning-AI:mainfrom
Open
fix: MCP tools/call fails with missing 'request' positional argument#669gambletan wants to merge 2 commits intoLightning-AI:mainfrom
gambletan wants to merge 2 commits intoLightning-AI:mainfrom
Conversation
The `_call_handler` function assumed MCP arguments would be keyed by
the endpoint handler's parameter name (e.g. `request`), but MCP clients
send the model's fields directly as flat arguments. When there is no
key matching the parameter name, `bind_partial` produces empty bindings
and the handler call raises:
endpoint_handler() missing 1 required positional argument: 'request'
Fix: detect single-parameter handlers whose parameter is a BaseModel
subclass and construct the model from the flat MCP arguments when
the arguments are not already wrapped under the parameter name.
Fixes Lightning-AI#560
Signed-off-by: Tan <alvinttang@gmail.com>
for more information, see https://pre-commit.ci
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.
Summary
Fixes #560
_call_handlerassumed MCP arguments would be keyed by the endpoint handler's parameter name (e.g.request), but MCP clients send the model's fields directly as flat keyword arguments. When no key matches the parameter name,bind_partialproduces empty bindings and the call raisesendpoint_handler() missing 1 required positional argument: 'request'.BaseModelsubclass and construct the model instance from the flat MCP arguments. Also handles the case where arguments are already wrapped under the parameter name.test_call_handler_with_flat_mcp_argumentscovering both flat and wrapped argument styles.Test plan
tests/unit/test_mcp.py)name="Alice", age=30) and wrapped args (request={"name": "Bob", "age": 25}) resolve correctly