Skip to content

bug: custom url prefix gets overwritten in sse #583

Open
@NishantJoshi00

Description

@NishantJoshi00

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:

this._endpoint = new URL(messageEvent.data, this._url);


Steps to Reproduce

  1. Deploy the MCP server behind a reverse proxy with a path prefix (e.g., /mcp).
  2. Access the SSE endpoint at https://example.com/mcp/sse.
  3. 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/*.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions