Skip to content

Commit 40bd73c

Browse files
Pass incoming headers to the DO fetch method (#357)
* Pass incoming headers to the DO fetch method * Create dry-parrots-smash.md --------- Co-authored-by: Sunil Pai <threepointone@gmail.com>
1 parent 77368ff commit 40bd73c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/dry-parrots-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"agents": patch
3+
---
4+
5+
Pass incoming headers to the DO fetch method

packages/agents/src/mcp/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,14 @@ export abstract class McpAgent<
613613
const upgradeUrl = new URL(request.url);
614614
// enforce that the path that the DO receives is always /sse
615615
upgradeUrl.pathname = "/sse";
616+
const existingHeaders: Record<string, string> = {};
617+
request.headers.forEach((value, key) => {
618+
existingHeaders[key] = value;
619+
});
616620
const response = await doStub.fetch(
617621
new Request(upgradeUrl, {
618622
headers: {
623+
...existingHeaders,
619624
Upgrade: "websocket",
620625
// Required by PartyServer
621626
"x-partykit-room": sessionId
@@ -990,9 +995,14 @@ export abstract class McpAgent<
990995
// Connect to the Durable Object via WebSocket
991996
const upgradeUrl = new URL(request.url);
992997
upgradeUrl.pathname = "/streamable-http";
998+
const existingHeaders: Record<string, string> = {};
999+
request.headers.forEach((value, key) => {
1000+
existingHeaders[key] = value;
1001+
});
9931002
const response = await doStub.fetch(
9941003
new Request(upgradeUrl, {
9951004
headers: {
1005+
...existingHeaders,
9961006
Upgrade: "websocket",
9971007
// Required by PartyServer
9981008
"x-partykit-room": sessionId

0 commit comments

Comments
 (0)