Skip to content

Python MCP SDK: Incorrect handling of absolute paths in SSE endpoint URLs leads to incorrect URL construction. #585

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

Open
footuser opened this issue Apr 25, 2025 · 1 comment · May be fixed by #597
Labels
bug Something isn't working

Comments

@footuser
Copy link

Describe the bug
When the MCP server, connected via SSE, returns an endpoint event with a data value that starts with / (e.g., /mcp/message?sessionId=...), the SDK appears to be using this absolute path directly without considering the base URL of the initial SSE connection. This results in the client attempting to access an incorrect URL.

To Reproduce
Steps to reproduce the behavior:

  1. Establish an SSE connection to an MCP server with a URL like: http://my.mcp-server.com/weather/sse.
  2. Observe the server sending an SSE event with event: endpoint and data: /mcp/message?sessionId=your_session_id.
  3. The client, using the Python MCP SDK, constructs the endpoint URL as http://my.mcp-server.com/mcp/message?sessionId=your_session_id.
  4. The expected behavior, based on the MCPEx specification (clients should use the same origin as the SSE connection and append the received path), is that the URL should be http://my.mcp-server.com/weather/mcp/message?sessionId=your_session_id.

Expected behavior
The expected URL should be http://my.mcp-server.com/weather/mcp/message?sessionId=your_session_id.

Possible Root Cause:
Relevant Code Snippet (from langchain-mcp-adapters/client.py - for context):

Image

urllib.parse.urljoin treats paths starting with / as absolute paths, causing it to discard the path component of the base URL (http://my.mcp-server.com/weather/sse) and only use the hostname.

Suggested Solution
When the server returns an endpoint URL starting with /, the SDK should treat it as a path to be appended to the path of the initial SSE connection URL, rather than a completely new absolute path relative to the server root. This might involve checking if sse_data starts with / and adjusting the base URL used in the URL joining process accordingly.

Image

@kavinkumar807
Copy link

kavinkumar807 commented Apr 25, 2025

@footuser Debugging the issue will raise PR for it

@ihrpr ihrpr added the bug Something isn't working label Apr 27, 2025
@aarora79 aarora79 linked a pull request Apr 28, 2025 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants