Title: sse_app() ignores mount prefix, resulting in 404 from client · Issue #412 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: sse_app() ignores mount prefix, resulting in 404 from client · Issue #412 · modelcontextprotocol/python-sdk
X Title: sse_app() ignores mount prefix, resulting in 404 from client · Issue #412 · modelcontextprotocol/python-sdk
Description: Describe the bug When mounting sse_app() from FastMCP with a URL prefix using Starlette’s Mount, the SSE stream still returns the default /messages/ endpoint without the prefix. This causes the MCP client to resolve an incorrect URL (e.g...
Open Graph Description: Describe the bug When mounting sse_app() from FastMCP with a URL prefix using Starlette’s Mount, the SSE stream still returns the default /messages/ endpoint without the prefix. This causes the MCP...
X Description: Describe the bug When mounting sse_app() from FastMCP with a URL prefix using Starlette’s Mount, the SSE stream still returns the default /messages/ endpoint without the prefix. This causes the MCP...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/412
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"sse_app() ignores mount prefix, resulting in 404 from client","articleBody":"**Describe the bug**\n\nWhen mounting sse_app() from FastMCP with a URL prefix using Starlette’s Mount, the SSE stream still returns the default /messages/ endpoint without the prefix. This causes the MCP client to resolve an incorrect URL (e.g., /messages/ instead of /mcp/messages/), resulting in a 404 error.\n\n**To Reproduce**\n\nSteps to reproduce the behavior:\n\n1. Define an MCP server as below:\n\n```python\nfrom mcp.server.fastmcp import FastMCP\nfrom starlette.applications import Starlette\nfrom starlette.routing import Mount\n\nmcp = FastMCP(\n # sse_path=\"/sse\", # default\n # message_path=\"/messages/\", # default\n)\n\n\napplication = Starlette(\n routes=[\n Mount(\"/mcp\", app=mcp.sse_app()), # HERE !!!\n ]\n)\n```\n\n2. Start the server and navigate to http://127.0.0.1:8000/mcp/sse in your browser\n3. Observe the response in the browser. You will receive an SSE event like:\n\n```\nevent: endpoint\ndata: /messages/?session_id=...\n```\n\nAt this point, the MCP client performs a `urljoin` operation between the SSE URL (http://127.0.0.1:8000/mcp/sse) and the endpoint path (/messages/). This causes the resolved endpoint URL to become http://127.0.0.1:8000/messages/.\n\n4. The client tries to connect to http://127.0.0.1:8000/messages/, which results in a 404.\n\n**Expected behavior**\n\nThe SSE stream should return the correct full path reflecting the prefix, e.g.:\n\n```\ndata: /mcp/messages/?session_id=...\n```\n\nThis would allow the client to connect to the actual valid message endpoint.\n\n**Screenshots**\nIf applicable, add screenshots to help explain your problem.\n\n**Desktop (please complete the following information):**\n\n - OS: macOS\n - Browser : Arc\n - Version : 1.87.1 (60573)\n\n**Smartphone (please complete the following information):**\n - Device: N/A\n - OS: N/A\n - Browser : N/A\n - Version : N/A\n\n**Additional context**\n\nThis behavior seems to originate from hardcoded endpoint generation inside sse_app():\n\nhttps://github.com/modelcontextprotocol/python-sdk/blob/c2ca8e03e046908935d089a2ceed4e80b0c29a24/src/mcp/server/sse.py#L98\n\nIt would be great to have support for specifying a prefix in sse_app() or for the prefix to be auto-detected from the ASGI scope.\n\nThank you!","author":{"url":"https://github.com/allieus","@type":"Person","name":"allieus"},"datePublished":"2025-04-02T16:00:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/412/python-sdk/issues/412"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6ceec25c-56fb-1568-13d2-a16af62b07aa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8844:211BBA:41CF85:5A9FBD:6A62986B |
| html-safe-nonce | 87c49b641634766a76425ee84331206243d132256517ed6667f7e4bde3fba8af |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODQ0OjIxMUJCQTo0MUNGODU6NUE5RkJEOjZBNjI5ODZCIiwidmlzaXRvcl9pZCI6IjMxMDI3MDUzODczOTUyNTg0NzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3ee63d43b7067e392d92d3238d4cd2b93ced7dd706e9a19b9337a302442f16dc |
| hovercard-subject-tag | issue:2966900247 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/modelcontextprotocol/python-sdk/412/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e637629cc6490ac69457c8b25730e515217cac90e458a6c092b52f343e661ce1/modelcontextprotocol/python-sdk/issues/412 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e637629cc6490ac69457c8b25730e515217cac90e458a6c092b52f343e661ce1/modelcontextprotocol/python-sdk/issues/412 |
| og:image:alt | Describe the bug When mounting sse_app() from FastMCP with a URL prefix using Starlette’s Mount, the SSE stream still returns the default /messages/ endpoint without the prefix. This causes the MCP... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | allieus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 10ffaff7e212112a3b4eeb224665f909dff951514db9af4f00de33b681024427 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e470e2fc66e1ac7f528caec0fd8825047788d563 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width