Skip to content

Fix SSE gateway endpoint resolution#2959

Draft
nZiben wants to merge 1 commit into
modelcontextprotocol:mainfrom
nZiben:codex/fix-sse-gateway-prefix
Draft

Fix SSE gateway endpoint resolution#2959
nZiben wants to merge 1 commit into
modelcontextprotocol:mainfrom
nZiben:codex/fix-sse-gateway-prefix

Conversation

@nZiben

@nZiben nZiben commented Jun 24, 2026

Copy link
Copy Markdown

Fixes #795.

Summary

This updates the SSE client endpoint resolution logic for API-gateway and nested-route deployments.

Previously, sse_client used urljoin(url, sse.data) for endpoint events. If the public SSE URL included a gateway prefix and the server emitted an absolute endpoint path, Python treated the endpoint as origin-rooted and dropped the gateway prefix.

For example:

https://example.com/gateway/deployment/v1/sse + /v1/messages/?session_id=...

previously resolved to:

https://example.com/v1/messages/?session_id=...

The new resolver preserves the non-overlapping public prefix when the SSE URL path and endpoint path overlap:

https://example.com/gateway/deployment/v1/messages/?session_id=...

It intentionally keeps standard root-relative behavior for no-overlap absolute paths such as /messages, because those are ambiguous: the client cannot safely infer whether the endpoint should be rooted at the origin or under a gateway prefix. Server-side mount-prefix cases should continue to be handled through ASGI root_path.

Verification

  • uv run --frozen pytest tests/shared/test_sse.py -q
  • uv run --frozen ruff format --check src/mcp/client/sse.py tests/shared/test_sse.py
  • uv run --frozen ruff check src/mcp/client/sse.py tests/shared/test_sse.py
  • uv run --frozen pyright src/mcp/client/sse.py tests/shared/test_sse.py
  • targeted coverage for src/mcp/client/sse.py: 100%
  • UV_FROZEN=1 uv run --frozen strict-no-cover
  • ./scripts/test

@nZiben nZiben force-pushed the codex/fix-sse-gateway-prefix branch from 4085ff2 to 5f0974f Compare June 24, 2026 21:07
@nZiben nZiben changed the title [codex] Fix SSE gateway endpoint resolution Fix SSE gateway endpoint resolution Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for API Gateway Path Prefixes in SSE Client URL Handling

1 participant