Skip to content

Commit 8876787

Browse files
authored
Update sse.py to preserve url base
fix: preserve base path when joining /messages from SSE endpoint Previous behavour, a MCP server at: https://my-mcp-server.com/mcp/weather-alerts/sse would fail to connect to messages as the endpoint would be called as: https://my-mcp-server.com/messages It should be: https://my-mcp-server.com/mcp/weather-alerts/messages
1 parent c2ca8e0 commit 8876787

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/mcp/client/sse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ async def sse_reader(
6161
logger.debug(f"Received SSE event: {sse.event}")
6262
match sse.event:
6363
case "endpoint":
64-
endpoint_url = urljoin(url, sse.data)
64+
uri_base = url.rsplit("/sse", 1)[0]
65+
endpoint_url = urljoin(uri_base + "/", sse.data.lstrip("/"))
6566
logger.info(
6667
f"Received endpoint URL: {endpoint_url}"
6768
)

0 commit comments

Comments
 (0)