Skip to content

Incorrect URL in sse.js when providing a custom path #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AbdullatifGhajar opened this issue Apr 14, 2025 · 3 comments · Fixed by modelcontextprotocol/typescript-sdk#466
Labels
bug Something isn't working waiting on submitter Waiting for the submitter to provide more info

Comments

@AbdullatifGhajar
Copy link

Summary
When adding an sse server using a custom path (e.g. http://localhost:3001/custom/path/sse), the server sends messages requests to http://localhost:3001 instead of http://localhost:3001/custom/path.

Steps to reproduce
Steps to reproduce the behavior:

  1. Launch an SSE MCP server on a custom path (e.g. http://localhost:3001/custom/path)
  2. Connect the inspector to it using the UI (enter http://localhost:3001/custom/path/sse in the URL field)
  3. Try to connect. Instead of successful connection, yo get an error because it sends requests to http://localhost:3001

Issue
this._endpoint = new URL(messageEvent.data, this._url); in sse.js ignores custom path, which is needed for the upcoming requests.

Impact
No connection is possible

@AbdullatifGhajar AbdullatifGhajar added the bug Something isn't working label Apr 14, 2025
@olaservo olaservo added the waiting on sdk Waiting for an SDK feature label May 2, 2025
bhosmer-ant added a commit to modelcontextprotocol/typescript-sdk that referenced this issue May 8, 2025
When an SSE client connects with a custom path (e.g., /api/v1/custom/sse),
ensure the endpoint URL maintains the same base path structure but with
/messages instead of /sse. This fixes issues where custom endpoints were
getting collapsed to the root path.

Should fix issues reported in modelcontextprotocol/inspector#313 and #296
Tests demonstrating the issue were added in PR #439

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
bhosmer-ant added a commit to modelcontextprotocol/typescript-sdk that referenced this issue May 12, 2025
When an SSE client connects with a custom path (e.g., /api/v1/custom/sse),
ensure the endpoint URL maintains the same base path structure but with
/messages instead of /sse. This fixes issues where custom endpoints were
getting collapsed to the root path.

Should fix issues reported in modelcontextprotocol/inspector#313 and #296
Tests demonstrating the issue were added in PR #439

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jerome3o-anthropic
Copy link
Member

Hey I had a quick dig into this issue. We'd originallly suspected a bug in the typescript SDK

I wrote some tests that I would expect to fail if it were an issue with the typescript sdk client implementation (draft pr here).

However, they don't fail, which leads me to suspect that you have an MCP server that doesn't set the endpoint SSE event correctly:

When a client connects, the server MUST send an endpoint event containing a URI for the client to use for sending messages. All subsequent client messages MUST be sent as HTTP POST requests to this endpoint.

@AbdullatifGhajar are you able to provide more information on the MCP server you're using to hit this bug? (i.e. is it in typescript/python, how did you set the custom path, source code would be amazing)

@olaservo olaservo added waiting on submitter Waiting for the submitter to provide more info and removed waiting on sdk Waiting for an SDK feature labels May 18, 2025
@cliffhall
Copy link
Contributor

cliffhall commented May 21, 2025

Steps to reproduce the behavior:

  1. Launch an SSE MCP server on a custom path (e.g. http://localhost:3001/custom/path)
  2. Connect the inspector to it using the UI (enter http://localhost:3001/custom/path/sse in the URL field)
  3. Try to connect. Instead of successful connection, yo get an error because it sends requests to http://localhost:3001

I made custom paths in an SSE server for the initial connection AND for the subsequent messages, ran it, then connected to it with the latest version of the Inspector. No issues.

Image
Screen.Recording.2025-05-21.at.1.57.23.PM.mov

Please note

The Inspector has a proxy server to which it connects and sends messages via the normal endpoints. So even though my server is receiving connections at http://localhost:3001/my/custom/sse and receiving subsequent messages at http://localhost:3001/my/custom/message the browser shows /message as the endpoint because that's the endpoint on the proxy server itself. The MCP server ends up receiving connections and messages at the custom endpoints.

Image

@olaservo
Copy link
Member

@AbdullatifGhajar I'm going to close this since it doesn't seem like its a bug with Inspector, as mentioned in the latest comments. Feel free to re-open if you're still having issues and can share the server code where you're running into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting on submitter Waiting for the submitter to provide more info
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants