-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Disconnecting an MCP server causes a CPU core to get stuck at 100% #2182
Copy link
Copy link
Closed
Labels
backendPertains to the Python backend.Pertains to the Python backend.bugSomething isn't workingSomething isn't workingneeds-triagestaleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closedIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed
Description
Describe the bug
When connecting to an MCP server and then disconnecting it, a thread consumes 100% of a cpu core.
To Reproduce
Steps to reproduce the behavior:
Run the minimal script below:
import chainlit as cl
from mcp import ClientSession
@cl.on_chat_start
async def chat_start():
await cl.Message(content="hello world").send()
@cl.on_mcp_connect
async def mcp_connect(connection, session: ClientSession):
tools = await session.list_tools()
print(f"connect mcp: {tools}")- Access the chat window.
- Add an MCP server.
- Disconnect from the MCP server.
After disconnecting, one CPU core gets stuck at 100% utilization due to an async thread.
I found that except Exception: pass in disconnect_mcp() hides an exception Attempted to exit cancel scope in a different task than it was entered in, which may causes the issue, I think.
ref: modelcontextprotocol/python-sdk#521
Expected behavior
The MCP server should disconnect properly (without exhausting a CPU core).
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
I ran chainlit==2.5.5 with mcp==1.9.0 on ubuntu 24.04.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
backendPertains to the Python backend.Pertains to the Python backend.bugSomething isn't workingSomething isn't workingneeds-triagestaleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closedIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed