Skip to content
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

Fix SSE client handling of nested path URLs #386

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/mcp/client/sse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
from contextlib import asynccontextmanager
from typing import Any
from urllib.parse import urljoin, urlparse
@@ -61,7 +62,15 @@ async def sse_reader(
logger.debug(f"Received SSE event: {sse.event}")
match sse.event:
case "endpoint":
endpoint_url = urljoin(url, sse.data)
base_path = re.search(
r"https?://[^/]+/(.+)/sse$", url
)
base_path = (
base_path.group(1) if base_path else ""
)
endpoint_url = urljoin(
url, base_path + sse.data
)
logger.info(
f"Received endpoint URL: {endpoint_url}"
)