Skip to content

fix(mcp): sequant init --mcp and the official-plugin-directory dist .mcp.json still invoke npx directly, retaining the #1084 shadowing exposure #1089

Closed

Description

@admarble

Follow-up to #1084. #1084 fixed the shadowing-by-npx exposure (a local node_modules/sequant in the open project silently running instead of the pinned version, killing the MCP handshake with CONNECTION_CLOSED) for the plugin's own .mcp.json — the file plugin users get via the marketplace source: "./" path — by inlining scripts/mcp-launch.mjs as a node -e launcher with no ${...} placeholders.

Two sibling sites were explicitly out of scope for #1084 and still carry the original exposure:

  1. getSequantMcpConfig() (src/lib/mcp-config.ts) — used by sequant init --mcp, createProjectMcpJson, addSequantToMcpConfig, and buildOpencodeMcpConfig. It still builds { command: "npx", args: ["-y", "sequant@<pin>", "serve"] }, which npx runs from whatever cwd the client (Claude Code, Cursor, VS Code+Continue, opencode) launches it with — the project directory in every case. A stale sequant devDependency in that project reproduces fix(mcp): plugin MCP server dies with CONNECTION_CLOSED when the open project has an older sequant in node_modules — npx ignores the pin and runs the local copy #1084's exact symptom.
  2. templates/mcp.json — the source template prepare-marketplace.ts pins and copies into the official-plugin-directory submission's dist/marketplace/external_plugins/sequant/.mcp.json (a separate distribution path from the marketplace source: "./" file fix(mcp): plugin MCP server dies with CONNECTION_CLOSED when the open project has an older sequant in node_modules — npx ignores the pin and runs the local copy #1084 fixed). Also still npx-direct.

Suggested fix

Reuse #1084's inline-launcher approach: have getSequantMcpConfig() (or a new variant) embed scripts/mcp-launch.mjs via scripts/generate-mcp-launch-inline.mjs instead of building a bare npx command, and have prepare-marketplace.ts stamp templates/mcp.json with the same inline form it now produces for the root .mcp.json. Needs its own design pass — getSequantMcpConfig() is also used for non-Claude-Code clients (Cursor, VS Code+Continue) whose cwd/env handling differs from the plugin case, and SEQUANT_PROJECT_DIR currently relies on process.cwd() at launcher-spawn time, which holds for .mcp.json-launched processes but needs re-checking for cwd-clients that pass an explicit cwd.

Scope

Out of scope: anything already covered by #1084 (the plugin's own shipped .mcp.json). This issue is limited to getSequantMcpConfig()'s callers and templates/mcp.json.

Design pass (2026-09-28, owner-approved)

Observed:

  • getSequantMcpConfig() has four consumers, not three. The fourth is getPhaseMcpServersConfig: the sequant server injected into every phase agent, with cwd set to the worktree. It carries the same exposure.
  • scripts/ is not in package.json files, so runtime code cannot read scripts/mcp-launch.mjs. That makes the inline node -e form (the fix(mcp): plugin MCP server dies with CONNECTION_CLOSED when the open project has an older sequant in node_modules — npx ignores the pin and runs the local copy #1084 shape) the only robust one. Today's inline source is 7,940 bytes.
  • serve honors SEQUANT_PROJECT_DIR (src/commands/serve.ts:39). The launcher derives that value from process.cwd(). Clients that take an explicit cwd (Claude Desktop, Continue) spawn in the project dir, so they get the same value and need no change.
  • prepare-marketplace.ts:287 rejects every .mcp.json whose command is not npx, so the validator enforces the vulnerable shape.
  • In the field, matcha-maps and portfolio-2025 .mcp.json are still npx -y [email protected] serve. syncSequantMcpPin only re-pins; it never migrates the shape.

Decisions:

  • D-1: a committed, generated src/lib/mcp-launch-inline.generated.ts exports MCP_LAUNCHER_INLINE_SOURCE. scripts/generate-mcp-launch-inline.mjs --write writes it, and also rewrites the root .mcp.json and templates/mcp.json. A drift gate test keeps it honest.
    • Rejected: generating it into dist at build time (the build is tsc-only, so this adds a build step and an untracked artifact).
    • Rejected: a file-path launcher (no stable path once installed through npx).
  • D-2: getSequantMcpConfig() returns { command: "node", args: ["-e", SOURCE, spec] }. The cwd/env logic is unchanged, and all four consumers inherit the new shape.
  • D-3 (owner: yes): syncSequantMcpPin, the update/sync path, migrates exactly the legacy generated shape (npx with ["-y", "sequant@X", "serve"]) to the inline form. It also refreshes a stale inline source, and leaves every other shape alone, including local-binary overrides. It reports this with a new result reason, migrated.
  • D-4: templates/mcp.json becomes the inline flat form. The prepare-marketplace.ts validator accepts the node -e shape and still requires a concrete pin.
  • Owner accepted that a committed project .mcp.json grows by about 8 KB and changes whenever the launcher changes. The plugin's own .mcp.json already works this way.

Acceptance criteria

  • AC-1: getSequantMcpConfig() returns command: "node", args[0] === "-e", args[1] === MCP_LAUNCHER_INLINE_SOURCE and the pinned spec as the last arg, for no clientType and for every McpClientType — Evidence: npx vitest run src/lib/mcp-config.test.ts
  • AC-2: running the command/args getSequantMcpConfig() returns, with cwd = a project whose node_modules/.bin/sequant shadows the package and a fake npx on PATH, spawns npx from a directory outside the project with the pinned spec — Evidence: npx vitest run scripts/mcp-launch.integration.test.ts new case, mutation-verified (reverting getSequantMcpConfig to the npx form fails it)
  • AC-3: src/lib/mcp-launch-inline.generated.ts equals generateInlineLauncherSource() output, and templates/mcp.json args[1] equals it too — Evidence: npx vitest run scripts/plugin-mcp-pin.test.ts gate case, mutation-verified
  • AC-4: syncSequantMcpPin migrates a legacy npx -y sequant@X serve entry to the inline form (reason migrated), refreshes a stale inline source, and leaves a local-binary entry byte-identical — Evidence: npx vitest run src/lib/mcp-config.test.ts
  • AC-5: templates/mcp.json is the inline flat form and npm run prepare:marketplace validates and pins it — Evidence: npm run prepare:marketplace output contains ✅ .mcp.json (MCP server config, pinned sequant@
  • AC-6: buildOpencodeMcpConfig() returns command: ["node", "-e", MCP_LAUNCHER_INLINE_SOURCE, <spec>] — Evidence: npx vitest run src/lib/mcp-config.test.ts
  • AC-7: npm run build && npm test green — Evidence: CI test job

Non-Goals

Activity

  1. added 4 commits that reference this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions