Commit Graph
19 Commits
Author SHA1 Message Date
haelyra 13c476965f fix(hooks): keep MCP reachability probes bounded
Remove the redundant JSON-RPC initialize fallback from the consolidated MCP health-check batch. A routed 404 already proves the endpoint is reachable, and the real authenticated MCP call remains authoritative. Avoiding the fallback also prevents a stalled GET plus stalled POST from consuming twice the configured hook timeout.
2026-08-28 21:09:35 -04:00
bengio777andAlex Schmitt 06ac5b8a49 fix(hooks): treat HTTP 404 MCP probes as reachable
The mcp-health-check preflight probes HTTP MCP servers with a bare GET.
Some Streamable HTTP servers route only POST /mcp and answer a bare GET
with 404 (Paper Desktop 0.5.3 is one). The probe scored that as down and
blocked every tool call for the server indefinitely, since the 30s
backoff just re-probes and re-fails.

A routed HTTP response of any status proves the endpoint is reachable,
which is all this preflight claims to check -- 400/401/403/405/406 are
already treated this way for the same reason. Add 404 to the set and let
the real MCP client validate the endpoint.

Adds a regression test that stands up a POST-only server (404 on GET,
200 on POST /mcp); it fails on the current code and passes with the fix.
2026-08-24 22:27:30 -03:00
66b1aad3f2 fix: probe POST-only Streamable HTTP MCP servers before marking them dead
The preflight probe in mcp-health-check only ever sent a bare GET to the
server URL. Some Streamable HTTP MCP servers route POST exclusively and
answer any GET with 404 — api.telnyx.com/v2/mcp is one — so the probe
failed permanently against a perfectly healthy server.

404 is not in HEALTHY_HTTP_CODES, so every probe failed, the backoff
compounded to the 10-minute ceiling, and the hook blocked every tool call
for that server before it left the machine while `claude mcp list` still
reported it Connected.

Replay a failed GET as a real JSON-RPC initialize POST and accept that as
proof of life. Whitelisting 404 was the alternative, but it would mask
genuine outages on every other server.

Adds a regression test with a POST-only server that 404s all GETs and
validates the initialize body; it fails without this change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-24 22:27:29 -03:00
b1d5d6366d fix(hooks): quote args when probing Windows .cmd MCP servers via shell (#2343)
On Windows, when a bare-name MCP server command (e.g. codesys-mcp-sp21-plus)
falls back to the .cmd candidate, the probe sets shell:true to work around
Node 18.20+ CVE-2024-27980. However, passing an args array alongside
shell:true causes Node to concatenate the tokens without quoting (DEP0190),
so an arg containing a space (e.g. --codesys-path "C:\Program Files\...") is
re-split by cmd.exe at every space boundary. The child process receives a
truncated path, fails to launch, and the probe declares the server unavailable,
falsely blocking every MCP tool call to that server.

Fix: add a quoteWin() helper that double-quotes any token containing whitespace
or cmd metacharacters. In the useShell branch, build a single properly-quoted
command line string and pass it as the sole argument to spawn() with no separate
args array. The else branch (shell:false, all non-.cmd commands) is unchanged.

Regression test added: on Windows, creates a .cmd shim that echoes its first
positional argument to stderr, probes it with a space-containing path arg, and
asserts the probe succeeds and the arg was not split at the space boundary.

Co-authored-by: Karstein Phobic Nyvold Kvistad <karstein.kvistad@maritimerobotics.com>
2026-06-29 15:54:52 -07:00
Affaan Mustafa 386326df8e fix: treat MCP HTTP 406 probes as reachable 2026-05-18 12:48:52 -04:00
Affaan MustafaandAffaan Mustafa 901e41997b test: stabilize MCP stderr probe timeout 2026-05-12 01:13:01 -04:00
Affaan MustafaandAffaan Mustafa e9c8845833 feat: add Astraflow provider support 2026-05-11 23:21:46 -04:00
Affaan MustafaandAffaan Mustafa 67a8b914ee test: harden mcp health port readiness 2026-05-11 22:40:19 -04:00
Affaan MustafaandGitHub f442bac8c9 fix: port Windows hook safety fixes (#1719) 2026-05-11 03:56:51 -04:00
MichaelandGitHub 600072ebd8 fix(hooks): resolve MCP health-check spawn ENOENT on Windows (#1456)
* fix(hooks): resolve MCP health-check spawn ENOENT on Windows

On Windows, commands like 'npx' are batch files (npx.cmd) that require
shell expansion to resolve via PATH. Without shell: true, Node.js
spawn() fails with ENOENT.

However, absolute paths (e.g. C:\Program Files\nodejs\node.exe) must
NOT use shell mode because cmd.exe misparses paths containing spaces.

Fix: enable shell mode only for non-absolute commands on Windows, using
path.isAbsolute() to distinguish. This matches how attemptReconnect()
already handles the shell option.

Fixes #1455

* fix(hooks): harden Windows shell spawn — validate command for metacharacters

Addresses bot review feedback on PR #1456:

- Add UNSAFE_SHELL_CHARS regex to guard against shell injection when
  needsShell=true: cmd.exe operators (&, |, <, >, ^, %, !, (), ;,
  whitespace) are rejected before shell mode is enabled
- Add typeof command === 'string' check so path.isAbsolute() cannot
  throw on malformed non-string command values
- Rename test to 'via PATH resolution' (not Windows-only; runs all platforms)
- Fix misleading test comment: 'node' resolves via PATH like npx.cmd but
  does not itself use .cmd; comment now accurately reflects the intent

* fix(hooks): kill full process tree on Windows when shell mode is used

When needsShell=true, the spawned child is cmd.exe. Calling child.kill()
only terminates the shell, leaving the real server process orphaned.

Use taskkill /PID <pid> /T /F on Windows+shell to kill the entire
process tree rooted at cmd.exe. Fall back to SIGTERM+SIGKILL on all
other platforms or when shell mode is not active.

* fix(hooks): fall back to child.kill() when taskkill fails

Windows taskkill can fail if it's not on PATH, the process already
exited, or permissions are denied. Previously the failure was silently
ignored and no kill signal reached the child.

Now: capture the spawnSync result and fall back to child.kill('SIGKILL')
on any taskkill error or non-zero status. This still may leak a
detached server process but at least guarantees the cmd.exe shell is
signaled.
2026-05-11 01:13:37 -04:00
Affaan MustafaandAffaan Mustafa 9627c201c7 test: harden mcp health http probe fixture 2026-04-29 23:05:17 -04:00
Affaan Mustafa 015b00b8fc test: stabilize mcp health crash probes 2026-04-29 18:29:02 -04:00
Affaan Mustafa f92dc544c4 test: cover mcp health edge paths 2026-04-29 18:08:45 -04:00
Affaan Mustafa bb96fdc9dc test: wait for http mcp fixtures to accept connections 2026-04-12 23:38:46 -07:00
Affaan Mustafa e363c54057 fix: treat oauth mcp 401 probes as reachable 2026-04-08 15:34:34 -07:00
Affaan Mustafa 3d2ec5ae12 fix: clear lingering lint failure in mcp health tests 2026-04-05 14:50:04 -07:00
Affaan Mustafa 8baffb4ad3 fix: harden install target filtering and MCP health probes 2026-04-05 13:59:42 -07:00
Affaan Mustafa 1d0aa5ac2a fix: fold session manager blockers into one candidate 2026-03-24 23:08:27 -04:00
Affaan MustafaandGitHub e8495aa3fc feat: add MCP health-check hook (#711) 2026-03-20 05:56:21 -07:00