Title: fix: preserve API gateway path prefix in SSE client URL resolution by Varun6578 · Pull Request #2243 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix: preserve API gateway path prefix in SSE client URL resolution by Varun6578 · Pull Request #2243 · modelcontextprotocol/python-sdk
X Title: fix: preserve API gateway path prefix in SSE client URL resolution by Varun6578 · Pull Request #2243 · modelcontextprotocol/python-sdk
Description: Summary Fixes #795 When an MCP server sits behind a reverse proxy or API gateway that adds a path prefix (e.g., /gateway), the server's endpoint events contain paths without that prefix. The SSE client previously used urljoin() which drops the base URL's path prefix for absolute paths (starting with /), causing incorrect routing through the gateway. Changes src/mcp/client/sse.py: Added _resolve_endpoint_url() that detects and preserves reverse proxy/API gateway path prefixes Replaced urljoin(url, sse.data) with _resolve_endpoint_url(url, sse.data) on the endpoint event handler tests/shared/test_sse.py: Added 8 parametrized test cases for _resolve_endpoint_url() covering: Gateway prefix preservation (the reported bug) Deep gateway prefixes (/org/team/v1/sse) No prefix (preserves existing behavior) Relative paths and absolute URL endpoints How it works The function detects gateway prefixes by finding where the endpoint's first path segment appears in the base URL path. Everything before that match is the prefix to preserve. base_url: https://host/gateway/v1/sse endpoint: /v1/messages/?session_id=abc before: https://host/v1/messages/?session_id=abc (prefix lost!) after: https://host/gateway/v1/messages/?session_id=abc (prefix preserved)
Open Graph Description: Summary Fixes #795 When an MCP server sits behind a reverse proxy or API gateway that adds a path prefix (e.g., /gateway), the server's endpoint events contain paths without that prefix. The SS...
X Description: Summary Fixes #795 When an MCP server sits behind a reverse proxy or API gateway that adds a path prefix (e.g., /gateway), the server's endpoint events contain paths without that prefix. Th...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2243
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1baa5ad7-3e58-c39c-10da-1121ad55ab13 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B6B0:1E1C8E:8837A:C43D0:6A6360AA |
| html-safe-nonce | b07e4da1936f7e3322bb83a1194e630180b7acc43f16d086cd72c79f1096af54 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkIwOjFFMUM4RTo4ODM3QTpDNDNEMDo2QTYzNjBBQSIsInZpc2l0b3JfaWQiOiIxNDI3MDQ1MDc4NTIzODIzNzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b913a0da79a99ec000b4b4eda55ade77628040135efe7448679a6723d6340bae |
| hovercard-subject-tag | pull_request:3366939688 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2243/files |
| twitter:image | https://avatars.githubusercontent.com/u/34965159?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/34965159?s=400&v=4 |
| og:image:alt | Summary Fixes #795 When an MCP server sits behind a reverse proxy or API gateway that adds a path prefix (e.g., /gateway), the server's endpoint events contain paths without that prefix. The SS... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 71b1218de2f2ab29c4d5ce72568e68e2c56044c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width