Skip to content

fix: exit cleanly on stdio KeyboardInterrupt#2671

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

fix: exit cleanly on stdio KeyboardInterrupt#2671
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-keyboardinterrupt-clean-exit

Conversation

@he-yufeng
Copy link
Copy Markdown

Fixes #2663. Handles Ctrl-C for FastMCP stdio runs at the stdio transport boundary so shutdown does not print a traceback. HTTP transports keep their existing behavior. Validation: uv run pytest tests\server\mcpserver\test_server.py::TestServer::test_run_stdio_exits_cleanly_on_keyboard_interrupt -q; uv run pytest tests\server\mcpserver\test_server.py -q; uv run python -m py_compile src\mcp\server\mcpserver\server.py tests\server\mcpserver\test_server.py; uv run ruff check src\mcp\server\mcpserver\server.py tests\server\mcpserver\test_server.py; uv run ruff format --check src\mcp\server\mcpserver\server.py tests\server\mcpserver\test_server.py; git diff --check.

@he-yufeng he-yufeng force-pushed the fix/stdio-keyboardinterrupt-clean-exit branch from c4dc40b to 58f2d2a Compare May 29, 2026 19:48
@he-yufeng
Copy link
Copy Markdown
Author

Closing this older stdio-only version in favor of #2745, which covers the same issue with the broader transport-level guard and the follow-up CI fixes. Keeping only one active PR for this topic.

@he-yufeng he-yufeng closed this Jun 5, 2026
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