hermes-agent/web/src/lib/mcp-server-create.test.ts
Siddharth Balyan 56ab9951b1
fix(dashboard): add MCP auth to profile builder (#65163)
* fix(dashboard): add MCP auth to profile builder

* fix(dashboard): preserve MCP rejection error contract

* feat(dashboard): refine profile MCP picker
2026-07-16 02:05:04 +05:30

99 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildMcpServerCreate, emptyMcpServerDraft } from "./mcp-server-create";
describe("buildMcpServerCreate", () => {
it("builds an HTTP Bearer request without stdio fields", () => {
const server = buildMcpServerCreate({
...emptyMcpServerDraft(),
name: " Linear ",
url: " https://mcp.linear.app/mcp ",
httpAuth: "header",
bearerToken: "Bearer secret-token",
command: "ignored",
args: "--ignored",
env: "IGNORED=value",
});
expect(server).toEqual({
name: "Linear",
url: "https://mcp.linear.app/mcp",
auth: "header",
bearer_token: "Bearer secret-token",
});
});
it("builds OAuth and unauthenticated HTTP requests without a token", () => {
expect(
buildMcpServerCreate({
...emptyMcpServerDraft(),
name: "oauth",
url: "https://example.com/mcp",
httpAuth: "oauth",
}),
).toEqual({
name: "oauth",
url: "https://example.com/mcp",
auth: "oauth",
});
expect(
buildMcpServerCreate({
...emptyMcpServerDraft(),
name: "public",
url: "https://example.com/mcp",
}),
).toEqual({
name: "public",
url: "https://example.com/mcp",
});
});
it("parses stdio arguments and environment assignments", () => {
const server = buildMcpServerCreate({
...emptyMcpServerDraft(),
name: "local",
transport: "stdio",
command: " uvx ",
args: "mcp-server, --debug",
env: "API_KEY=secret\nURL=https://example.com?a=b\nINVALID",
});
expect(server).toEqual({
name: "local",
command: "uvx",
args: ["mcp-server", "--debug"],
env: {
API_KEY: "secret",
URL: "https://example.com?a=b",
},
});
});
it("rejects missing transport fields and Bearer tokens", () => {
expect(() => buildMcpServerCreate(emptyMcpServerDraft())).toThrow(
"Name required",
);
expect(() =>
buildMcpServerCreate({
...emptyMcpServerDraft(),
name: "remote",
}),
).toThrow("URL required");
expect(() =>
buildMcpServerCreate({
...emptyMcpServerDraft(),
name: "remote",
url: "https://example.com/mcp",
httpAuth: "header",
}),
).toThrow("Bearer token required");
expect(() =>
buildMcpServerCreate({
...emptyMcpServerDraft(),
name: "local",
transport: "stdio",
}),
).toThrow("Command required");
});
});