Skip to content

Commit a9c7af5

Browse files
committed
fix: auth context
1 parent 11d6249 commit a9c7af5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

.changeset/olive-bottles-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mcp-handler": patch
3+
---
4+
5+
Ensure auth profiles stay tied to the request

src/handler/mcp-api-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface SerializedRequest {
2929
method: string;
3030
body: BodyType;
3131
headers: IncomingHttpHeaders;
32+
auth?: AuthInfo;
3233
}
3334

3435
type LogLevel = "log" | "error" | "warn" | "info" | "debug";
@@ -571,11 +572,13 @@ export function initializeMcpApiHandler(
571572
const request = JSON.parse(message) as SerializedRequest;
572573

573574
// Make in IncomingMessage object because that is what the SDK expects.
575+
// Pass auth from the serialized request to preserve the caller's auth context
574576
const req = createFakeIncomingMessage({
575577
method: request.method,
576578
url: request.url,
577579
headers: request.headers,
578580
body: request.body,
581+
auth: request.auth,
579582
});
580583

581584
const syntheticRes = new EventEmittingResponse(
@@ -720,6 +723,7 @@ export function initializeMcpApiHandler(
720723
method: req.method || "",
721724
body: parsedBody,
722725
headers: Object.fromEntries(req.headers.entries()),
726+
auth: req.auth,
723727
};
724728

725729
// Declare timeout and response handling state before subscription

0 commit comments

Comments
 (0)