You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
**Memory Leak** in MCP Server – will be a memory leak until OOM (Out of Memory) occurs #1076
As 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.
This issue is reproducible both in the fastmcp library and the MCP SDK.
Server.py----------------------------------------------------frommcp.server.fastmcpimportFastMCP# Create an MCP servermcp=FastMCP("Demo Server")
# Add a simple tool@mcp.tool()defgreet(name: str) ->str:
"""Return a greeting message."""returnf"Hello, {name}!"if__name__=="__main__":
# Run the server with streamable HTTP transportmcp.run(transport="streamable-http")
--------------------------------------------------client.py((withawhileloop)
---------------------------------------------------importasynciofrommcp.client.streamable_httpimportstreamablehttp_clientfrommcp.client.sessionimportClientSessionasyncdefcall_tool(name: str):
# Connect to the MCP server using streamable HTTPasyncwithstreamablehttp_client("http://127.0.0.1:8000/mcp") as (read, write, _):
asyncwithClientSession(read, write) assession:
# Initialize the connectionawaitsession.initialize()
# Call the 'greet' toolresult=awaitsession.call_tool("greet", {"name": name})
print(result)
asyncdefmain():
whileTrue:
awaitcall_tool("Bob")
if__name__=="__main__":
asyncio.run(main())
--------------------------------------------
Activity
Kludex commentedon Jul 6, 2025
Your text file doesn't show a leak, it just shows the memory increased.
Closing this issue, since I couldn't visualize the leak with
memray.