Skip to content

Commit da6fcfc

Browse files
committed
Relocate tool capability validation for consistency and remove redundant list copying in async server methods
1 parent 8d98e17 commit da6fcfc

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,20 +589,20 @@ public Mono<Void> removeTools(List<String> toolNames) {
589589
if (toolNames == null) {
590590
return Mono.error(new IllegalArgumentException("Tool names must not be null"));
591591
}
592+
if (this.serverCapabilities.tools() == null) {
593+
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
594+
}
592595
if (toolNames.isEmpty()) {
593596
return Mono.empty();
594597
}
595598

596599
Set<String> toolNamesToRemove = new HashSet<>();
597-
for (String toolName : new ArrayList<>(toolNames)) {
600+
for (String toolName : toolNames) {
598601
if (toolName == null) {
599602
return Mono.error(new IllegalArgumentException("Tool name must not be null"));
600603
}
601604
toolNamesToRemove.add(toolName);
602605
}
603-
if (this.serverCapabilities.tools() == null) {
604-
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
605-
}
606606

607607
return Mono.defer(() -> {
608608
if (this.tools.removeIf(toolSpecification -> toolNamesToRemove.contains(toolSpecification.tool().name()))) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,21 @@ public Mono<Void> removeTools(List<String> toolNames) {
457457
if (toolNames == null) {
458458
return Mono.error(new IllegalArgumentException("Tool names must not be null"));
459459
}
460+
if (this.serverCapabilities.tools() == null) {
461+
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
462+
}
460463
if (toolNames.isEmpty()) {
461464
return Mono.empty();
462465
}
463466

464467
Set<String> toolNamesToRemove = new HashSet<>();
465-
for (String toolName : new ArrayList<>(toolNames)) {
468+
for (String toolName : toolNames) {
466469
if (toolName == null) {
467470
return Mono.error(new IllegalArgumentException("Tool name must not be null"));
468471
}
469472
toolNamesToRemove.add(toolName);
470473
}
471-
if (this.serverCapabilities.tools() == null) {
472-
return Mono.error(new IllegalStateException("Server must be configured with tool capabilities"));
473-
}
474+
474475

475476
return Mono.defer(() -> {
476477
if (this.tools.removeIf(toolSpecification -> toolNamesToRemove.contains(toolSpecification.tool().name()))) {

0 commit comments

Comments
 (0)