Skip to content

fix(mcp): four MCP errors a client could not act on - #1410

Merged
NandhaKishorM merged 5 commits into
NandhaKishorM:mainfrom
Rish-it:fix/mcp-caller-error-codes
Oct 29, 2026
Merged

NandhaKishorM merged 5 commits into
NandhaKishorM:mainfrom
Rish-it:fix/mcp-caller-error-codes

Conversation

@Rish-it

@Rish-it Rish-it commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Four MCP paths answered a caller mistake with internal_error, or with no reason at all. Each fix is its own commit with its regression test, and every test goes through MCPServer.call_tool.

  • 5b82a1a7 A question type of [] or {} raised TypeError: unhashable type in validate_questions before the membership check. It now checks isinstance(qtype, str) first and returns invalid_questions, the same as an unknown type and the same as core (laya/agent.py:1020). This covers every tool that takes questions.
  • 34e4407c An unknown task on laya_route_batch / laya_predict_batch reached Router._route and came back internal_error: unknown model. The batch item now runs validate_task when no model is pinned, so it returns invalid_task naming requests[i]['task'], as laya_route does. A pinned model beside a task is still accepted (batch/validation_keeps_overrides).
  • f173dd32 With LAYA_BASE_URL set, laya_predict_long failed with internal_error: hooks are callables even with no hook passed: Router.predict_long passes normalise_hooks(None), which is [], and the remote guard refuses it. laya-serve has no long-state endpoint, and one /v1/systemone call would read only the first window, so the tool now returns unsupported_remote up front, like laya_shortlist and laya_tournament.
  • f943f46e docs/cli-mcp.md lists laya_predict_long among the tools remote mode refuses.
  • 1aabd031 laya_tournament_tool called _ensure_router() directly, so a router construction failure reached the client as a bare "Error executing tool laya_tournament". It now uses _router_or_error() like every other tool and sends the same {"error", "message"} payload. The line came from feat(mcp): expose core tournament selection as laya_tournament #1178.

On fe9a6c35 with no checkpoint loaded, the repro gives internal_error on the first three paths and an empty error on the fourth. On this branch it gives invalid_questions, invalid_task, unsupported_remote with 0 HTTP requests sent, and remote router construction failed.

Each commit passes on its own. At HEAD, in two clean runs: tests/test_mcp.py 1247 passed (1229 on main), tests/test_mcp_device.py 95, tests/test_mcp_remote.py 85 (83 on main), tests/test_hooks_api.py, tests/test_env_docs.py, ruff, compileall and zensical build --strict all clean. Reverting any one fix fails only that fix's tests. No public API change and no model load.

#1409 adds a block right after the laya_predict_long line this changes in tests/test_mcp_remote.py. Both are needed, so whichever merges second keeps both. I'll rebase this one if #1409 lands first.

validate_questions tested `qtype not in VALID_TYPES` before checking that the
type is a string. A JSON array or object there is unhashable, so the set
lookup raised TypeError and the wrapper reported internal_error, while core's
Agent._check_question refuses the same question with a ValueError naming it.

Check the shape first, so `"type": []` and `"type": {}` get the same
invalid_questions code and message as an unknown string type.
…error

laya_route and laya_predict check `task` with validate_task and answer a name
no checkpoint answers to with invalid_task. The batch validator only checked
that the task is a non-empty string, so the same name on laya_route_batch or
laya_predict_batch reached Router.route_batch, whose normalise_name raised
ValueError, and the client got internal_error.

Run validate_task on a batch item that pins no model, with the item index in
the message. A pinned model is never routed, so its task is still kept as
given, as batch/validation_keeps_overrides pins.
laya-serve has no long-state endpoint, so with LAYA_BASE_URL set the scan
has nowhere to run. The call reached Router.predict_long on the
RemoteRouter, whose hook guard raised RemoteError, and the client got
internal_error ("hooks are callables and cannot be sent to laya-serve")
for a call that never passed a hook.

Refuse it before any validation or HTTP request with unsupported_remote,
the way laya_shortlist and laya_tournament already are, naming what does
work: run the MCP server without LAYA_BASE_URL, or call laya_predict
knowing it reads the first window only. Local scans are unchanged.
Name it beside laya_shortlist and laya_tournament, and say what to do instead: laya-serve has no long-state scan, so run the MCP server without LAYA_BASE_URL, or accept that laya_predict over HTTP reads the first window only.
…every other tool

Every decision tool gets its router through _router_or_error, which turns
_ensure_router's ToolError into the JSON payload the wrapper sends. The
tournament tool called _ensure_router bare, so a router that could not be
built (for example LAYA_BASE_URL=http://) escaped as a raw ToolError and
the MCP layer redacted it to "Error executing tool laya_tournament", with
no error code and no reason, while laya_predict reported
"remote router construction failed: ..." for the same environment.

Use _router_or_error there too.
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged in 0.4.18. Four separate defects, each a real one, and the title is accurate: none of these were actionable by a client.

I reproduced the two that are easy to get wrong.

The unhashable question type is the sharpest find. On main:

{'type': [1, 2]}   -> TypeError: unhashable type: 'list'
{'type': {'a': 1}} -> TypeError: unhashable type: 'dict'
{'type': 5}        -> ToolError  (already fine)
{'type': None}     -> ToolError  (already fine)

A set membership test raising on the value it is testing is not something a reader expects, and the two shapes that crash are exactly the ones a JSON client sends by accident. isinstance(qtype, str) first is the minimal fix.

The _ensure_router call was a genuine inconsistency, not a style preference. On main, nine tool handlers use _router_or_error and laya_tournament_tool at line 504 was the only one calling _ensure_router directly, so a router construction failure there surfaced as a raw exception instead of the {"error": ..., "message": ...} payload every sibling returns.

The laya_predict_long refusal is the right shape too. It raises before validate_state, so a remote deployment gets the explanation without paying to parse the body first, and the message tells the caller both ways out rather than just saying no.

The batch task check being conditional on no pinned model matches where the router actually reads task, which is the part a narrower fix would have got wrong by validating a field that is ignored.

One thing to know about the merge: this conflicted with #1409 in tests/test_mcp_remote.py, where you both touched the refusal loop. Both sides were additive so I kept your three-tool tuple inside their diagnostics block. Your laya_predict_long_tool refusal happens before any request is issued, so their no_http guard above the loop still holds.

Verified: 706 tests across 93 suites.

@NandhaKishorM
NandhaKishorM merged commit cf81be8 into NandhaKishorM:main Oct 29, 2026
63 checks passed
NandhaKishorM added a commit that referenced this pull request Oct 29, 2026
Twelve pull requests: #1364, #1409, #1410, #1412, #1413, #1414, #1415, #1416,
#1417, #1418, #1419, #1420.

Test suites: 706 passing across 93 suites, up from 640 across 92. laya-cpp
registers 423 ctest tests, up from 213, and its MIN_TESTS floor is raised to match.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.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.

2 participants