René's URL Explorer Experiment


Title: Support for API Gateway Path Prefixes in SSE Client URL Handling · Issue #795 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: Support for API Gateway Path Prefixes in SSE Client URL Handling · Issue #795 · modelcontextprotocol/python-sdk

X Title: Support for API Gateway Path Prefixes in SSE Client URL Handling · Issue #795 · modelcontextprotocol/python-sdk

Description: Is your feature request related to a problem? Please describe. When using the client SDK to connect MCP server behind an API gateway that adds a deployment-specific prefix (e.g., /gateway_prefix/), the backend mcp server...

Open Graph Description: Is your feature request related to a problem? Please describe. When using the client SDK to connect MCP server behind an API gateway that adds a deployment-specific prefix (e.g., /gateway_prefix/

X Description: Is your feature request related to a problem? Please describe. When using the client SDK to connect MCP server behind an API gateway that adds a deployment-specific prefix (e.g., /gateway_prefix/&l...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/795

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for API Gateway Path Prefixes in SSE Client URL Handling","articleBody":"**Is your feature request related to a problem? Please describe.**\n\nWhen using the client SDK to connect MCP server behind an `API gateway` that adds a deployment-specific prefix (e.g., `/gateway_prefix/\u003cdeployment_name\u003e`), the backend mcp server is unaware of this prefix and only exposes routes like `/v1/sse` and `/v1/messages`. The client SDK currently only supports [url](https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py#L25) and uses [urljoin](https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py#L75) to resolve endpoint URLs, which causes the gateway prefix to be dropped when joining paths that start with /. This results in incorrect routing through the gateway.\n\ndebug logs:\n\n```\n❯ python3 client.py\nDEBUG:asyncio:Using selector: KqueueSelector\nINFO:mcp.client.sse:Connecting to SSE endpoint: https://example.com/gateway_prefix/\u003cdeployment_name\u003e/v1/sse\nDEBUG:httpcore.connection:connect_tcp.started host='https://example.com' port=443 local_address=None timeout=5 socket_options=None\nDEBUG:httpcore.connection:connect_tcp.complete return_value=\u003chttpcore._backends.anyio.AnyIOStream object at 0x10889fef0\u003e\nDEBUG:httpcore.connection:start_tls.started ssl_context=\u003cssl.SSLContext object at 0x10895ca50\u003e server_hostname='example.com' timeout=5\nDEBUG:httpcore.connection:start_tls.complete return_value=\u003chttpcore._backends.anyio.AnyIOStream object at 0x107fb45c0\u003e\nDEBUG:httpcore.http11:send_request_headers.started request=\u003cRequest [b'GET']\u003e\nDEBUG:httpcore.http11:send_request_headers.complete\nDEBUG:httpcore.http11:send_request_body.started request=\u003cRequest [b'GET']\u003e\nDEBUG:httpcore.http11:send_request_body.complete\nDEBUG:httpcore.http11:receive_response_headers.started request=\u003cRequest [b'GET']\u003e\nDEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'cache-control', b'no-store'), (b'content-type', b'text/event-stream; charset=utf-8'), (b'date', b'Fri, 23 May 2025 15:45:20 GMT'), (b'x-accel-buffering', b'no'), (b'x-upstream-service-time', b'7'), (b'transfer-encoding', b'chunked')])\nINFO:httpx:HTTP Request: GET https://example.com/gateway_prefix/\u003cdeployment_name\u003e/v1/sse \"HTTP/1.1 200 OK\" \u003c== correct sse endpoint\nDEBUG:mcp.client.sse:SSE connection established\nDEBUG:httpcore.http11:receive_response_body.started request=\u003cRequest [b'GET']\u003e\nDEBUG:mcp.client.sse:Received SSE event: endpoint\nDEBUG:mcp.client.sse:urljoin: https://example.com/gateway_prefix/\u003cdeployment_name\u003e/v1/sse + /v1/messages/?session_id=80b1237100a34eaa9795a5993661c76a \u003c== wrong messages endpoint\nINFO:mcp.client.sse:Received endpoint URL: https://example.com/v1/messages/?session_id=80b1237100a34eaa9795a5993661c76a\nINFO:mcp.client.sse:Starting post writer with endpoint URL: https://example.com/v1/messages/?session_id=80b1237100a34eaa9795a5993661c76a\n```\n\n**Describe the solution you'd like**\nThe client SDK should preserve the gateway prefix when joining endpoint URLs, so that requests are routed correctly through the gateway. Ideally, the SDK should provide a way to configure or detect the gateway prefix and ensure all endpoint URLs are constructed with it.\n\n**Describe alternatives you've considered**\n\n**Additional context**\n\nExample:\n```python\nurl = \"https://example.com/gateway_prefix/\u003cdeployment_name\u003e/v1/sse\"\npath = \"/v1/messages\"\nurljoin(url, path)\n# Actual:   https://example.com/v1/messages\n# Expected: https://example.com/gateway_prefix/\u003cdeployment_name\u003e/v1/messages\n```\nThis is a common pattern for API gateways and reverse proxies, so supporting this would improve compatibility.\n\nsimilar request: \nhttps://github.com/modelcontextprotocol/python-sdk/issues/412#issuecomment-2820077952\nhttps://github.com/modelcontextprotocol/python-sdk/issues/733\nhttps://github.com/modelcontextprotocol/python-sdk/pull/386\n","author":{"url":"https://github.com/lizzzcai","@type":"Person","name":"lizzzcai"},"datePublished":"2025-05-23T16:14:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/795/python-sdk/issues/795"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:718edc41-6eff-1b88-d387-2572a750b308
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCAC8:2F70B7:86410A:BE9809:6A6319C7
html-safe-nonce7f22f2208578e2820ff8739c90733610ae546fa1bd596ea21674adf08ebf73f3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUM4OjJGNzBCNzo4NjQxMEE6QkU5ODA5OjZBNjMxOUM3IiwidmlzaXRvcl9pZCI6IjE0MzUwMTA2MjA0NzYwMzc1NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac3103c993af2f43f32eb5d4d6f7c2502306d55f38b3a264a14cf1fff2ff69671b
hovercard-subject-tagissue:3086877237
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/795/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e752e67510a15c94f7b6873fd844cbff05777aff282ad47830e1f649074a4900/modelcontextprotocol/python-sdk/issues/795
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e752e67510a15c94f7b6873fd844cbff05777aff282ad47830e1f649074a4900/modelcontextprotocol/python-sdk/issues/795
og:image:altIs your feature request related to a problem? Please describe. When using the client SDK to connect MCP server behind an API gateway that adds a deployment-specific prefix (e.g., /gateway_prefix/
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamelizzzcai
hostnamegithub.com
expected-hostnamegithub.com
None1a6c056e02f174fffc096c521ec0ff6fb83e40a2ec8cb8875466ec1524872dd6
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release6a93e25585f487ddff9e3996c06d5b869d6e1828
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/795#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F795
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F795
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/795
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/795
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/795
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/issues/795
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 270 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 317 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
#2243https://github.com/modelcontextprotocol/python-sdk/pull/2243
#2959https://github.com/modelcontextprotocol/python-sdk/pull/2959
Support for API Gateway Path Prefixes in SSE Client URL Handlinghttps://github.com/modelcontextprotocol/python-sdk/issues/795#top
#2243https://github.com/modelcontextprotocol/python-sdk/pull/2243
#2959https://github.com/modelcontextprotocol/python-sdk/pull/2959
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%22
Mount / Routing questionshttps://github.com/modelcontextprotocol/python-sdk/milestone/23
https://github.com/lizzzcai
lizzzcaihttps://github.com/lizzzcai
on May 23, 2025https://github.com/modelcontextprotocol/python-sdk/issues/795#issue-3086877237
urlhttps://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py#L25
urljoinhttps://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py#L75
#412 (comment)https://github.com/modelcontextprotocol/python-sdk/issues/412#issuecomment-2820077952
#733https://github.com/modelcontextprotocol/python-sdk/issues/733
#386https://github.com/modelcontextprotocol/python-sdk/pull/386
P1Significant bug affecting many users, highly requested featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P1%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
ready for workEnough information for someone to start working onhttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22ready%20for%20work%22
Mount / Routing questionsNo due datehttps://github.com/modelcontextprotocol/python-sdk/milestone/23
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.