Skip to content

Commit 1fcb977

Browse files
Apply Gemini review: close HC5 HttpClient on shutdown
Both ToolRegistry and McpStdioServer now implement Closeable with close() calling httpClient.close(). McpBridgeMain uses try-with- resources to ensure connection pools are released when stdin closes (Claude Desktop terminates the MCP subprocess). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9d86d49 commit 1fcb977

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

modules/mcp-bridge/src/main/java/org/apache/axis2/mcp/bridge/McpBridgeMain.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ public static void main(String[] args) {
8888
keystorePath, keystorePass.toCharArray(),
8989
truststorePath, truststorePass.toCharArray());
9090

91-
ToolRegistry registry = new ToolRegistry(baseUrl, mapper, sslContext);
92-
registry.load();
91+
try (ToolRegistry registry = new ToolRegistry(baseUrl, mapper, sslContext)) {
92+
registry.load();
9393

94-
McpStdioServer server = new McpStdioServer(baseUrl, registry, mapper, sslContext);
95-
server.run();
94+
try (McpStdioServer server = new McpStdioServer(baseUrl, registry, mapper, sslContext)) {
95+
server.run();
96+
}
97+
}
9698

9799
} catch (Exception e) {
98100
System.err.println("[axis2-mcp-bridge] Fatal: " + e.getMessage());

modules/mcp-bridge/src/main/java/org/apache/axis2/mcp/bridge/McpStdioServer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
* <p>Notifications (messages without an {@code id} field) are silently consumed
5858
* with no response, as required by JSON-RPC 2.0.
5959
*/
60-
public class McpStdioServer {
60+
public class McpStdioServer implements java.io.Closeable {
6161

6262
private static final String PROTOCOL_VERSION = "2024-11-05";
6363
private static final String SERVER_NAME = "axis2-mcp-bridge";
@@ -281,4 +281,9 @@ private void writeLine(String json) {
281281
out.println(json);
282282
out.flush();
283283
}
284+
285+
@Override
286+
public void close() throws IOException {
287+
httpClient.close();
288+
}
284289
}

modules/mcp-bridge/src/main/java/org/apache/axis2/mcp/bridge/ToolRegistry.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* It is fetched once at startup; restart the bridge to pick up newly deployed
4848
* services.
4949
*/
50-
public class ToolRegistry {
50+
public class ToolRegistry implements java.io.Closeable {
5151

5252
private final String baseUrl;
5353
private final ObjectMapper mapper;
@@ -140,4 +140,9 @@ public void load() throws IOException {
140140
public List<McpTool> getTools() { return tools; }
141141

142142
public McpTool getTool(String name) { return toolMap.get(name); }
143+
144+
@Override
145+
public void close() throws IOException {
146+
httpClient.close();
147+
}
143148
}

0 commit comments

Comments
 (0)