Skip to content

Commit 4f19f7e

Browse files
committed
Relocate tool capability validation to ensure early exit in async server methods
1 parent 428b8fe commit 4f19f7e

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ public Mono<Void> addTools(List<McpServerFeatures.AsyncToolSpecification> toolSp
380380
if (toolSpecifications.isEmpty()) {
381381
return Mono.empty();
382382
}
383+
if (this.serverCapabilities.tools() == null) {
384+
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
385+
}
383386

384387
Map<String, McpServerFeatures.AsyncToolSpecification> wrappedToolSpecificationsByName;
385388
try {
@@ -388,9 +391,6 @@ public Mono<Void> addTools(List<McpServerFeatures.AsyncToolSpecification> toolSp
388391
catch (IllegalArgumentException e) {
389392
return Mono.error(e);
390393
}
391-
if (this.serverCapabilities.tools() == null) {
392-
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
393-
}
394394

395395
return Mono.defer(() -> {
396396
this.tools.removeIf(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ public Mono<Void> addTools(List<McpStatelessServerFeatures.AsyncToolSpecificatio
369369
if (toolSpecifications.isEmpty()) {
370370
return Mono.empty();
371371
}
372+
if (this.serverCapabilities.tools() == null) {
373+
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
374+
}
372375

373376
Map<String, McpStatelessServerFeatures.AsyncToolSpecification> wrappedToolSpecificationsByName;
374377
try {
@@ -377,9 +380,6 @@ public Mono<Void> addTools(List<McpStatelessServerFeatures.AsyncToolSpecificatio
377380
catch (IllegalArgumentException e) {
378381
return Mono.error(e);
379382
}
380-
if (this.serverCapabilities.tools() == null) {
381-
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
382-
}
383383

384384
return Mono.defer(() -> {
385385
this.tools.removeIf(

0 commit comments

Comments
 (0)