Skip to content

Fix SSE client handling of nested path URLs #386

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
wants to merge 13 commits into from
Closed
Prev Previous commit
Next Next commit
style: format to avoid max-line validation error
  • Loading branch information
eyeonyou committed Apr 9, 2025
commit 3728328497814e046293e5ffc8ac8571968e9e2d
5 changes: 4 additions & 1 deletion src/mcp/server/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ async def connect_sse(self, scope: Scope, receive: Receive, send: Send):

session_id = uuid4()
request_path = scope["path"]

match = re.match(r"^/([^/]+(?:/mcp)?)/sse$", request_path)
mount_prefix = match.group(1) if match else ""
session_uri = f"/{quote(mount_prefix)}{quote(self._endpoint)}?session_id={session_id.hex}"

session_uri = f"/{quote(mount_prefix)}{quote(self._endpoint)}"
session_uri += f"?session_id={session_id.hex}"

self._read_stream_writers[session_id] = read_stream_writer
logger.debug(f"Created new session with ID: {session_id}")
Expand Down
Loading