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
24 changes: 24 additions & 0 deletions src/http.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@ describe("HTTP transport configuration", () => {
);
});

it("allows the mcp-protocol-version request header in preflight", async () => {
await start({ allowedOrigins: ["https://app.example"] });

// The official StreamableHTTPClientTransport sends mcp-protocol-version
// on every request after initialize, so browser preflights ask for it.
const preflight = await fetch(`${baseUrl}/mcp`, {
method: "OPTIONS",
headers: {
Origin: "https://app.example",
"Access-Control-Request-Method": "POST",
"Access-Control-Request-Headers":
"content-type,mcp-session-id,mcp-protocol-version",
},
});

expect(preflight.headers.get("access-control-allow-origin")).toBe(
"https://app.example",
);
const allowHeaders = (
preflight.headers.get("access-control-allow-headers") ?? ""
).toLowerCase();
expect(allowHeaders).toContain("mcp-protocol-version");
});

it("does not allow a non-allowlisted origin even when others are allowlisted", async () => {
await start({ allowedOrigins: ["https://app.example"] });

Expand Down
2 changes: 1 addition & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function createHttpApp(options: HttpAppOptions): Express {
return callback(new CorsOriginNotAllowedError(origin));
},
exposedHeaders: ["Mcp-Session-Id", "mcp-protocol-version"],
allowedHeaders: ["Content-Type", "mcp-session-id"],
allowedHeaders: ["Content-Type", "mcp-session-id", "mcp-protocol-version"],
}),
);

Expand Down
2 changes: 1 addition & 1 deletion src/transport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("Transport Integration Tests", () => {
app.use(cors({
origin: "*",
exposedHeaders: ["Mcp-Session-Id", "mcp-protocol-version"],
allowedHeaders: ["Content-Type", "mcp-session-id"],
allowedHeaders: ["Content-Type", "mcp-session-id", "mcp-protocol-version"],
}));
app.use(express.json());
});
Expand Down