Skip to content

Commit c42d313

Browse files
tzolovchemicL
andauthored
Return void from McpStatelessSyncServer#closeGracefully instead of Mono (#1019)
Co-authored-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com> Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
1 parent 2756337 commit c42d313

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

MIGRATION-2.0.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The changes fall into these areas:
99
- [JSON serialization behaviour](#json-serialization-behaviour) — wire-format changes.
1010
- [Server-side validation](#server-side-validation) — runtime validation of tool arguments and embedded schemas.
1111
- [Transport changes](#transport-changes) — removed methods and the SSE deprecation.
12+
- [Server API changes](#server-api-changes) — sync server method signature corrections.
1213
- [New features](#new-features) — additive, backward-compatible capabilities.
1314

1415
---
@@ -220,6 +221,18 @@ The HTTP+SSE client and server transports (and their supporting validator/except
220221

221222
---
222223

224+
## Server API changes
225+
226+
### `McpStatelessSyncServer#closeGracefully` returns `void`
227+
228+
In 1.x, `McpStatelessSyncServer.closeGracefully()` accidentally leaked the reactive signature from the underlying async server and returned `Mono<Void>`. The sync API is intentionally blocking, so returning a `Mono` was an oversight — callers had to call `.block()` themselves to get any actual shutdown behaviour.
229+
230+
In 2.0 the return type is corrected to `void`; the blocking call is performed internally.
231+
232+
**Action:** Remove any `.block()` (or `.subscribe()`) call you had appended to `closeGracefully()`. The method now blocks until the server has shut down and returns normally.
233+
234+
---
235+
223236
## New features
224237

225238
These are additive and backward-compatible.

mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public McpSchema.Implementation getServerInfo() {
5050

5151
/**
5252
* Gracefully closes the server, allowing any in-progress operations to complete.
53-
* @return A Mono that completes when the server has been closed
53+
*
5454
*/
55-
public Mono<Void> closeGracefully() {
56-
return this.asyncServer.closeGracefully();
55+
public void closeGracefully() {
56+
this.asyncServer.closeGracefully().block();
5757
}
5858

5959
/**

mcp-test/src/main/java/io/modelcontextprotocol/AbstractStatelessIntegrationTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package io.modelcontextprotocol;
66

7-
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
8-
97
import java.net.URI;
108
import java.net.http.HttpClient;
119
import java.net.http.HttpRequest;
@@ -31,9 +29,9 @@
3129
import net.javacrumbs.jsonunit.core.Option;
3230
import org.junit.jupiter.params.ParameterizedTest;
3331
import org.junit.jupiter.params.provider.MethodSource;
34-
import org.junit.jupiter.params.provider.ValueSource;
3532
import reactor.core.publisher.Mono;
3633

34+
import static io.modelcontextprotocol.util.ToolsUtils.EMPTY_JSON_SCHEMA;
3735
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
3836
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json;
3937
import static org.assertj.core.api.Assertions.assertThat;
@@ -128,7 +126,7 @@ void testToolCallSuccess(String clientType) {
128126
assertThat(response).isNotNull().isEqualTo(callResponse);
129127
}
130128
finally {
131-
mcpServer.closeGracefully().block();
129+
mcpServer.closeGracefully();
132130
}
133131
}
134132

0 commit comments

Comments
 (0)