Skip to content

Commit 7e52f41

Browse files
authored
do not remove search params and hash from mcp endpoint message
Reference: modelcontextprotocol/typescript-sdk#177
1 parent 671bdf7 commit 7e52f41

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/agents/src/mcp/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,11 @@ export abstract class McpAgent<
558558
const encoder = new TextEncoder();
559559

560560
// Send the endpoint event
561-
const endpointMessage = `event: endpoint\ndata: ${encodeURI(`${pathname}/message`)}?sessionId=${sessionId}\n\n`;
561+
const endpointUrl = new URL(request.url)
562+
endpointUrl.pathname = encodeURI(`${pathname}/message`)
563+
endpointUrl.searchParams.set('sessionId', sessionId)
564+
const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;
565+
const endpointMessage = `event: endpoint\ndata: ${relativeUrlWithSession}\n\n`;
562566
writer.write(encoder.encode(endpointMessage));
563567

564568
// Get the Durable Object

0 commit comments

Comments
 (0)