Skip to content

fix: exit stdio server cleanly on interrupt#2745

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-keyboardinterrupt-clean-exit-v2
Open

fix: exit stdio server cleanly on interrupt#2745
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-keyboardinterrupt-clean-exit-v2

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • catch KeyboardInterrupt at the synchronous MCPServer.run() boundary
  • keep normal transport errors unchanged
  • add a regression test for the stdio branch so Ctrl-C exits without re-raising through AnyIO

To verify

  • .\.venv\Scripts\python.exe -m pytest tests\server\mcpserver\test_server.py::TestServer::test_stdio_keyboard_interrupt_exits_cleanly -q
  • .\.venv\Scripts\python.exe -m ruff check src\mcp\server\mcpserver\server.py tests\server\mcpserver\test_server.py
  • .\.venv\Scripts\python.exe -m ruff format --check src\mcp\server\mcpserver\server.py tests\server\mcpserver\test_server.py
  • .\.venv\Scripts\pyright.exe src\mcp\server\mcpserver\server.py tests\server\mcpserver\test_server.py
  • git diff --check

Refs #2663

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.

1 participant