Skip to content

fix: suppress MCPServer KeyboardInterrupt tracebacks#2813

Open
he-yufeng wants to merge 3 commits into
modelcontextprotocol:mainfrom
he-yufeng:fix/mcpserver-keyboardinterrupt
Open

fix: suppress MCPServer KeyboardInterrupt tracebacks#2813
he-yufeng wants to merge 3 commits into
modelcontextprotocol:mainfrom
he-yufeng:fix/mcpserver-keyboardinterrupt

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • suppress KeyboardInterrupt at the synchronous MCPServer.run() boundary
  • cover stdio, sse, and streamable-http dispatch paths with a focused regression test

Closes #2663.

To verify

  • uv run --frozen pytest tests/server/mcpserver/test_server.py::TestServer::test_run_suppresses_keyboard_interrupt -q
  • uv run --frozen pytest tests/server/mcpserver/test_server.py -q
  • uv run --frozen ruff check src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_server.py
  • uv run --frozen pyright src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_server.py
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FastMCP.run(transport="stdio") produces noisy traceback on KeyboardInterrupt instead of clean exit

1 participant