Skip to content

Commit 89edbf5

Browse files
committed
attach auth headers to the streamable http request
1 parent ed4a2cf commit 89edbf5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

server/src/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { findActualExecutable } from "spawn-rx";
2020
import mcpProxy from "./mcpProxy.js";
2121

2222
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
23+
const STREAMABLE_HTTP_HEADERS_PASSTHROUGH = ["authorization"];
2324

2425
const defaultEnvironment = {
2526
...getDefaultEnvironment(),
@@ -96,8 +97,24 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
9697
console.log("Connected to SSE transport");
9798
return transport;
9899
} else if (transportType === "streamable-http") {
100+
const headers: HeadersInit = {};
101+
102+
for (const key of STREAMABLE_HTTP_HEADERS_PASSTHROUGH) {
103+
if (req.headers[key] === undefined) {
104+
continue;
105+
}
106+
107+
const value = req.headers[key];
108+
headers[key] = Array.isArray(value) ? value[value.length - 1] : value;
109+
}
110+
99111
const transport = new StreamableHTTPClientTransport(
100112
new URL(query.url as string),
113+
{
114+
requestInit: {
115+
headers,
116+
},
117+
},
101118
);
102119
await transport.start();
103120
console.log("Connected to Streamable HTTP transport");

0 commit comments

Comments
 (0)