Repository navigation
Description
Problem
The five clients each react to Ctrl-C in a different way. This was the last open task in #269, which asked for cleanup on Ctrl-C in Go, Rust and Ruby and assumed Python and TypeScript already handled it. They don't: Python hangs at the prompt, and TypeScript waits out a pending query.
Behavior on main (d084a4b), checked by starting each client against a stdio server, waiting for the Query: prompt, and sending SIGINT with stdin left open. A second case sent SIGINT while the API request for a query was still pending. Ruby is described from the code; it wasn't run.
| Client | Ctrl-C at the prompt | Ctrl-C during a query | Cleanup runs? |
|---|---|---|---|
| Python | Prints a KeyboardInterrupt traceback, then hangs until Enter or Ctrl-D, because Python waits at exit for the thread blocked in input() |
Exits with status 130 and a KeyboardInterrupt traceback |
Not reliably: on Python 3.11+, the cancellation also cancels cleanup's own awaits |
| TypeScript | Exits cleanly with status 0 | Waits for the pending reply, then exits 0; a second Ctrl-C kills it at once | Yes |
| Go | Exits at once with status 130 | Same | No |
| Rust | Exits at once with status 130 | Same | No |
| Ruby | ensure runs cleanup, then Ruby prints the Interrupt backtrace and exits non-zero |
Same | Yes |
Where this comes from in the code:
mcp-client-python/client.py:184-185reads input withasyncio.to_thread(input, ...)and catchesKeyboardInterrupt, but underasyncio.run(line 233) Ctrl-C doesn't arrive there, and the worker thread stays blocked ininput().mcp-client-typescript/index.ts:230-235closes readline on SIGINT, which ends the loop at the prompt but doesn't abort a request in flight.mcp-client-go/main.goandmcp-client-rust/src/main.rsinstall no handler, so the default SIGINT action ends the process beforeCleanup()/cleanup()runs.mcp-client-ruby/client.rb:231-249cleans up inensure, butrescue => edoesn't catchInterrupt, which isn't aStandardError.
In practice no server is left running in any client: in a terminal Ctrl-C reaches the server too, and a stdio server exits when its stdin closes. So the visible differences are hangs, backtraces and exit status, not leaked processes.
Decision needed
How much Ctrl-C handling belongs in a quickstart. AGENTS.md asks to leave out code that only makes an example more robust, and quit and Ctrl-D already exit cleanly in all five clients.
- Option A, clean shutdown on Ctrl-C everywhere: every client catches Ctrl-C at the prompt and during a query, closes the session and exits 0. Draft PR Clean up on Ctrl-C in the Go, Rust and Ruby clients #300 implements this and extends the tool-loop test to check it. It works, but it costs about 230 lines across the clients and tests, including asyncio internals in Python (
Task.uncancel(),os._exit), a stdin goroutine andsignal.NotifyContextin Go,tokio::select!plusprocess::exitin Rust, and an abort signal passed through TypeScript's query code. Much of that sits in code the tutorials quote. - Option B,
quitand Ctrl-D are the clean exit, Ctrl-C just stops the client: fix only what's broken, the Python hang and the Ruby backtrace, leave the default behavior elsewhere, and say in each README thatquitor Ctrl-D exits cleanly and Ctrl-C stops the client at once. This is a few lines per client, plus a test that Ctrl-C at the prompt ends the client promptly.
Option A
- Review and merge Clean up on Ctrl-C in the Go, Rust and Ruby clients #300.
Option B
- Python: restore the default SIGINT handler before
asyncio.run(main()), so Ctrl-C exits at once instead of hanging, and dropKeyboardInterruptfrom theexceptaroundinput(). - Ruby: rescue
Interruptnext torescue => e, so Ctrl-C exits without a backtrace (ensurestill cleans up). - TypeScript: decide whether Ctrl-C during a query should stop the client at once (drop the SIGINT handler, or abort the request) or keep waiting for the reply, and document whichever it is.
- Say in every client README that
quitor Ctrl-D exits and shuts the server down cleanly, and what Ctrl-C does. - Extend
tests/helpers/tool-loop-test.tsto send SIGINT to the client's process group at the prompt, with stdin left open, and fail if the client doesn't exit within a few seconds.
Acceptance criteria
- All five clients do the same thing on Ctrl-C, at the prompt and during a query, and their READMEs say what that is.
- No client hangs after Ctrl-C or prints a backtrace.
- The tool-loop test fails if a client stops behaving that way.
Activity
olaservo commentedon Nov 15, 2026
Decision: Option B. #302 is merged, so
quitand Ctrl-D are the clean exits in all five clients, Ctrl-C stops the client at once, every README says so, and the tool-loop test checks that Ctrl-C at the prompt ends the client without a hang or a backtrace. #300 can be closed.One small follow-up if you want the five fully alike: Ruby exits 0 after Ctrl-C while the other four exit 130.
Generated by Claude Code
a-akimov commentedon Nov 16, 2026
Thank you, @olaservo. Created #303 as a follow up on Ruby.