diff --git a/packages/core/src/settings.ts b/packages/core/src/settings.ts index 8dbbf89..1d16eb5 100644 --- a/packages/core/src/settings.ts +++ b/packages/core/src/settings.ts @@ -556,7 +556,9 @@ function mergeMcpServers( for (const name of serverNames) { const userConfig = userServers[name]; const projectConfig = projectServers[name]; - const command = projectConfig?.command ?? userConfig?.command; + const projectCommand = projectConfig?.command; + const userCommand = userConfig?.command; + const command = projectCommand ?? userCommand; if (!command) { continue; } @@ -571,9 +573,18 @@ function mergeMcpServers( ...systemEnv, ...systemMcpEnv, }; + // `command` and `args` describe one executable: a layer that names its own + // command owns its argument list. Inheriting `args` from a layer that names + // a *different* command silently produces a pair neither layer wrote (a + // project-level `.cmd` shim receiving user-level `["@playwright/mcp@latest"]` + // -> the host starts it, it exits on the unknown argument, and the server's + // tools disappear without an error). Only borrow `args` across layers when + // both name the same command. + const sameCommand = projectCommand !== undefined && projectCommand === userCommand; + const args = projectConfig?.args ?? (projectCommand === undefined || sameCommand ? userConfig?.args : undefined); const config: McpServerConfig = { command, - args: projectConfig?.args ?? userConfig?.args, + args, }; if (Object.keys(env).length > 0) { config.env = env; diff --git a/packages/core/src/tests/settings-and-notify.test.ts b/packages/core/src/tests/settings-and-notify.test.ts index a5ca060..a9af0f9 100644 --- a/packages/core/src/tests/settings-and-notify.test.ts +++ b/packages/core/src/tests/settings-and-notify.test.ts @@ -558,7 +558,9 @@ test("resolveSettingsSources merges MCP env with documented priority", () => { ); assert.equal(resolved.mcpServers?.github?.command, "python"); - assert.deepEqual(resolved.mcpServers?.github?.args, ["user-server.js"]); + // `command` and `args` describe one executable, so the project-level command + // does not inherit the user-level args of a different binary. + assert.equal(resolved.mcpServers?.github?.args, undefined); assert.deepEqual(resolved.mcpServers?.github?.env, { MCP_GITHUB_PERSONAL_ACCESS_TOKEN: "system-global", GITHUB_PERSONAL_ACCESS_TOKEN: "system-global", @@ -567,6 +569,47 @@ test("resolveSettingsSources merges MCP env with documented priority", () => { }); }); +test("resolveSettingsSources keeps command and its args in the same layer", () => { + const resolved = resolveSettingsSources( + { + mcpServers: { + playwright: { + command: "npx", + args: ["@playwright/mcp@latest"], + }, + shared: { + command: "npx", + args: ["--user-level"], + }, + }, + }, + { + mcpServers: { + playwright: { + command: "/usr/local/bin/playwright-mcp", + }, + shared: { + command: "npx", + }, + }, + }, + { + model: "default-model", + baseURL: "https://default.example.com", + }, + TEST_PROCESS_ENV + ); + + // A layer that names its own command owns the argument list: borrowing the + // user-level args would hand `@playwright/mcp@latest` to a different binary. + assert.equal(resolved.mcpServers?.playwright?.command, "/usr/local/bin/playwright-mcp"); + assert.equal(resolved.mcpServers?.playwright?.args, undefined); + + // Same command on both layers: the user-level args still apply. + assert.equal(resolved.mcpServers?.shared?.command, "npx"); + assert.deepEqual(resolved.mcpServers?.shared?.args, ["--user-level"]); +}); + test("resolveSettings defaults DeepSeek v4 models to thinking mode", () => { const resolved = resolveSettings( {