Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mcp-client-ruby/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def anthropic_client
rescue Interrupt
# Ctrl-C: stop without a backtrace; `ensure` still cleans up.
puts
exit 130
Comment thread
a-akimov marked this conversation as resolved.
Resolved
rescue => e
warn "Error: #{e.message}"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The fake API picks a script from the query text and checks every request the cli

Finally the client must exit 0 on `quit`. A client that does one tool round and stops, drops `tools` on the follow-up call, sends one `tool_result` per message, gets the turn cap wrong, drops what a tool returned, forgets the conversation, keeps a failed query or an empty reply, or ignores `stop_reason` passes the no-key test and fails this one.

A second run checks Ctrl-C: the helper starts the client in a process group of its own, sends `SIGINT` to the group at the `Query:` prompt, as a terminal does, and leaves stdin open. The client must exit within 15 seconds without printing a backtrace. `quit` and EOF are the clean exits, so the exit status isn't checked; a client that hangs on a blocked stdin read, or never reaches the prompt, fails here.
A second run checks Ctrl-C: the helper starts the client in a process group of its own, sends `SIGINT` to the group at the `Query:` prompt, as a terminal does, and leaves stdin open. The client must exit within 15 seconds, without printing a backtrace and with a non-zero status: `quit` and EOF are the clean exits, and Ctrl-C isn't one. A client that hangs on a blocked stdin read, never reaches the prompt, or exits 0 fails here.

All five clients are covered, including Rust: it calls the Messages API directly, so it honours `ANTHROPIC_BASE_URL` like the official SDKs do.

Expand Down
13 changes: 8 additions & 5 deletions tests/helpers/tool-loop-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
* here and passes the no-key test.
*
* A second client process checks that Ctrl-C at the prompt stops the client
* promptly and without a backtrace. `quit` and EOF are the clean exits; Ctrl-C
* only has to stop it, not hang on a blocked stdin read.
* promptly, non-zero and without a backtrace. `quit` and EOF are the clean
* exits; Ctrl-C only has to stop it, not hang on a blocked stdin read.
*
* Usage: node tool-loop-test.js <client command> [args...]
*/
Expand Down Expand Up @@ -593,8 +593,8 @@ function runClient(

/**
* Starts the client, sends SIGINT to its process group at the prompt, as a
* terminal's Ctrl-C does, and checks that it exits without a backtrace.
* stdin stays open.
* terminal's Ctrl-C does, and checks that it exits non-zero without a
* backtrace. stdin stays open.
*/
function runInterrupted(command: string, args: string[], baseUrl: string): Promise<void> {
return new Promise((resolve) => {
Expand Down Expand Up @@ -625,10 +625,13 @@ function runInterrupted(command: string, args: string[], baseUrl: string): Promi
}, INTERRUPT_TIMEOUT_MS);
});
child.stderr.on("data", (chunk) => (stderr += chunk));
child.on("close", () => {
child.on("close", (code, signal) => {
clearTimeout(startup);
clearTimeout(timer);
if (!timer) check(false, "Ctrl-C: client showed its prompt");
// Not 0: Ctrl-C isn't a clean exit. Clients exit 130 or die by SIGINT,
// but `uv run` reports a SIGINT death as 2.
check(code !== 0, `Ctrl-C: client exited non-zero (got ${signal ?? code})`);
// Python's traceback, or Ruby's uncaught `...: Interrupt`.
check(!/Traceback|KeyboardInterrupt|: Interrupt\b/.test(stderr), "Ctrl-C: client printed no backtrace");
resolve();
Expand Down
Loading