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
20 changes: 20 additions & 0 deletions cli/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
17 changes: 12 additions & 5 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,24 @@ function parseKeyValuePair(
value: string,
previous: Record<string, string> = {},
): Record<string, string> {
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(
Expand Down
Loading