From d9ef92883e13916fe0b1e00ed04bc6eb506cf896 Mon Sep 17 00:00:00 2001 From: pragnyanramtha Date: Sun, 17 May 2026 04:05:42 +0000 Subject: [PATCH] fix: allow empty env values in cli launcher --- cli/__tests__/cli.test.ts | 20 ++++++++++++++++++++ cli/src/cli.ts | 17 ++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/cli/__tests__/cli.test.ts b/cli/__tests__/cli.test.ts index b263f618c..d40ae093f 100644 --- a/cli/__tests__/cli.test.ts +++ b/cli/__tests__/cli.test.ts @@ -123,6 +123,26 @@ describe("CLI Tests", () => { expect(envVars.API_KEY).toBe("abc123=xyz789=="); }); + it("should accept empty environment variable values", async () => { + const { command, args } = getTestMcpServerCommand(); + const result = await runCli([ + command, + ...args, + "-e", + "EMPTY_ENV=", + "--cli", + "--method", + "resources/read", + "--uri", + "test://env", + ]); + + expectCliSuccess(result); + const json = expectValidJson(result); + const envVars = JSON.parse(json.contents[0].text); + expect(envVars.EMPTY_ENV).toBe(""); + }); + it("should handle environment variable with base64-encoded value", async () => { const { command, args } = getTestMcpServerCommand(); const result = await runCli([ diff --git a/cli/src/cli.ts b/cli/src/cli.ts index f4187e02d..e6688eb8d 100644 --- a/cli/src/cli.ts +++ b/cli/src/cli.ts @@ -205,17 +205,24 @@ function parseKeyValuePair( value: string, previous: Record = {}, ): Record { - const parts = value.split("="); - const key = parts[0]; - const val = parts.slice(1).join("="); + const equalsIndex = value.indexOf("="); - if (val === undefined || val === "") { + if (equalsIndex === -1) { throw new Error( `Invalid parameter format: ${value}. Use key=value format.`, ); } - return { ...previous, [key as string]: val }; + const key = value.slice(0, equalsIndex); + const val = value.slice(equalsIndex + 1); + + if (key === "") { + throw new Error( + `Invalid parameter format: ${value}. Use key=value format.`, + ); + } + + return { ...previous, [key]: val }; } function parseHeaderPair(