attach auth headers to the streamable http request
This commit is contained in:
@@ -20,6 +20,7 @@ import { findActualExecutable } from "spawn-rx";
|
|||||||
import mcpProxy from "./mcpProxy.js";
|
import mcpProxy from "./mcpProxy.js";
|
||||||
|
|
||||||
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
|
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
|
||||||
|
const STREAMABLE_HTTP_HEADERS_PASSTHROUGH = ["authorization"];
|
||||||
|
|
||||||
const defaultEnvironment = {
|
const defaultEnvironment = {
|
||||||
...getDefaultEnvironment(),
|
...getDefaultEnvironment(),
|
||||||
@@ -96,8 +97,24 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
|
|||||||
console.log("Connected to SSE transport");
|
console.log("Connected to SSE transport");
|
||||||
return transport;
|
return transport;
|
||||||
} else if (transportType === "streamable-http") {
|
} else if (transportType === "streamable-http") {
|
||||||
|
const headers: HeadersInit = {};
|
||||||
|
|
||||||
|
for (const key of STREAMABLE_HTTP_HEADERS_PASSTHROUGH) {
|
||||||
|
if (req.headers[key] === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = req.headers[key];
|
||||||
|
headers[key] = Array.isArray(value) ? value[value.length - 1] : value;
|
||||||
|
}
|
||||||
|
|
||||||
const transport = new StreamableHTTPClientTransport(
|
const transport = new StreamableHTTPClientTransport(
|
||||||
new URL(query.url as string),
|
new URL(query.url as string),
|
||||||
|
{
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
await transport.start();
|
await transport.start();
|
||||||
console.log("Connected to Streamable HTTP transport");
|
console.log("Connected to Streamable HTTP transport");
|
||||||
|
|||||||
Reference in New Issue
Block a user