Skip to content

fix: MCP tools/call fails with missing 'request' positional argument#669

Open
gambletan wants to merge 2 commits intoLightning-AI:mainfrom
gambletan:fix/mcp-tools-call-request-arg
Open

fix: MCP tools/call fails with missing 'request' positional argument#669
gambletan wants to merge 2 commits intoLightning-AI:mainfrom
gambletan:fix/mcp-tools-call-request-arg

Conversation

@gambletan
Copy link
Copy Markdown

Summary

Fixes #560

  • _call_handler 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 keyword arguments. When no key matches the parameter name, bind_partial produces empty bindings and the 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 instance from the flat MCP arguments. Also handles the case where arguments are already wrapped under the parameter name.
  • Added test test_call_handler_with_flat_mcp_arguments covering both flat and wrapped argument styles.

Test plan

  • All 15 existing + new MCP unit tests pass (tests/unit/test_mcp.py)
  • New test verifies both flat args (name="Alice", age=30) and wrapped args (request={"name": "Bob", "age": 25}) resolve correctly

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LitServe MCP Bug: tools/call Always Fails

1 participant