Skip to content

Commit 5ccd495

Browse files
committed
functional style
1 parent 90e1af1 commit 5ccd495

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,10 @@ private McpRequestHandler<McpSchema.ReadResourceResult> resourcesReadRequestHand
645645
new TypeRef<McpSchema.ReadResourceRequest>() {
646646
});
647647
var resourceUri = resourceRequest.uri();
648-
649-
Optional<McpServerFeatures.AsyncResourceSpecification> specification = asyncResourceSpecification(
650-
resourceUri);
651-
if (specification.isPresent()) {
652-
return Mono.error(RESOURCE_NOT_FOUND.apply(resourceUri));
653-
}
654-
return Mono.defer(() -> specification.get().readHandler().apply(exchange, resourceRequest));
648+
return asyncResourceSpecification(resourceUri)
649+
.map(asyncResourceSpecification -> Mono
650+
.defer(() -> asyncResourceSpecification.readHandler().apply(exchange, resourceRequest)))
651+
.orElseGet(() -> Mono.error(RESOURCE_NOT_FOUND.apply(resourceUri)));
655652
};
656653
}
657654

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ private McpStatelessRequestHandler<McpSchema.ReadResourceResult> resourcesReadRe
488488
};
489489
}
490490

491-
private Optional<McpStatelessServerFeatures.AsyncResourceSpecification> asyncResourceSpecification(String resourceUri) {
491+
private Optional<McpStatelessServerFeatures.AsyncResourceSpecification> asyncResourceSpecification(
492+
String resourceUri) {
492493
return resources.values()
493494
.stream()
494495
.filter(resourceSpecification -> this.uriTemplateManagerFactory

0 commit comments

Comments
 (0)