Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/core/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
45 changes: 44 additions & 1 deletion packages/core/src/tests/settings-and-notify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
{
Expand Down
Loading