Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

fix(mcp): preserve empty command argument positions (#8561)

Andrew Barnesdc5145dabd61
diff --git a/src/components/mcp/mcpDraft.ts b/src/components/mcp/mcpDraft.ts
index d85354ad3..0c81d5231 100644
--- a/src/components/mcp/mcpDraft.ts
+++ b/src/components/mcp/mcpDraft.ts
@@ -104,8 +104,7 @@ export function specOf(conn: McpDraftConnection, mask = false): McpServerSpec {
if (conn.transport === "stdio") {
spec.type = "stdio";
spec.command = conn.command.trim();
- const args = conn.args.filter((arg) => arg !== "");
- if (args.length) spec.args = args;
+ if (conn.args.length) spec.args = [...conn.args];
const env = objectOf(conn.env);
if (Object.keys(env).length) spec.env = env;
if (conn.cwd.trim()) spec.cwd = conn.cwd.trim();
diff --git a/tests/components/McpFormModal.test.tsx b/tests/components/McpFormModal.test.tsx
index 60d3276da..938c24065 100644
--- a/tests/components/McpFormModal.test.tsx
+++ b/tests/components/McpFormModal.test.tsx
@@ -225,6 +225,56 @@ describe("McpFormModal (drawer)", () => {
});
});
+ it.each(["form", "JSON"])(
+ "keeps empty arguments when saving from the %s tab",
+ async (tab) => {
+ const server: McpServer = {
+ id: "example",
+ name: "example",
+ server: {
+ type: "stdio",
+ command: "node",
+ args: ["server.js", "--label", "", "--mode", "read-only"],
+ },
+ apps: {} as McpServer["apps"],
+ };
+ renderForm({ editingId: "example", initialData: server });
+
+ if (tab === "JSON") {
+ await userEvent.click(screen.getByRole("button", { name: "JSON" }));
+ fireEvent.change(screen.getByLabelText("mcpPage.drawer.jsonLabel"), {
+ target: { value: JSON.stringify(server.server) },
+ });
+ }
+ await userEvent.click(
+ screen.getByRole("button", { name: "common.save" }),
+ );
+
+ await waitFor(() => expect(mocks.upsert).toHaveBeenCalledTimes(1));
+ expect(mocks.upsert.mock.calls[0][0].server).toEqual(server.server);
+ },
+ );
+
+ it("removes only the selected argument row, preserving other empty arguments", async () => {
+ renderForm({
+ editingId: "example",
+ initialData: {
+ id: "example",
+ name: "example",
+ server: { type: "stdio", command: "node", args: ["", "keep", ""] },
+ apps: {} as McpServer["apps"],
+ },
+ });
+
+ await userEvent.click(
+ screen.getAllByRole("button", { name: "mcpPage.drawer.removeArg" })[0],
+ );
+ await userEvent.click(screen.getByRole("button", { name: "common.save" }));
+
+ await waitFor(() => expect(mocks.upsert).toHaveBeenCalledTimes(1));
+ expect(mocks.upsert.mock.calls[0][0].server.args).toEqual(["keep", ""]);
+ });
+
it("masks secrets in the JSON tab and keeps them on save", async () => {
const server: McpServer = {
id: "serena",
diff --git a/tests/components/mcpDraft.test.ts b/tests/components/mcpDraft.test.ts
index 97b1d27bc..c9f52c41d 100644
--- a/tests/components/mcpDraft.test.ts
+++ b/tests/components/mcpDraft.test.ts
@@ -128,6 +128,29 @@ describe("mcpDraft form ⇄ JSON", () => {
startup_timeout_ms: 30000,
};
+ it.each([
+ { args: ["", "server.js"] },
+ { args: ["server.js", "--label", "", "--mode", "read-only"] },
+ { args: ["server.js", ""] },
+ { args: ["", ""] },
+ ])("preserves empty argument positions in $args", ({ args }) => {
+ const original = { type: "stdio" as const, command: "node", args };
+ const conn = connectionOf(original);
+ expect(specOf(conn)).toEqual(original);
+
+ const json = jsonTextOf(conn, false);
+ expect(JSON.parse(json)).toEqual(original);
+ const parsed = parseJsonText(json, conn);
+ expect(parsed.ok && specOf(connectionOf(parsed.spec))).toEqual(original);
+ });
+
+ it("omits args when there are no argument rows", () => {
+ expect(specOf(connectionOf({ command: "node", args: [] }))).toEqual({
+ type: "stdio",
+ command: "node",
+ });
+ });
+
it("keeps unknown fields and masks secrets only for display", () => {
const conn = connectionOf(spec);
expect(conn.extra).toEqual({ startup_timeout_ms: 30000 });