Skip to content

fix: accept both 'tool' and 'tool_name' on /v1/mcp/execute#1285

Merged
jundot merged 1 commit into
jundot:mainfrom
mvanhorn:fix/1113-accept-both-tool-and-tool-name-on-v1-mcp-execute
May 19, 2026
Merged

fix: accept both 'tool' and 'tool_name' on /v1/mcp/execute#1285
jundot merged 1 commit into
jundot:mainfrom
mvanhorn:fix/1113-accept-both-tool-and-tool-name-on-v1-mcp-execute

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Two camps of MCP clients send the target tool as either tool or tool_name in the /v1/mcp/execute payload. omlx accepted tool_name only, so clients sending tool got a 422 even though their request was otherwise valid. Accepts both field names, with tool_name taking precedence when both are present.

Why this matters

#1113 reports the field-name drift; the workaround is a wrapper that rewrites the field, which is friction for every new client. Aligns omlx with the de-facto behavior across MCP servers.

Changes

  • omlx/api/openai_models.py - accept either field on the MCP execute model.
  • tests/integration/test_server_endpoints.py - tests covering tool-only, tool_name-only, both-present (precedence), and neither (still rejects).

Testing

New integration tests + existing endpoint tests pass locally.

Fixes #1113

Various MCP clients send either `tool` or `tool_name` to specify the
tool to invoke. omlx accepted `tool_name` only and rejected `tool`,
breaking parity with the spec drift seen across clients. Accept both
field names with `tool_name` taking precedence when both are present.

Fixes jundot#1113
@jundot

jundot commented May 19, 2026

Copy link
Copy Markdown
Owner

Thanks! Clean use of AliasChoices, and the precedence ordering does what the PR body says. I'll merge and tack on a couple more test cases for the alias paths in a follow-up.

@jundot jundot merged commit 06d7a78 into jundot:main May 19, 2026
jundot added a commit that referenced this pull request May 19, 2026
Follow-up to #1285. Adds the three cases the PR body promised but did not
land: tool_name happy path, tool_name precedence when both fields are
present, and 422 when neither is supplied.
cfbraun added a commit to cfbraun/omlx that referenced this pull request May 22, 2026
omlx/api/mcp_routes.py was wired into server.py at module init but had
zero direct test coverage — test_mcp_*.py files exercised the manager
and executor layers but not the FastAPI handlers, leaving the request
parsing, no-manager fallbacks, and the tool/tool_name alias
(upstream PR jundot#1285) unguarded.

15 tests via TestClient covering all four entry points:
- set_mcp_manager_getter wiring + None propagation
- GET /v1/mcp/tools: empty-list short-circuit, namespaced full_name
  serialization
- GET /v1/mcp/servers: enum-to-string flattening, error-field passthrough
- POST /v1/mcp/execute: 503 when unconfigured, success / handled-error
  paths, tool-vs-tool_name alias regression guard, default-arguments
  fallback, 422 on missing tool name

The autouse fixture resets the module-global `_get_mcp_manager` callback
between tests so state can't leak across cases.
cfbraun added a commit to cfbraun/omlx that referenced this pull request May 26, 2026
omlx/api/mcp_routes.py was wired into server.py at module init but had
zero direct test coverage — test_mcp_*.py files exercised the manager
and executor layers but not the FastAPI handlers, leaving the request
parsing, no-manager fallbacks, and the tool/tool_name alias
(upstream PR jundot#1285) unguarded.

15 tests via TestClient covering all four entry points:
- set_mcp_manager_getter wiring + None propagation
- GET /v1/mcp/tools: empty-list short-circuit, namespaced full_name
  serialization
- GET /v1/mcp/servers: enum-to-string flattening, error-field passthrough
- POST /v1/mcp/execute: 503 when unconfigured, success / handled-error
  paths, tool-vs-tool_name alias regression guard, default-arguments
  fallback, 422 on missing tool name

The autouse fixture resets the module-global `_get_mcp_manager` callback
between tests so state can't leak across cases.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Cheers @jundot - thanks for landing the dual field-name acceptance so MCP clients on either side of the tool/tool_name split stop seeing 422s.

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.

web-search__brave_web_search returns "Tool not found" when called by pi agent — wrong field name in /v1/mcp/execute

2 participants