Skip to content

fix(mcp): keep command and args in the same settings layer - #412

Open
raymondginger2018-sudo wants to merge 1 commit into
lessweb:mainfrom
raymondginger2018-sudo:pr/mcp-pair-merge
Open

raymondginger2018-sudo wants to merge 1 commit into
lessweb:mainfrom
raymondginger2018-sudo:pr/mcp-pair-merge

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown

Summary

mergeMcpServers resolves command and args independently:

const command = projectConfig?.command ?? userConfig?.command;
const args = projectConfig?.args ?? userConfig?.args;

A project entry that names its own command but omits args therefore inherits the user-level args, which belong to a different executable. The merged pair is one no layer ever wrote — for example a project-level .cmd shim receiving ["@playwright/mcp@latest"]. The host spawns it, the shim exits on the unknown argument, and that server's tools disappear with no error anywhere.

Change

Resolve the pair together: the layer that supplies command owns args; args is borrowed across layers only when both layers name the same command.

const sameCommand =
  projectCommand !== undefined && projectCommand === userCommand;
const args =
  projectConfig?.args ??
  (projectCommand === undefined || sameCommand ? userConfig?.args : undefined);

This also heals configurations already on disk: a project override without args now means "no args" instead of "somebody else's args".

Tests

  • settings-and-notify.test.ts: 47 passed.
    • The env-priority test asserted the previous per-field behaviour for args; it now asserts the coherent-pair rule (env layering is untouched).
    • New case keeps command and its args in the same layer covers both branches: different commands (args dropped) and the same command on both layers (args inherited).
  • npm run check (typecheck + eslint + prettier): clean.

Notes

Two failures in model-settings.test.ts are pre-existing on this machine, not caused by this change: they fail identically with the patch stashed (git stash A/B on the same tree, pass 4 / fail 2 both ways).

`mergeMcpServers` resolved `command` and `args` independently: a project entry
that names its own command but omits `args` inherited the user-level `args`,
which belong to a different executable. The result is a pair no layer ever
wrote - e.g. a project-level `.cmd` shim receiving
`["@playwright/mcp@latest"]`: the host starts it, it exits on the unknown
argument, and that server's tools disappear without an error.

Resolve the pair together instead: the layer that supplies `command` owns
`args`; borrow `args` across layers only when both name the same command.

This also heals configurations already on disk: a project override without
args now means "no args" rather than "somebody else's args".

Tests: `settings-and-notify.test.ts` 47 passed. The env-priority test asserted
the old per-field behaviour for `args`; it now asserts the coherent-pair rule,
and a dedicated case covers both branches (different commands vs the same
command on both layers). `npm run check` (typecheck + eslint + prettier) is
clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant