Repository navigation
fix(mcp): four MCP errors a client could not act on - #1410
Conversation
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.
|
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: 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. The The The batch One thing to know about the merge: this conflicted with #1409 in Verified: 706 tests across 93 suites. |
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>
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 throughMCPServer.call_tool.5b82a1a7A questiontypeof[]or{}raisedTypeError: unhashable typeinvalidate_questionsbefore the membership check. It now checksisinstance(qtype, str)first and returnsinvalid_questions, the same as an unknown type and the same as core (laya/agent.py:1020). This covers every tool that takes questions.34e4407cAn unknowntaskonlaya_route_batch/laya_predict_batchreachedRouter._routeand came backinternal_error: unknown model. The batch item now runsvalidate_taskwhen no model is pinned, so it returnsinvalid_tasknamingrequests[i]['task'], aslaya_routedoes. A pinnedmodelbeside ataskis still accepted (batch/validation_keeps_overrides).f173dd32WithLAYA_BASE_URLset,laya_predict_longfailed withinternal_error: hooks are callableseven with no hook passed:Router.predict_longpassesnormalise_hooks(None), which is[], and the remote guard refuses it. laya-serve has no long-state endpoint, and one/v1/systemonecall would read only the first window, so the tool now returnsunsupported_remoteup front, likelaya_shortlistandlaya_tournament.f943f46edocs/cli-mcp.mdlistslaya_predict_longamong the tools remote mode refuses.1aabd031laya_tournament_toolcalled_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
fe9a6c35with no checkpoint loaded, the repro givesinternal_erroron the first three paths and an empty error on the fourth. On this branch it givesinvalid_questions,invalid_task,unsupported_remotewith 0 HTTP requests sent, andremote router construction failed.Each commit passes on its own. At HEAD, in two clean runs:
tests/test_mcp.py1247 passed (1229 on main),tests/test_mcp_device.py95,tests/test_mcp_remote.py85 (83 on main),tests/test_hooks_api.py,tests/test_env_docs.py, ruff, compileall andzensical build --strictall 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_longline this changes intests/test_mcp_remote.py. Both are needed, so whichever merges second keeps both. I'll rebase this one if #1409 lands first.