Title: MCPServer serves subscriptions/listen and advertises listChanged=true unconditionally — hold-open streams pin serverless invocations to the platform timeout · Issue #3493 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: MCPServer serves subscriptions/listen and advertises listChanged=true unconditionally — hold-open streams pin serverless invocations to the platform timeout · Issue #3493 · modelcontextprotocol/python-sdk
X Title: MCPServer serves subscriptions/listen and advertises listChanged=true unconditionally — hold-open streams pin serverless invocations to the platform timeout · Issue #3493 · modelcontextprotocol/python-sdk
Description: Summary MCPServer always registers the subscriptions/listen handler (on_subscriptions_listen=ListenHandler(self._subscriptions)), and Server.get_capabilities() derives tools/prompts/resources.listChanged = true and resources.subscribe = ...
Open Graph Description: Summary MCPServer always registers the subscriptions/listen handler (on_subscriptions_listen=ListenHandler(self._subscriptions)), and Server.get_capabilities() derives tools/prompts/resources.listC...
X Description: Summary MCPServer always registers the subscriptions/listen handler (on_subscriptions_listen=ListenHandler(self._subscriptions)), and Server.get_capabilities() derives tools/prompts/resources.listC...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3493
X: @github
Domain: redirect.github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MCPServer serves subscriptions/listen and advertises listChanged=true unconditionally — hold-open streams pin serverless invocations to the platform timeout","articleBody":"## Summary\n\n`MCPServer` always registers the `subscriptions/listen` handler (`on_subscriptions_listen=ListenHandler(self._subscriptions)`), and `Server.get_capabilities()` derives `tools/prompts/resources.listChanged = true` and `resources.subscribe = true` from the mere presence of that handler on the 2026-07-28 wire. A server that never publishes any change notification therefore advertises subscriptions, 2026-era clients open `subscriptions/listen`, and the response stream stays open until the client closes it (as specified).\n\nOn serverless HTTP platforms where a client disconnect does not propagate to the app (AWS Lambda Function URL with response streaming behind Lambda Web Adapter, in our case), every such stream pins one invocation until the platform timeout. There is no public way to opt out.\n\nThis is the same failure mode as #3492 (legacy GET stream), now on the modern wire.\n\n## Environment\n\n- mcp 2.1.1 (local reproduction) and 2.2.0 (production, same behaviour)\n- `MCPServer(...)` + `mcp.streamable_http_app(streamable_http_path=\"/\", stateless_http=True, transport_security=...)`, no `json_response`\n- uvicorn 0.52.4 (uvloop + httptools), sse-starlette 3.4.8, Python 3.12\n- AWS Lambda (container image, Function URL `RESPONSE_STREAM`, aws-lambda-web-adapter 0.9.1) — client disconnects never reach the ASGI app\n- Clients: TypeScript SDK based (auto-open listen on connect) and a hosted connector\n\n## Reproduction (no Lambda needed)\n\n```python\nimport asyncio, json\nfrom mcp.server.mcpserver import MCPServer\n\nmcp = MCPServer(\"demo\")\n\n@mcp.tool()\nasync def hello() -> str:\n return \"hi\"\n\nmcp.streamable_http_app(streamable_http_path=\"/\", stateless_http=True)\nsm = mcp.session_manager\n\nMETA = {\"io.modelcontextprotocol/protocolVersion\": \"2026-07-28\",\n \"io.modelcontextprotocol/clientInfo\": {\"name\": \"probe\", \"version\": \"1\"},\n \"io.modelcontextprotocol/clientCapabilities\": {}}\n\ndef scope(body, method):\n return {\"type\": \"http\", \"http_version\": \"1.1\", \"method\": \"POST\", \"scheme\": \"http\", \"path\": \"/\",\n \"raw_path\": b\"/\", \"query_string\": b\"\", \"server\": (\"localhost\", 3000), \"client\": (\"127.0.0.1\", 1),\n \"headers\": [(b\"host\", b\"localhost\"), (b\"accept\", b\"application/json, text/event-stream\"),\n (b\"content-type\", b\"application/json\"), (b\"content-length\", str(len(body)).encode()),\n (b\"mcp-protocol-version\", b\"2026-07-28\"), (b\"mcp-method\", method.encode())]}\n\nasync def post(msg, timeout=3):\n body = json.dumps(msg).encode(); got = False\n async def receive():\n nonlocal got\n if not got:\n got = True\n return {\"type\": \"http.request\", \"body\": body, \"more_body\": False}\n await asyncio.sleep(3600) # like Lambda: no http.disconnect ever arrives\n events, done = [], asyncio.Event()\n async def send(m):\n events.append(m)\n if m[\"type\"] == \"http.response.body\" and not m.get(\"more_body\", False):\n done.set()\n task = asyncio.create_task(sm.handle_request(scope(body, msg[\"method\"]), receive, send))\n try:\n await asyncio.wait_for(done.wait(), timeout); print(msg[\"method\"], \"completed\")\n except asyncio.TimeoutError:\n print(msg[\"method\"], \"STILL OPEN after\", timeout, \"s\")\n print(\" \", b\"\".join(e.get(\"body\", b\"\") for e in events if e[\"type\"] == \"http.response.body\")[:200])\n task.cancel()\n\nasync def main():\n async with sm.run():\n await post({\"jsonrpc\": \"2.0\", \"id\": \"d1\", \"method\": \"server/discover\", \"params\": {\"_meta\": META}})\n await post({\"jsonrpc\": \"2.0\", \"id\": \"listen:1\", \"method\": \"subscriptions/listen\",\n \"params\": {\"_meta\": META, \"notifications\": {\"toolsListChanged\": True}}})\n\nasyncio.run(main())\n```\n\nOutput:\n\n```\nserver/discover completed\n {\"jsonrpc\":\"2.0\",\"id\":\"d1\",\"result\":{\"cacheScope\":\"private\",\"capabilities\":{\"prompts\":{\"listChanged\":true},\"resources\":{\"listChanged\":true,\"subscribe\":true},\"tools\":{\"listChanged\":true}}, ...\nsubscriptions/listen STILL OPEN after 3 s\n event: message\\r\\ndata: {\"jsonrpc\":\"2.0\",\"method\":\"notifications/subscriptions/acknowledged\",\"params\":{\"_meta\":{\"io.modelcontextprotocol/subscriptionId\":\"listen:1\"},\"notifications\":{\"toolsListChanged\":true}}}\n```\n\nThe server has nothing it could ever publish, yet it advertises `listChanged: true` and holds the listen stream open.\n\n## Impact observed in production\n\nAfter migrating from mcp 1.29 (FastMCP) to 2.x, the only method that never completed was `subscriptions/listen`: in a 30-minute sample, 19 of 19 listen POSTs were still unanswered after 60 s while every other method (tools/call, tools/list, prompts/list, resources/list, server/discover, initialize) completed in milliseconds. Each open stream ran to the Lambda timeout (900 s); ~1,300–1,800 such invocations per day accounted for 99% of the function's billed GB-seconds. Clients re-sent the listen request immediately after each timeout, so the streams were permanently occupied.\n\n## Current workaround\n\n```python\nmcp._lowlevel_server._request_handlers.pop(\"subscriptions/listen\")\n```\n\nWith the handler gone, `get_capabilities()` reports `listChanged: false / subscribe: false`, and a listen POST gets the SDK's standard `404` + JSON-RPC `-32601`, which the TypeScript client treats as a soft error (\"a failed auto-open MUST NOT fail connect\"). It works, but it depends on two private attributes.\n\n## Request\n\nA public way to run a server without `subscriptions/listen`, for example `MCPServer(subscriptions=None)` meaning \"not served\" (today `None` means \"use the in-memory bus\"), or an explicit `listen=False` / `serve_subscriptions=False` flag — and have `get_capabilities()` derive `listChanged=false` from it, as it already does from handler presence. Alternatively, a documented guidance for stateless/serverless deployments.\n\nThanks for the SDK — the 2.x transport is otherwise working well for us.\n","author":{"url":"https://github.com/tomoki-takahashi-oisix","@type":"Person","name":"tomoki-takahashi-oisix"},"datePublished":"2026-09-11T12:08:24Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3493"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:a7a78d6b-dbfc-949b-2de5-0fb23ba794ea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DCA8:3B6A24:F80A5D:153DE21:6B055D27 |
| html-safe-nonce | 67f9eba45f12dd84366b01c8ea5aafed2b6b55de5b7e3d50494ca9e9bca77d1d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0E4OjNCNkEyNDpGODBBNUQ6MTUzREUyMTo2QjA1NUQyNyIsInZpc2l0b3JfaWQiOiIxNzg1Njc5MTUyNDIzNDYwMTM1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 16a6217b930834a17cea8d5d5e63414c469eaa2060f5ef4513089f62fda7ef92 |
| hovercard-subject-tag | issue:5424111684 |
| 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/3493/issue_layout |
| twitter:image | https://opengraph.githubassets.com/77b0385d40e9fca361998eeb7900694925f1110b837029553cfdbca20fdbe4e8/modelcontextprotocol/python-sdk/issues/3493 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/77b0385d40e9fca361998eeb7900694925f1110b837029553cfdbca20fdbe4e8/modelcontextprotocol/python-sdk/issues/3493 |
| og:image:alt | Summary MCPServer always registers the subscriptions/listen handler (on_subscriptions_listen=ListenHandler(self._subscriptions)), and Server.get_capabilities() derives tools/prompts/resources.listC... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tomoki-takahashi-oisix |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8a6760da3cce5e2d079d07e3b62df71194316c4478db1a5e38050f44fce72c72 |
| 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 | 8327739ac0648b9c3c722b5f401f7338553936b8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width