Title: **Memory Leak** in MCP Server – will be a memory leak until OOM (Out of Memory) occurs · Issue #1076 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: **Memory Leak** in MCP Server – will be a memory leak until OOM (Out of Memory) occurs · Issue #1076 · modelcontextprotocol/python-sdk
X Title: **Memory Leak** in MCP Server – will be a memory leak until OOM (Out of Memory) occurs · Issue #1076 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description As part of our usage o...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1076
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"**Memory Leak** in MCP Server – will be a memory leak until OOM (Out of Memory) occurs","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\nAs part of our usage of FastMCP and Python MCP SDK, we observed a memory leak in the MCP server. When the client continuously calls a simple tool (e.g., a greet function), the server's memory usage steadily increases over time and does not get released, eventually leading to an Out of Memory (OOM) condition.\n\nThis issue is reproducible both in the fastmcp library and the MCP SDK.\n\n### Issue\nHere is the Logs:Memory will keep increasing\n[memory_log_pythonmcp.txt](https://github.com/user-attachments/files/21033314/memory_log_pythonmcp.txt)\n\n### Example Code\n\n```Python\nServer.py\n----------------------------------------------------\nfrom mcp.server.fastmcp import FastMCP\n\n# Create an MCP server\nmcp = FastMCP(\"Demo Server\")\n\n# Add a simple tool\n@mcp.tool()\ndef greet(name: str) -\u003e str:\n \"\"\"Return a greeting message.\"\"\"\n return f\"Hello, {name}!\"\n\nif __name__ == \"__main__\":\n # Run the server with streamable HTTP transport\n mcp.run(transport=\"streamable-http\")\n\n--------------------------------------------------\nclient.py((with a while loop)\n---------------------------------------------------\nimport asyncio\nfrom mcp.client.streamable_http import streamablehttp_client\nfrom mcp.client.session import ClientSession\n\nasync def call_tool(name: str):\n # Connect to the MCP server using streamable HTTP\n async with streamablehttp_client(\"http://127.0.0.1:8000/mcp\") as (read, write, _):\n async with ClientSession(read, write) as session:\n # Initialize the connection\n await session.initialize()\n # Call the 'greet' tool\n result = await session.call_tool(\"greet\", {\"name\": name})\n print(result)\n\nasync def main():\n while True:\n await call_tool(\"Bob\")\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n--------------------------------------------\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\nEnvironment:\n\nPython: 3.12.1\n\nMCP Python SDK: 1.10.1\n```","author":{"url":"https://github.com/MadanMaram","@type":"Person","name":"MadanMaram"},"datePublished":"2025-07-03T08:39:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1076/python-sdk/issues/1076"}
| 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:479ad939-ca83-88bf-696b-9ca2e9e55442 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3E8:1A4414:8EACD6:CBD761:6A59EDD6 |
| html-safe-nonce | f2f0a3ddc65b575201778f7b625ada30a5463226faa1227509bb94cc8eef6393 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0U4OjFBNDQxNDo4RUFDRDY6Q0JENzYxOjZBNTlFREQ2IiwidmlzaXRvcl9pZCI6IjIxMjUwOTUxNDA2MTY0MzMxMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 145005c82221788aaae5a65b0bcaa7cafe08a97c75edd067386e5daa32e7d3e2 |
| hovercard-subject-tag | issue:3198559977 |
| 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/1076/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f8760ecffe746cef3029f34e25fd2565ae3bff867c04ade2676772c08e2d421e/modelcontextprotocol/python-sdk/issues/1076 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f8760ecffe746cef3029f34e25fd2565ae3bff867c04ade2676772c08e2d421e/modelcontextprotocol/python-sdk/issues/1076 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MadanMaram |
| hostname | github.com |
| expected-hostname | github.com |
| None | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| 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 | 32bf0b7849e1b6561059cca2cb03568251960859 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width