Skip to content

Commit 8d98e17

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

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,13 @@ public Mono<Void> addTools(List<McpServerFeatures.AsyncToolSpecification> toolSp
377377
if (toolSpecifications == null) {
378378
return Mono.error(new IllegalArgumentException("Tool specifications must not be null"));
379379
}
380-
if (toolSpecifications.isEmpty()) {
381-
return Mono.empty();
382-
}
380+
383381
if (this.serverCapabilities.tools() == null) {
384382
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
385383
}
384+
if (toolSpecifications.isEmpty()) {
385+
return Mono.empty();
386+
}
386387

387388
Map<String, McpServerFeatures.AsyncToolSpecification> wrappedToolSpecificationsByName;
388389
try {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,14 @@ public Mono<Void> addTools(List<McpStatelessServerFeatures.AsyncToolSpecificatio
366366
if (toolSpecifications == null) {
367367
return Mono.error(new IllegalArgumentException("Tool specifications must not be null"));
368368
}
369-
if (toolSpecifications.isEmpty()) {
370-
return Mono.empty();
371-
}
372369
if (this.serverCapabilities.tools() == null) {
373370
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
374371
}
375372

373+
if (toolSpecifications.isEmpty()) {
374+
return Mono.empty();
375+
}
376+
376377
Map<String, McpStatelessServerFeatures.AsyncToolSpecification> wrappedToolSpecificationsByName;
377378
try {
378379
wrappedToolSpecificationsByName = sanitizeToolSpecifications(toolSpecifications);

0 commit comments

Comments
 (0)