Title: Stateless Mode memory leak · Issue #756 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Stateless Mode memory leak · Issue #756 · modelcontextprotocol/python-sdk
X Title: Stateless Mode memory leak · Issue #756 · modelcontextprotocol/python-sdk
Description: Describe the bug Stateless mode with Streamable-HTTP leaks memory. The StreamableHTTPSessionManager stateless server task group never exits and the _task list grows with each request leading to always increasing memory usage. Expected be...
Open Graph Description: Describe the bug Stateless mode with Streamable-HTTP leaks memory. The StreamableHTTPSessionManager stateless server task group never exits and the _task list grows with each request leading to alw...
X Description: Describe the bug Stateless mode with Streamable-HTTP leaks memory. The StreamableHTTPSessionManager stateless server task group never exits and the _task list grows with each request leading to alw...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/756
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Stateless Mode memory leak","articleBody":"**Describe the bug**\nStateless mode with Streamable-HTTP leaks memory. The `StreamableHTTPSessionManager` stateless server task group never exits and the `_task` list grows with each request leading to always increasing memory usage. \n\n**Expected behavior**\nStateless server exits after handling the request freeing up the resources\n\n**Steps to reproduce**\n1. Create minimal MCP server:\n```python\nfrom mcp.server.fastmcp import FastMCP\n\nmcp = FastMCP(\"StatelessServer\", stateless_http=True)\n\n\n@mcp.tool()\ndef task_size() -\u003e int:\n return len(mcp.session_manager._task_group._tasks)\n\n\nif __name__ == \"__main__\":\n mcp.run(transport=\"streamable-http\")\n\n```\n2. Create minimal MCP client:\n```python\nimport asyncio\n\nfrom fastmcp import Client\nfrom fastmcp.client.transports import StreamableHttpTransport\nfrom mcp.types import CallToolResult\n\nasync def execute_mcp_tool_call():\n transport = StreamableHttpTransport(\"http://localhost:8000/mcp/\")\n\n async with Client(transport) as client:\n tools = await client.list_tools()\n print(tools)\n\n result = await client.call_tool(\"task_size\")\n print(result)\n\n\nasyncio.run(execute_mcp_tool_call())\n```\n3. Do multiple requests\n4. Tool will return the size of pending tasks in session manager task group and it is always increasing:\n```\n[TextContent(type='text', text='23', annotations=None)]\n[TextContent(type='text', text='27', annotations=None)]\n[TextContent(type='text', text='31', annotations=None)]\n```","author":{"url":"https://github.com/algirdasci","@type":"Person","name":"algirdasci"},"datePublished":"2025-05-19T17:00:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/756/python-sdk/issues/756"}
| 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:de56a9f0-7ddd-cca9-c362-651b48b786c6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBD2:23E36B:D2EBD0:12E72D6:6A59FE7A |
| html-safe-nonce | 976e571d782526ded4ecbbe8a2ee0f7429a86246de24e85563222c1174749091 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkQyOjIzRTM2QjpEMkVCRDA6MTJFNzJENjo2QTU5RkU3QSIsInZpc2l0b3JfaWQiOiI3NTQ5OTY2Nzc3NjkyMzIzNDUwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ea6506a9d90e7c24112fa7a505779617e564dab801c54e3fc2bb8aecffae95b6 |
| hovercard-subject-tag | issue:3074488474 |
| 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/756/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6935c62ac127d97023a3f271156b05b519efd9c2e2651851ff61a8b536bc5937/modelcontextprotocol/python-sdk/issues/756 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6935c62ac127d97023a3f271156b05b519efd9c2e2651851ff61a8b536bc5937/modelcontextprotocol/python-sdk/issues/756 |
| og:image:alt | Describe the bug Stateless mode with Streamable-HTTP leaks memory. The StreamableHTTPSessionManager stateless server task group never exits and the _task list grows with each request leading to alw... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | algirdasci |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3f961cfc83a4348ee5be7691cf4ae3515aab3ef5200c13a7e41b048125fb61 |
| 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 | ac4d28603af300ac851b62521abb878ab5d3319a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width