From 916e12490004fbc1164c33734f9f44dc784bb03d Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 3 Nov 2026 17:04:54 +0100 Subject: [PATCH 1/2] fix(mcp): list the MCP server's own probe and close the list_probes client list_probes only relayed the agent's list of detached probes, so it returned nothing while this server's own probe was running, and "check that no probe is left" proved nothing. It now reports the session this server holds (running, exited or connection lost) next to the detached probes. The handler also never closed the client it opened, and its 10 s wait started only after the blocking listProbes call returned, so an agent that never answered hung the request. The call now runs under the timeout and the client is closed on every path. Verified: ./gradlew check 55 tests, 0 failures; e2eTest against a current btrace build - McpServerE2ETest 13/13, McpLostConnectionE2ETest 2/2; validate-marketplace and check-tool-references pass. Co-Authored-By: Claude Opus 5.5 --- .../java/io/btrace/mcp/McpServerE2ETest.java | 8 ++ .../btrace/mcp/tools/ListProbesHandler.java | 101 ++++++++++++++---- .../test/java/io/btrace/client/Client.java | 6 ++ .../java/io/btrace/mcp/ToolHandlersTest.java | 2 +- .../mcp/tools/ListProbesHandlerTest.java | 96 +++++++++++++++++ .../skills/btrace-mcp-operations/SKILL.md | 6 +- 6 files changed, 197 insertions(+), 22 deletions(-) create mode 100644 plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java diff --git a/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java b/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java index 64f8de1..0316550 100644 --- a/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java +++ b/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java @@ -152,6 +152,11 @@ void deployScriptInstrumentsTheTarget() throws Exception { assertSuccess(result); assertTrue(text(result).contains("Script deployed successfully to PID " + pid)); awaitCounter(RUNNING_PROBE, "processCalls", calls -> calls > 0); + + // The agent lists only detached probes; list_probes must still show the one this server holds. + String listed = text(tool("list_probes")); + assertTrue(listed.contains("Connected through this MCP server: a probe on port"), listed); + assertFalse(listed.contains(RUNNING_PROBE), "a connected probe is listed as detached:\n" + listed); } @Test @@ -242,6 +247,9 @@ void listProbesReportsTheRunningProbe() throws Exception { Map result = tool("list_probes"); assertSuccess(result); assertTrue(text(result).contains(RUNNING_PROBE)); + assertTrue( + text(result).contains("Connected through this MCP server: none"), + "the detached probe is not this server's session:\n" + text(result)); assertTrue(server.isAlive(), "list_probes terminated the MCP server"); } diff --git a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java index 5d550ad..ae9c516 100644 --- a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java +++ b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java @@ -18,17 +18,23 @@ import io.btrace.mcp.BTraceClient; import io.btrace.mcp.ClientManager; -import java.io.StringWriter; +import io.btrace.mcp.ProbeOutput; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Handles the list_probes MCP tool - lists active probes on a JVM. */ +/** + * Handles the list_probes MCP tool. The agent lists only probes no client is connected to, so the + * probe this server's own session holds is reported from {@link ClientManager}. A probe another + * client (a btrace CLI, another MCP server) is connected to appears in neither list. + */ public final class ListProbesHandler { private static final Logger log = LoggerFactory.getLogger(ListProbesHandler.class); private static final int DEFAULT_PORT = 2020; @@ -40,7 +46,10 @@ private ListProbesHandler() {} public static Map schema() { Map tool = new LinkedHashMap<>(); tool.put("name", "list_probes"); - tool.put("description", "List detached probes available to reconnect."); + tool.put( + "description", + "List the probe this server is connected to on a JVM and the detached probes still running" + + " there. Probes connected through another client are not listed."); Map properties = new LinkedHashMap<>(); @@ -67,6 +76,10 @@ public static Map schema() { /** Executes the list_probes tool. */ public static Map execute(Map arguments) { + return execute(arguments, TimeUnit.SECONDS.toMillis(TIMEOUT_SECONDS)); + } + + static Map execute(Map arguments, long timeoutMillis) { String pid = getStringArg(arguments, "pid"); int port = getIntArg(arguments, "port", DEFAULT_PORT); @@ -74,33 +87,83 @@ public static Map execute(Map arguments) { return toolResult("Error: 'pid' parameter is required", true); } + // Read before listing: a lost session is forgotten once list_probes has shown its probe. + String connected = connectedSession(pid); + BTraceClient client = null; try { - BTraceClient client = ClientManager.getClient(port); + client = ClientManager.getClient(port); client.attach(pid, null, "."); StringBuilder output = new StringBuilder(); - CountDownLatch latch = new CountDownLatch(1); - - client.listProbes( - "localhost", - cmd -> { - output.append(client.printableText(cmd)); - if (client.commandType(cmd) == client.commandConstant("LIST_PROBES")) { - latch.countDown(); - } - }); - - boolean done = latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS); - if (!done) { + BTraceClient lister = client; + // The client reads the reply with no timeout; never let an agent that does not answer block + // the request. + FutureTask list = + new FutureTask<>( + () -> { + lister.listProbes( + "localhost", cmd -> output.append(lister.printableText(cmd))); + return null; + }); + Thread listerThread = new Thread(list, "btrace-list-probes-" + pid); + listerThread.setDaemon(true); + listerThread.start(); + try { + list.get(timeoutMillis, TimeUnit.MILLISECONDS); + } catch (TimeoutException e) { return toolResult("Timed out waiting for probe list from PID " + pid, true); + } catch (ExecutionException e) { + throw e.getCause() instanceof Exception ? (Exception) e.getCause() : e; } ClientManager.forgetLostSession(pid); - String resultText = "Active probes on PID " + pid + ":\n" + output.toString(); + String detached = output.toString().trim(); + String resultText = + "Probes on PID " + + pid + + ":\n" + + "Connected through this MCP server: " + + connected + + "\n" + + "Detached (stop with stop_detached_probe): " + + (detached.isEmpty() ? "none" : "\n" + detached) + + "\n" + + "Probes connected through another client (a btrace CLI or another MCP server) are" + + " not listed."; return toolResult(resultText, false); } catch (Exception e) { log.error("Failed to list probes", e); return toolResult("Error listing probes on PID " + pid + ": " + e.getMessage(), true); + } finally { + closeQuietly(client); + } + } + + /** Describes this server's session on the PID, which the agent's list does not include. */ + private static String connectedSession(String pid) { + int port = ClientManager.sessionPort(pid); + if (port < 0) { + return "none"; + } + ProbeOutput output = ClientManager.getOutput(pid, port); + if (output == null || !output.isFinished()) { + return "a probe on port " + port + " (stop with exit_probe)"; + } + return output.hasExited() + ? "none (the probe on port " + port + " exited)" + : "none (the connection to the probe on port " + + port + + " was lost; if it is still running, it is listed as detached)"; + } + + private static void closeQuietly(BTraceClient client) { + if (client == null) { + return; + } + try { + client.close(); + } catch (Exception e) { + log.debug("Failed to close the list_probes client", e); } } diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java index a6eb97a..75d1f0c 100644 --- a/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java @@ -17,6 +17,8 @@ public class Client { public static String exitOutput = ""; public static boolean failAttach = false; public static boolean ignoreExit = false; + /** An agent that never answers a probe list request: only closing the client ends the wait. */ + public static boolean hangListProbes = false; public final int port; public String attachedPid; public int exitCode; @@ -78,6 +80,10 @@ public void submit( } public void connectAndListProbes(String host, CommandListener listener) throws Exception { + if (hangListProbes) { + closeLatch.await(); + return; + } listener.onCommand(new FakePrintableCommand(Command.LIST_PROBES, host)); } diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/ToolHandlersTest.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/ToolHandlersTest.java index 79d78e4..ee08132 100644 --- a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/ToolHandlersTest.java +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/ToolHandlersTest.java @@ -75,7 +75,7 @@ void runsTheMaskedClientToolWorkflowWithFixtures() { Map probes = ListProbesHandler.execute(Map.of("pid", "53", "port", 2053)); assertFalse((Boolean) probes.get("isError")); - assertTrue(text(probes).contains("Active probes on PID 53")); + assertTrue(text(probes).contains("Probes on PID 53")); } @Test diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java new file mode 100644 index 0000000..143802c --- /dev/null +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java @@ -0,0 +1,96 @@ +package io.btrace.mcp.tools; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import io.btrace.client.Client; +import io.btrace.mcp.ClientManager; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class ListProbesHandlerTest { + @Test + void reportsTheProbeThisServerIsConnectedTo() { + deploy("70", 2070); + Client session = Client.last; + try { + Map result = ListProbesHandler.execute(Map.of("pid", "70", "port", 2070)); + + assertEquals(false, result.get("isError"), text(result)); + assertTrue( + text(result).contains("Connected through this MCP server: a probe on port 2070"), + text(result)); + assertTrue(text(result).contains("exit_probe"), text(result)); + assertTrue(text(result).contains("another client"), text(result)); + assertTrue(Client.last != session && Client.last.closed, "the list client must be closed"); + assertTrue(!session.closed, "listing must not touch the probe's own session"); + } finally { + ExitProbeHandler.execute(Map.of("pid", "70", "port", 2070)); + } + } + + @Test + void reportsNoConnectedProbeWithoutASession() { + Map result = ListProbesHandler.execute(Map.of("pid", "71", "port", 2071)); + + assertEquals(false, result.get("isError"), text(result)); + assertTrue(text(result).contains("Connected through this MCP server: none"), text(result)); + assertTrue(text(result).contains("Detached (stop with stop_detached_probe):"), text(result)); + assertTrue(Client.last.closed, "the list client must be closed"); + } + + @Test + void saysALostSessionsProbeIsListedAsDetached() throws Exception { + deploy("72", 2072); + ClientManager.getExistingClient("72", 2072).close(); + assertTrue(ClientManager.getOutput("72", 2072).awaitFinished(5000)); + + Map result = ListProbesHandler.execute(Map.of("pid", "72", "port", 2072)); + + assertEquals(false, result.get("isError"), text(result)); + assertTrue(text(result).contains("was lost"), text(result)); + assertTrue(text(result).contains("listed as detached"), text(result)); + assertEquals(null, ClientManager.getExistingClient("72", 2072), "the lost session is forgotten"); + } + + @Test + void givesUpAndClosesTheClientWhenTheAgentNeverAnswers() { + Client.hangListProbes = true; + try { + Map result = + ListProbesHandler.execute(Map.of("pid", "73", "port", 2073), 200); + + assertEquals(true, result.get("isError")); + assertTrue(text(result).contains("Timed out"), text(result)); + assertTrue(Client.last.closed, "client must be closed to release the connection"); + } finally { + Client.hangListProbes = false; + } + } + + @Test + void closesTheClientWhenAttachFails() { + Client.failAttach = true; + try { + Map result = ListProbesHandler.execute(Map.of("pid", "74", "port", 2074)); + + assertEquals(true, result.get("isError")); + assertTrue(Client.last.closed, "client must be closed after a failed attach"); + } finally { + Client.failAttach = false; + } + } + + private static void deploy(String pid, int port) { + Map deployed = + DeployOnelinerHandler.execute( + Map.of("pid", pid, "oneliner", "orders.Api::create @return { print duration }", "port", port)); + assertEquals(false, deployed.get("isError"), text(deployed)); + } + + @SuppressWarnings("unchecked") + private static String text(Map result) { + return (String) ((List>) result.get("content")).get(0).get("text"); + } +} diff --git a/plugins/btrace-observability/skills/btrace-mcp-operations/SKILL.md b/plugins/btrace-observability/skills/btrace-mcp-operations/SKILL.md index eaa61fd..fd7d02d 100644 --- a/plugins/btrace-observability/skills/btrace-mcp-operations/SKILL.md +++ b/plugins/btrace-observability/skills/btrace-mcp-operations/SKILL.md @@ -10,8 +10,10 @@ The BTrace MCP server offers structured local-JVM operations such as `list_jvms` and `stop_detached_probe`. It is suitable when the AI client and target JVM are on the same host and the operator wants an auditable conversational workflow. -`list_probes` reports probes that were detached with `detach_probe`, or whose connection was lost, -and are still running on the target; probes deployed in the current session that are still attached do not appear. Call it +`list_probes` reports the probe this MCP server is connected to on the target, if any, and the +probes that were detached with `detach_probe`, or whose connection was lost, and are still running +there. A probe connected through another client (a `btrace` CLI or another MCP server) appears in +neither list, so an empty result does not prove that nothing else is attached. Call it before deploying, so probes left behind by an earlier session are found rather than stacked on, and after any `detach_probe` to confirm what is still running. Stop a listed probe with `stop_detached_probe`, passing its id or the whole `list_probes` line, only after the operator From bb6c724ac6126629dd6a4c71753dcfeee1706a65 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Tue, 3 Nov 2026 19:02:10 +0100 Subject: [PATCH 2/2] fix(mcp): forget only the lost session list_probes reported Follow-ups from review: - list_probes read this server's session before listing and forgot any lost session afterwards. A session that dropped while the list was in flight was reported as live ("stop with exit_probe") and then forgotten, so that exit_probe call failed. Only a session this listing reported as lost is forgotten now; one that drops mid-list is reported by the next call. - On a timeout or a failed attach the error now still says what this server's session is, which needs no answer from the agent. - An interrupt restores the thread's flag, and error text unwraps reflection wrappers like stop_detached_probe does. - The e2e assertion checks the whole "Connected through this MCP server: none" line, not a prefix that the exited and lost variants also match. Verified: ./gradlew check 56 tests, 0 failures; the new keepsASessionLostWhileTheListIsInFlightForTheNextCall fails with the old unconditional forget and passes with the fix; e2eTest against a current btrace build - McpServerE2ETest 13/13, McpLostConnectionE2ETest 2/2. Co-Authored-By: Claude Opus 5.5 --- .../java/io/btrace/mcp/McpServerE2ETest.java | 2 +- .../btrace/mcp/tools/ListProbesHandler.java | 59 ++++++++++++++----- .../test/java/io/btrace/client/Client.java | 5 ++ .../mcp/tools/ListProbesHandlerTest.java | 36 +++++++++++ 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java b/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java index 0316550..53fc2d5 100644 --- a/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java +++ b/plugins/btrace-observability/mcp/src/e2eTest/java/io/btrace/mcp/McpServerE2ETest.java @@ -248,7 +248,7 @@ void listProbesReportsTheRunningProbe() throws Exception { assertSuccess(result); assertTrue(text(result).contains(RUNNING_PROBE)); assertTrue( - text(result).contains("Connected through this MCP server: none"), + text(result).contains("Connected through this MCP server: none\n"), "the detached probe is not this server's session:\n" + text(result)); assertTrue(server.isAlive(), "list_probes terminated the MCP server"); } diff --git a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java index ae9c516..3c91ad5 100644 --- a/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java +++ b/plugins/btrace-observability/mcp/src/main/java/io/btrace/mcp/tools/ListProbesHandler.java @@ -87,8 +87,10 @@ static Map execute(Map arguments, long timeoutMi return toolResult("Error: 'pid' parameter is required", true); } - // Read before listing: a lost session is forgotten once list_probes has shown its probe. - String connected = connectedSession(pid); + // Read before listing. Only a session this listing reports as lost is forgotten afterwards; one + // that drops while the list is in flight is left for the next call to report. + Session session = connectedSession(pid); + String connectedLine = "Connected through this MCP server: " + session.description; BTraceClient client = null; try { client = ClientManager.getClient(port); @@ -111,19 +113,21 @@ static Map execute(Map arguments, long timeoutMi try { list.get(timeoutMillis, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { - return toolResult("Timed out waiting for probe list from PID " + pid, true); + return toolResult( + "Timed out waiting for probe list from PID " + pid + "\n" + connectedLine, true); } catch (ExecutionException e) { throw e.getCause() instanceof Exception ? (Exception) e.getCause() : e; } - ClientManager.forgetLostSession(pid); + if (session.lost) { + ClientManager.forgetLostSession(pid); + } String detached = output.toString().trim(); String resultText = "Probes on PID " + pid + ":\n" - + "Connected through this MCP server: " - + connected + + connectedLine + "\n" + "Detached (stop with stop_detached_probe): " + (detached.isEmpty() ? "none" : "\n" + detached) @@ -131,29 +135,56 @@ static Map execute(Map arguments, long timeoutMi + "Probes connected through another client (a btrace CLI or another MCP server) are" + " not listed."; return toolResult(resultText, false); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return toolResult( + "Interrupted while listing probes on PID " + pid + "\n" + connectedLine, true); } catch (Exception e) { log.error("Failed to list probes", e); - return toolResult("Error listing probes on PID " + pid + ": " + e.getMessage(), true); + return toolResult( + "Error listing probes on PID " + pid + ": " + rootMessage(e) + "\n" + connectedLine, + true); } finally { closeQuietly(client); } } + /** What this server's session on a PID looked like when the listing started. */ + private static final class Session { + final String description; + final boolean lost; + + Session(String description, boolean lost) { + this.description = description; + this.lost = lost; + } + } + /** Describes this server's session on the PID, which the agent's list does not include. */ - private static String connectedSession(String pid) { + private static Session connectedSession(String pid) { int port = ClientManager.sessionPort(pid); if (port < 0) { - return "none"; + return new Session("none", false); } ProbeOutput output = ClientManager.getOutput(pid, port); if (output == null || !output.isFinished()) { - return "a probe on port " + port + " (stop with exit_probe)"; + return new Session("a probe on port " + port + " (stop with exit_probe)", false); } return output.hasExited() - ? "none (the probe on port " + port + " exited)" - : "none (the connection to the probe on port " - + port - + " was lost; if it is still running, it is listed as detached)"; + ? new Session("none (the probe on port " + port + " exited)", false) + : new Session( + "none (the connection to the probe on port " + + port + + " was lost; if it is still running, it is listed as detached)", + true); + } + + private static String rootMessage(Throwable e) { + Throwable cause = e; + while (cause.getCause() != null && cause.getMessage() == null) { + cause = cause.getCause(); + } + return cause.getMessage(); } private static void closeQuietly(BTraceClient client) { diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java index 75d1f0c..d9a5180 100644 --- a/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/client/Client.java @@ -19,6 +19,8 @@ public class Client { public static boolean ignoreExit = false; /** An agent that never answers a probe list request: only closing the client ends the wait. */ public static boolean hangListProbes = false; + /** Runs while a probe list request is in flight, to model events that race with it. */ + public static Runnable duringListProbes = null; public final int port; public String attachedPid; public int exitCode; @@ -84,6 +86,9 @@ public void connectAndListProbes(String host, CommandListener listener) throws E closeLatch.await(); return; } + if (duringListProbes != null) { + duringListProbes.run(); + } listener.onCommand(new FakePrintableCommand(Command.LIST_PROBES, host)); } diff --git a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java index 143802c..6ef14b8 100644 --- a/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java +++ b/plugins/btrace-observability/mcp/src/test/java/io/btrace/mcp/tools/ListProbesHandlerTest.java @@ -54,8 +54,37 @@ void saysALostSessionsProbeIsListedAsDetached() throws Exception { assertEquals(null, ClientManager.getExistingClient("72", 2072), "the lost session is forgotten"); } + @Test + void keepsASessionLostWhileTheListIsInFlightForTheNextCall() throws Exception { + deploy("75", 2075); + Client.duringListProbes = + () -> { + try { + ClientManager.getExistingClient("75", 2075).close(); + assertTrue(ClientManager.getOutput("75", 2075).awaitFinished(5000)); + } catch (Exception e) { + throw new AssertionError(e); + } + }; + try { + Map first = ListProbesHandler.execute(Map.of("pid", "75", "port", 2075)); + assertTrue(text(first).contains("a probe on port 2075"), text(first)); + assertTrue( + ClientManager.getExistingClient("75", 2075) != null, + "a session this listing reported as live must not be forgotten"); + } finally { + Client.duringListProbes = null; + } + + Map second = ListProbesHandler.execute(Map.of("pid", "75", "port", 2075)); + assertTrue(text(second).contains("was lost"), text(second)); + assertEquals(null, ClientManager.getExistingClient("75", 2075), "reported, then forgotten"); + } + @Test void givesUpAndClosesTheClientWhenTheAgentNeverAnswers() { + deploy("73", 2073); + Client session = Client.last; Client.hangListProbes = true; try { Map result = @@ -63,9 +92,14 @@ void givesUpAndClosesTheClientWhenTheAgentNeverAnswers() { assertEquals(true, result.get("isError")); assertTrue(text(result).contains("Timed out"), text(result)); + assertTrue( + text(result).contains("Connected through this MCP server: a probe on port 2073"), + text(result)); + assertTrue(Client.last != session, "the list must use its own client"); assertTrue(Client.last.closed, "client must be closed to release the connection"); } finally { Client.hangListProbes = false; + ExitProbeHandler.execute(Map.of("pid", "73", "port", 2073)); } } @@ -76,6 +110,8 @@ void closesTheClientWhenAttachFails() { Map result = ListProbesHandler.execute(Map.of("pid", "74", "port", 2074)); assertEquals(true, result.get("isError")); + assertTrue(text(result).contains("attach failed"), text(result)); + assertTrue(text(result).contains("Connected through this MCP server: none"), text(result)); assertTrue(Client.last.closed, "client must be closed after a failed attach"); } finally { Client.failAttach = false;