Description
Describe the Bug
When running the MCP server behind a proxy and exposing it at a subpath such as https://example.com/mcp/sse
, the EventSource
connection is established successfully. However, subsequent redirection to the /messages/*
endpoint does not preserve the base path prefix.
Instead of using the correct path https://example.com/mcp/messages/*
, the SDK incorrectly attempts to connect to https://example.com/messages/*
, stripping the /mcp
prefix.
Relevant code:
typescript-sdk/src/client/sse.ts
Line 148 in 590d484
Steps to Reproduce
- Deploy the MCP server behind a reverse proxy with a path prefix (e.g.,
/mcp
). - Access the SSE endpoint at
https://example.com/mcp/sse
. - Observe the redirected connection target when the server pushes updates.
Expected Behavior
The SDK should preserve the original base path prefix (/mcp
) and construct the /messages/*
URLs relative to it, resulting in a correct path like https://example.com/mcp/messages/*
.