Skip to content

Commit ba57a37

Browse files
committed
Silence peer closed warning logs
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
1 parent c8e8091 commit ba57a37

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

mcp-core/src/main/java/io/modelcontextprotocol/spec/McpClientSession.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ else if (message instanceof McpSchema.JSONRPCRequest request) {
164164
if (t instanceof McpTransportSessionClosedException) {
165165
logger.debug("Can't send response to request {} when the transport is closed", request.id());
166166
}
167+
else if (McpTransport.isPeerClosed(t)) {
168+
logger.debug("Can't send response to request {}: connection closed by peer", request.id(), t);
169+
}
167170
else {
168171
logger.warn("Failed to send response to the server", t);
169172
}

mcp-core/src/main/java/io/modelcontextprotocol/spec/McpTransport.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,23 @@ public interface McpTransport {
5353
*/
5454
default void close() {
5555
this.closeGracefully().subscribe(ignored -> {
56-
}, error -> logger.warn("Error during asynchronous close", error));
56+
}, error -> {
57+
if (isPeerClosed(error)) {
58+
logger.debug("Error during asynchronous close", error);
59+
}
60+
else {
61+
logger.warn("Error during asynchronous close", error);
62+
}
63+
});
64+
}
65+
66+
static boolean isPeerClosed(Throwable t) {
67+
for (Throwable c = t; c != null; c = c.getCause()) {
68+
if (c instanceof java.io.EOFException) {
69+
return true;
70+
}
71+
}
72+
return false;
5773
}
5874

5975
/**

mcp-test/src/test/java/io/modelcontextprotocol/server/transport/ServerTransportSecurityIntegrationTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void setUp() {
8181

8282
@AfterEach
8383
void tearDown() {
84+
requestCustomizer.reset();
8485
mcpClient.close();
8586
}
8687

0 commit comments

Comments
 (0)