Repository navigation
Conversation
Entire-Checkpoint: df20a978ed63
Entire-Checkpoint: cef2c5f2c5aa
Entire-Checkpoint: 328010829d2c
- Fix a real infinite-recursion/swallowed-signal bug in the launcher's
signal re-raise: process.kill(self, signal) with our own SIGINT/SIGTERM
listener still attached routed back into that listener instead of
terminating, silently reporting exit 0 for a process actually killed by
a signal. removeAllListeners() before re-raising fixes it.
- Resolve npx.cmd on win32 (spawn("npx") raises ENOENT there with
shell: false — npm ships npx as npx.cmd on Windows).
- doctor's shadow check now also compares against the project's own
.mcp.json pin, not just the running CLI version, so it catches shadows
that match the running CLI (including the self-shadowing case where
doctor itself runs the shadow) but still defeat the pin.
- Add regression tests for exit-code/signal forwarding and the npx.cmd
resolution, and a CHANGELOG entry.
- Scope .mjs files into real lint coverage instead of a blanket ignore.
Entire-Checkpoint: 4645960a34b9
Entire-Checkpoint: c1ec6e3e835f
7 tasks
…de Code's env expander cannot touch it
The generic ${VAR} expander runs over every arg in .mcp.json. Three stderr messages in mcp-launch.mjs used template literals, which the inline copy carried verbatim. Rewritten as concatenation; inline regenerated; the shipped config now contains no ${ at all.
…ust the plugin placeholder tokens
…install-resource test over stdio, pinned arg index, generator --write wired into prepare:marketplace - mcp-launch.mjs: sweepStaleLaunchDirs() removes empty sequant-mcp-launch-* dirs older than an hour on each launch (SIGKILL of the launcher skips cleanup()). - generate-mcp-launch-inline.mjs: strips every 'export function', refuses other exports, and --write rewrites .mcp.json args[1] in place; npm run mcp-launch:inline, first step of prepare:marketplace. - serve.integration.test.ts: reads sequant://install through a real StdioClientTransport with cwd != project and asserts the SEQUANT_PROJECT_DIR project's manifest. - plugin-mcp-pin.test.ts: pin must sit at args[2] with exactly three args. - docs: sweep + regeneration command.
…plugin-mcp-server-dies-with-connection-clo
…; pid-file ownership so the sweep never removes a live session's launch dir - Node refuses to spawn npx.cmd without a shell (CVE-2024-27980 hardening, inside the engine floor), so shell: true on win32; isSafeSpec() rejects any spec a shell could interpret before spawn. - Each launch dir carries launcher.pid; sweepStaleLaunchDirs() keeps dirs whose launcher is alive (however old), removes dead ones outright, and age-gates only pid-less dirs. - Integration test: launch-dir cleanup assertion is now unconditional. - Generator: replaceAll for the argv index rewrite.
admarble
deleted the
feature/1084-fix-mcp-plugin-mcp-server-dies-with-connection-clo
branch
September 19, 2026 03:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.mcp.jsonnow launchessequant servethrough a dependency-free launcher (scripts/mcp-launch.mjs) that spawnsnpxfrom an isolatedmkdtempcwd, sonpxcan never resolve a shadowingnode_modules/sequantin the open project (the root cause ofCONNECTION_CLOSED).SEQUANT_PROJECT_DIR;sequant servenowchdirs there before doing anything else, and rejects a non-directory value with a named stderr message + non-zero exit.sequant doctorgains a Local sequant shadow warning: it walks cwd's ancestor chain and$HOMEfor anode_modules/sequantat a version different from the running CLI, and names the fix.docs/troubleshooting.mdanddocs/features/mcp-server.mddocument the new failure mode,SEQUANT_PROJECT_DIR, and how the launcher avoids it..mcp.jsonlaunches the server asnode -e <inline launcher> sequant@<pin>with no${...}anywhere incommand/args/env.${CLAUDE_PLUGIN_ROOT:-.}was proven (QA run 2 probe) to resolve to the open project, and Claude Code's generic env expander runs over every arg, so the launcher source uses string concatenation, never template literals.scripts/generate-mcp-launch-inline.mjsderives the inline form fromscripts/mcp-launch.mjs, and a gate test keeps the two byte-identical. The same file therefore works unchanged as the plugin config and as the dev repo's own project config.68db25fd: the launcher sweeps emptysequant-mcp-launch-*dirs older than an hour on each start (a SIGKILL of the launcher skips its own cleanup);sequant://installis read through a realStdioClientTransportwith cwd ≠ project as the AC-3 regression test; the pin test assertsargs[2]and exactly three args;npm run mcp-launch:inlineregenerates the inline launcher in place and runs first inprepare:marketplace; an Execution Verification record is on the issue.cd0347fd: on Windows the launch goes throughcmd.exe(Node refuses to spawnnpx.cmdwithout a shell — CVE-2024-27980 hardening, inside the engine floor), gated byisSafeSpec()which rejects any spec a shell could interpret before spawn; each launch dir carrieslauncher.pid, and the sweep keeps any dir whose launcher is alive (however old), removes dead ones outright, and age-gates only pid-less dirs — so a session open for hours keeps its launch dir even while a pre-2.16serveis still using it as cwd; the integration test's cleanup assertion is unconditional; the generator usesreplaceAllfor the argv index rewrite. Branch carries origin/main through52cd790e(fix(#1075): timeout the codex+opencode CLI probes; add the missing templates/codex routing test #1091, fix(#1071): preserve .sequant/settings.json on re-init #1092) with no conflicts.Pre-PR AC Verification
scripts/mcp-launch.mjslauncherscripts/mcp-launch.mjs; mutation-verified byscripts/mcp-launch.integration.test.ts.mcp.jsonis an inlinenode -elauncher, no placeholders, pin inargs[2], byte-identical to the generated form.mcp.json;scripts/generate-mcp-launch-inline.mjs;scripts/plugin-mcp-pin.test.ts(see AC-2 Mutation-verified marker)servechdirs toSEQUANT_PROJECT_DIR, rejects non-directory;sequant://installresolves against itsrc/commands/serve.ts(applyProjectDir);src/commands/serve.integration.test.ts— stderr warning test, non-directory test, and a stdioreadResource("sequant://install")test asserting the project's0.0.1manifestscripts/mcp-launch.integration.test.ts(see Mutation-verified marker below)doctorwarns on a shadowing localsequantsrc/commands/doctor.ts(checkShadowingLocalSequant);src/commands/doctor.test.tsdocs/troubleshooting.md,docs/features/mcp-server.md.mcp.jsonas resolved by Claude Code, in the dev-repo context and in a project with an older localsequantclaude -p --mcp-configprobes + one initialize probe, recorded verbatimscripts/mcp-launch.mjs(stderr line on every start)Mutation-verified: AC-4 — commented out the launcher's isolated-cwd spawn (
cwd: launchCwd→cwd: projectDir);scripts/mcp-launch.integration.test.tsfailed (recorded npx cwd equalled the shadowing project dir); restored.Mutation-verified: AC-2 — (a) appended one space to
.mcp.jsonargs[1];scripts/plugin-mcp-pin.test.ts > the inline launcher source (args[1]) is byte-identical to the generated form of scripts/mcp-launch.mjsfailed (1 failed / 6 passed); restored. (b) setargs[0]to${CLAUDE_PLUGIN_ROOT}/-e; both theinvokes node -eand thecarries no ${...}tests failed (2 failed / 5 passed); restored. Baseline 7/7 green.Mutation-verified: AC-1 (sweep) — removed the age check in
sweepStaleLaunchDirs(now - st.mtimeMs < maxAgeMs);scripts/mcp-launch.test.ts > leaves a fresh sibling launcher's directory alonefailed (1 failed / 6 passed); restored, 7/7 green.Mutation-verified: AC-1 (pid ownership) — removed
if (alive(pid)) continue;insweepStaleLaunchDirs;scripts/mcp-launch.test.ts > never removes a directory whose launcher pid is still alive, however oldand> consults the injected liveness check with the recorded pidfailed (2 failed / 12 passed); restored.Mutation-verified: AC-1 (Windows spawn) — made
spawnShellForreturn false on win32;scripts/mcp-launch.test.ts > uses a shell only on win32failed (1 failed / 13 passed); restored. LoosenedisSafeSpectospec.length > 0;> rejects anything a shell could interpretfailed (1 failed / 13 passed); restored. Baseline 14/14 green.Also mutation-verified along the way (not separately AC-gated, but load-bearing for AC-3/AC-5):
serve.ts'sapplyProjectDir()call — disabling it left both newserve.integration.test.tsAC-3 tests timing out/failing.doctor.ts'scheckShadowingLocalSequantpush — disabling it dropped both "warns" tests to[].Test plan
npm run build— exit 0 (worktree, headcd0347fd)npm run lint— exit 0,--max-warnings 0(headcd0347fd)npm test(full suite, worktree, headcd0347fd, includes origin/main through52cd790e) — Test Files 321 passed (321); Tests 6508 passed | 1 expected fail | 3 skipped (6512), 0 failures.cd0347fdfrom~/Projects/sequant-landing(shadowed):serverInfo.version 2.15.1, launch dir removed on exit;node -e <launcher> '[email protected]; echo pwned'→mcp-launch: refusing package spec with shell-significant characters, exit 1.serverInfo.version 2.15.1;claude -p --mcp-configconnected in both contexts;mcp-launch:inlineidempotent).claude -p "reply with the single word ok" --mcp-config .mcp.json --strict-mcp-config --output-format stream-json --verbose --max-turns 1→ init message"mcp_servers":[{"name":"sequant","status":"connected","source":"dynamic"}].~/Projects/sequant-landing(has[email protected]innode_modules, the original CONNECTION_CLOSED reproducer) →"mcp_servers":[{"name":"sequant","status":"connected","source":"dynamic"}].node -e "$(jq -r '.mcpServers.sequant.args[1]' .mcp.json)" [email protected]fed an MCPinitialize→ stderrmcp-launch: project dir /Users/tony/Projects/sequant-landing; launching npx from /var/folders/.../sequant-mcp-launch-WOvIvNthenSequant MCP server started (stdio); replyserverInfo: {name: "sequant", version: "2.15.1"}. The 1.20.1 local copy never ran.claude mcp listfrom the worktree lists the project server asnode -e … [email protected] — Pending approval; project-scope.mcp.jsonservers need a one-time interactive approval per path, which is why the host-resolution probes above use--mcp-config(same loader, same expansion, no approval gate).Known trade-off (flagged, not fixed here)
Previously, the dev repo's own
.mcp.jsonhappened to run the local checkout'sdist/bin/cli.js(becausenpxresolved the repo's ownpackage.jsonbin when cwd == repo root — the same shadowing behavior this issue fixes for plugin users). With the isolated-cwd launcher, the dev repo's own MCP server now always fetches the pinned publishedsequant@<pin>vianpx, same as any other project. This is the intended effect of removing the shadow, but it means local, uncommitted CLI changes are no longer reflected when testingsequant servethrough.mcp.jsonin this repo — contributors iterating on MCP-server code should invokedist/bin/cli.js servedirectly instead.Also out of scope (per the issue's own scope note):
templates/mcp.json(the separate official-marketplace dist copy, not yet catalogued) andsequant init --mcp's project-level config (src/lib/mcp-config.ts) still invokenpxdirectly and have the same shadowing exposure — AC-5'sdoctorcheck covers users of either path, but neither routes through the new launcher.Review history
${CLAUDE_PLUGIN_ROOT:-.}resolves against the open project (three-row probe on a throwaway plugin). Owner decision: inline launcher.AC_MET_BUT_NOT_A_PLUSverdict is void (noted on the issue).56c33a0b, plus removal of the three template literals the inline source carried.aace6fc3. Its non-blocking notes (temp-dir leak on SIGKILL, AC-3 resource test, pin index, generator wiring,/verifyrecord) are closed in68db25fd; sibling shadowing sites stay in fix(mcp): sequant init --mcp and the official-plugin-directory dist .mcp.json still invoke npx directly, retaining the #1084 shadowing exposure #1089.68db25fd; flagged the Windows.cmdspawn (EINVAL under CVE-2024-27980 hardening) and the sweep's blind spot for a live session older than an hour. Both fixed incd0347fd, mutation-verified above.Closes #1084
🤖 Generated with Claude Code