Files
Open_Ultra_SAST/tests
Marius Ciepluch 8998697b4e fix(contributor-scan): the MCP server answers a tool that stops the CLI and stays up (3.1, follow-up)
By the maintainer's decision of 2026-11-25, recorded in the handover: "McpServer.handle
catches Exception only, so a missing scan path raises SystemExit through it and ends the stdio
loop; openultrasast.scan and openultrasast.benchmark both take that path. One bad call would
become an error result for that call and the server would stay up."

`McpServer.handle` in src/openultrasast/mcp.py catches `SystemExit` beside `Exception` and
answers with the error it already builds for any exception a tool raises: `-32603` with
`SystemExit: scan path is not a directory: <path>`. The stdio loop reads on, answers the next
request and exits 0 at EOF; before, the process exited 1 with that message on stderr and nothing
on stdout. `openultrasast.benchmark` takes the same clause when the manifest names a source path
that does not exist. No other path changes: the notification return comes before the `try`, a
line that does not parse is answered in `serve`, and `cli.py:588` is the only `SystemExit` a tool
handler can reach (the independent reviewer's trace), raised before the configuration is loaded
and before a run directory is created.

"Error result" is read as that JSON-RPC error: the decision names `handle`, and the handover
keeps this channel apart from `isError: true`, which `_call_tool` builds for `McpToolError`. A
missing path therefore travels a different channel from a missing `path` argument or an
unsupported mode; that is left for the maintainer's menu, with one pre-existing gap the reviewer
found: a line that is valid JSON but not an object still ends the loop.

Tests: through `serve`, a tools/call for `openultrasast.scan` with a missing path followed by a
ping gives the error object and then the ping result, and `serve` returns 0; through `handle`,
the same call gives that error object. Both failed on the code as it was, each with the
`SystemExit` raised through the function it calls (the first in my run, the second in the
reviewer's, on a copy of the code before the change); the second pins that the catch sits in
`handle`, the public dispatch, where a catch in `serve` alone passes the first. The 23 test files
around the scan path and the MCP server pass (242 passed before the second test was added, and
`tests/test_mcp.py` 18 passed after); ruff, mypy, the three gates and compileall pass, and the
gates print what they printed before the change. The real `ousast mcp` process, fed the same two
lines, answered both and exited 0 with an empty stderr. An independent reviewer approved the
change in one round and proposed the second test.
2026-11-25 18:14:06 +01:00
..