Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public List<AsyncPromptListChangedSpecification> getPromptListChangedSpecificati
.filter(method -> method.isAnnotationPresent(McpPromptListChanged.class))
.filter(method -> method.getReturnType() == void.class
|| Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpPromptListChangedConsumerMethod -> {
var promptListChangedAnnotation = mcpPromptListChangedConsumerMethod
.getAnnotation(McpPromptListChanged.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public List<SyncPromptListChangedSpecification> getPromptListChangedSpecificatio
.map(consumerObject -> Stream.of(doGetClassMethods(consumerObject))
.filter(method -> method.isAnnotationPresent(McpPromptListChanged.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpPromptListChangedConsumerMethod -> {
var promptListChangedAnnotation = mcpPromptListChangedConsumerMethod
.getAnnotation(McpPromptListChanged.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public List<AsyncResourceListChangedSpecification> getResourceListChangedSpecifi
.filter(method -> method.isAnnotationPresent(McpResourceListChanged.class))
.filter(method -> method.getReturnType() == void.class
|| Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpResourceListChangedConsumerMethod -> {
var resourceListChangedAnnotation = mcpResourceListChangedConsumerMethod
.getAnnotation(McpResourceListChanged.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public List<SyncResourceListChangedSpecification> getResourceListChangedSpecific
.map(consumerObject -> Stream.of(doGetClassMethods(consumerObject))
.filter(method -> method.isAnnotationPresent(McpResourceListChanged.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpResourceListChangedConsumerMethod -> {
var resourceListChangedAnnotation = mcpResourceListChangedConsumerMethod
.getAnnotation(McpResourceListChanged.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public List<AsyncToolListChangedSpecification> getToolListChangedSpecifications(
.filter(method -> method.isAnnotationPresent(McpToolListChanged.class))
.filter(method -> method.getReturnType() == void.class
|| Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpToolListChangedConsumerMethod -> {
var toolListChangedAnnotation = mcpToolListChangedConsumerMethod
.getAnnotation(McpToolListChanged.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public List<SyncToolListChangedSpecification> getToolListChangedSpecifications()
.map(consumerObject -> Stream.of(doGetClassMethods(consumerObject))
.filter(method -> method.isAnnotationPresent(McpToolListChanged.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpToolListChangedConsumerMethod -> {
var toolListChangedAnnotation = mcpToolListChangedConsumerMethod
.getAnnotation(McpToolListChanged.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public List<AsyncCompletionSpecification> getCompleteSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpCompleteMethod -> {
var completeAnnotation = mcpCompleteMethod.getAnnotation(McpComplete.class);
var completeRef = CompleteAdapter.asCompleteReference(completeAnnotation, mcpCompleteMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public List<AsyncCompletionSpecification> getCompleteSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpCompleteMethod -> {
var completeAnnotation = mcpCompleteMethod.getAnnotation(McpComplete.class);
var completeRef = CompleteAdapter.asCompleteReference(completeAnnotation, mcpCompleteMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public List<SyncCompletionSpecification> getCompleteSpecifications() {
.map(completeObject -> Stream.of(doGetClassMethods(completeObject))
.filter(method -> method.isAnnotationPresent(McpComplete.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpCompleteMethod -> {
var completeAnnotation = mcpCompleteMethod.getAnnotation(McpComplete.class);
var completeRef = CompleteAdapter.asCompleteReference(completeAnnotation, mcpCompleteMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public List<SyncCompletionSpecification> getCompleteSpecifications() {
.map(completeObject -> Stream.of(doGetClassMethods(completeObject))
.filter(method -> method.isAnnotationPresent(McpComplete.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpCompleteMethod -> {
var completeAnnotation = mcpCompleteMethod.getAnnotation(McpComplete.class);
var completeRef = CompleteAdapter.asCompleteReference(completeAnnotation, mcpCompleteMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public List<AsyncElicitationSpecification> getElicitationSpecifications() {
&& ElicitRequest.class.isAssignableFrom(method.getParameterTypes()[0]))
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| ElicitResult.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpElicitationMethod -> {
var elicitationAnnotation = mcpElicitationMethod.getAnnotation(McpElicitation.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public List<SyncElicitationSpecification> getElicitationSpecifications() {
.filter(method -> ElicitResult.class.isAssignableFrom(method.getReturnType()))
.filter(method -> method.getParameterCount() == 1
&& ElicitRequest.class.isAssignableFrom(method.getParameterTypes()[0]))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpElicitationMethod -> {
var elicitationAnnotation = mcpElicitationMethod.getAnnotation(McpElicitation.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ public AsyncMcpLoggingProvider(List<Object> loggingConsumerObjects) {
public List<AsyncLoggingSpecification> getLoggingSpecifications() {

List<AsyncLoggingSpecification> loggingConsumers = this.loggingConsumerObjects.stream()
.map(consumerObject -> Stream.of(doGetClassMethods(consumerObject))
.map(consumerObject -> Stream.of(this.doGetClassMethods(consumerObject))
.filter(method -> method.isAnnotationPresent(McpLogging.class))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpLoggingConsumerMethod -> {
var loggingConsumerAnnotation = mcpLoggingConsumerMethod.getAnnotation(McpLogging.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public List<SyncLoggingSpecification> getLoggingSpecifications() {
.map(consumerObject -> Stream.of(doGetClassMethods(consumerObject))
.filter(method -> method.isAnnotationPresent(McpLogging.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpLoggingConsumerMethod -> {
var loggingConsumerAnnotation = mcpLoggingConsumerMethod.getAnnotation(McpLogging.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public List<AsyncProgressSpecification> getProgressSpecifications() {
}
return false;
})
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpProgressMethod -> {
var progressAnnotation = mcpProgressMethod.getAnnotation(McpProgress.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public List<SyncProgressSpecification> getProgressSpecifications() {
.filter(method -> method.getReturnType() == void.class) // Only void
// return type is
// valid for sync
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpProgressMethod -> {
var progressAnnotation = mcpProgressMethod.getAnnotation(McpProgress.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public List<AsyncPromptSpecification> getPromptSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpPromptMethod -> {
var promptAnnotation = mcpPromptMethod.getAnnotation(McpPrompt.class);
var mcpPrompt = PromptAdapter.asPrompt(promptAnnotation, mcpPromptMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public List<AsyncPromptSpecification> getPromptSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpPromptMethod -> {
var promptAnnotation = mcpPromptMethod.getAnnotation(McpPrompt.class);
var mcpPrompt = PromptAdapter.asPrompt(promptAnnotation, mcpPromptMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public List<SyncPromptSpecification> getPromptSpecifications() {
.map(resourceObject -> Stream.of(doGetClassMethods(resourceObject))
.filter(method -> method.isAnnotationPresent(McpPrompt.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpPromptMethod -> {
var promptAnnotation = mcpPromptMethod.getAnnotation(McpPrompt.class);
var mcpPrompt = PromptAdapter.asPrompt(promptAnnotation, mcpPromptMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public List<SyncPromptSpecification> getPromptSpecifications() {
.map(promptObject -> Stream.of(doGetClassMethods(promptObject))
.filter(method -> method.isAnnotationPresent(McpPrompt.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpPromptMethod -> {
var promptAnnotation = mcpPromptMethod.getAnnotation(McpPrompt.class);
var mcpPrompt = PromptAdapter.asPrompt(promptAnnotation, mcpPromptMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public List<AsyncResourceSpecification> getResourceSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpResourceMethod -> {

var resourceAnnotation = doGetMcpResourceAnnotation(mcpResourceMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public List<AsyncResourceSpecification> getResourceSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpResourceMethod -> {

var resourceAnnotation = doGetMcpResourceAnnotation(mcpResourceMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public List<SyncResourceSpecification> getResourceSpecifications() {
.map(resourceObject -> Stream.of(this.doGetClassMethods(resourceObject))
.filter(resourceMethod -> resourceMethod.isAnnotationPresent(McpResource.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpResourceMethod -> {
var resourceAnnotation = mcpResourceMethod.getAnnotation(McpResource.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public List<SyncResourceSpecification> getResourceSpecifications() {
.map(resourceObject -> Stream.of(doGetClassMethods(resourceObject))
.filter(method -> method.isAnnotationPresent(McpResource.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpResourceMethod -> {

var resourceAnnotation = doGetMcpResourceAnnotation(mcpResourceMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public List<AsyncSamplingSpecification> getSamplingSpecifictions() {
&& CreateMessageRequest.class.isAssignableFrom(method.getParameterTypes()[0]))
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| CreateMessageResult.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpSamplingMethod -> {
var samplingAnnotation = mcpSamplingMethod.getAnnotation(McpSampling.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public List<SyncSamplingSpecification> getSamplingSpecifications() {
.filter(method -> CreateMessageResult.class.isAssignableFrom(method.getReturnType()))
.filter(method -> method.getParameterCount() == 1
&& CreateMessageRequest.class.isAssignableFrom(method.getParameterTypes()[0]))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpSamplingMethod -> {
var samplingAnnotation = mcpSamplingMethod.getAnnotation(McpSampling.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public List<AsyncToolSpecification> getToolSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpToolMethod -> {

var toolJavaAnnotation = doGetMcpToolAnnotation(mcpToolMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public List<AsyncToolSpecification> getToolSpecifications() {
.filter(method -> Mono.class.isAssignableFrom(method.getReturnType())
|| Flux.class.isAssignableFrom(method.getReturnType())
|| Publisher.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpToolMethod -> {

var toolJavaAnnotation = doGetMcpToolAnnotation(mcpToolMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public List<SyncToolSpecification> getToolSpecifications() {
.map(toolObject -> Stream.of(doGetClassMethods(toolObject))
.filter(method -> method.isAnnotationPresent(McpTool.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpToolMethod -> {

McpTool toolJavaAnnotation = doGetMcpToolAnnotation(mcpToolMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public List<SyncToolSpecification> getToolSpecifications() {
.map(toolObject -> Stream.of(doGetClassMethods(toolObject))
.filter(method -> method.isAnnotationPresent(McpTool.class))
.filter(method -> !Mono.class.isAssignableFrom(method.getReturnType()))
.sorted((m1, m2) -> m1.getName().compareTo(m2.getName()))
.map(mcpToolMethod -> {

var toolJavaAnnotation = doGetMcpToolAnnotation(mcpToolMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ static class LoggingHandler {

@McpLogging(clients = "test-client")
public void handleLoggingMessage(LoggingMessageNotification notification) {
System.out.println("1");
this.lastNotification = notification;
}

@McpLogging(clients = "test-client")
public void handleLoggingMessageWithParams(LoggingLevel level, String logger, String data) {
System.out.println("2");
this.lastLevel = level;
this.lastLogger = logger;
this.lastData = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import org.junit.jupiter.api.Test;
Expand All @@ -29,6 +31,8 @@ public class AsyncMcpProgressProviderTests {
*/
static class AsyncProgressHandler {

final CountDownLatch latch;

private ProgressNotification lastNotification;

private Double lastProgress;
Expand All @@ -37,6 +41,14 @@ static class AsyncProgressHandler {

private String lastTotal;

public AsyncProgressHandler(CountDownLatch latch) {
this.latch = latch;
}

public AsyncProgressHandler() {
this.latch = new CountDownLatch(2);
}

@McpProgress(clients = "my-client-id")
public void handleProgressVoid(ProgressNotification notification) {
this.lastNotification = notification;
Expand All @@ -45,6 +57,7 @@ public void handleProgressVoid(ProgressNotification notification) {
@McpProgress(clients = "my-client-id")
public Mono<Void> handleProgressMono(ProgressNotification notification) {
this.lastNotification = notification;
latch.countDown();
return Mono.empty();
}

Expand All @@ -60,6 +73,7 @@ public Mono<Void> handleProgressWithParamsMono(Double progress, String progressT
this.lastProgress = progress;
this.lastProgressToken = progressToken;
this.lastTotal = total;
latch.countDown();
return Mono.empty();
}

Expand Down Expand Up @@ -92,7 +106,8 @@ public Mono<String> invalidMonoReturnType(ProgressNotification notification) {

@Test
void testGetProgressSpecifications() {
AsyncProgressHandler progressHandler = new AsyncProgressHandler();
CountDownLatch latch = new CountDownLatch(1);
AsyncProgressHandler progressHandler = new AsyncProgressHandler(latch);
AsyncMcpProgressProvider provider = new AsyncMcpProgressProvider(List.of(progressHandler));

List<AsyncProgressSpecification> specifications = provider.getProgressSpecifications();
Expand All @@ -109,6 +124,15 @@ void testGetProgressSpecifications() {
"Test progress message");

StepVerifier.create(handlers.get(0).apply(notification)).verifyComplete();

try {
// Wait for progress notifications to be processed
latch.await(3, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
e.printStackTrace();
}

assertThat(progressHandler.lastNotification).isEqualTo(notification);

// Reset
Expand Down