Skip to content

Commit

Permalink
Merge pull request #50 from mkouba/support-enum-args
Browse files Browse the repository at this point in the history
Support enum arguments in feature methods
  • Loading branch information
mkouba authored Jan 13, 2025
2 parents c0a68e4 + 02100a3 commit 2a0acba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ private Object[] prepareArguments(FeatureMethodInfo info, ArgumentProviders argP
throw new IllegalStateException(e);
}
} else {
ret[idx] = val;
if (arg.type() instanceof Class clazz && clazz.isEnum()) {
ret[idx] = Enum.valueOf(clazz, val.toString());
} else {
ret[idx] = val;
}
}
}
idx++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static QuarkusUnitTest defaultConfig() {
// but the test CL can see the class and we don't need Quarkus to analyze this util class
QuarkusUnitTest config = new QuarkusUnitTest();
if (System.getProperty("logTraffic") != null) {
config.overrideConfigKey("quarkus.mcp.server.sse.traffic-logging.enabled", "true");
config.overrideConfigKey("quarkus.mcp.server.traffic-logging.enabled", "true");
}
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.quarkiverse.mcp.server.test.Checks.checkExecutionModel;
import static io.quarkiverse.mcp.server.test.Checks.checkRequestContext;

import java.time.DayOfWeek;
import java.util.List;

import jakarta.inject.Inject;
Expand Down Expand Up @@ -57,11 +58,11 @@ Uni<Content> uni_bravo(int price) {
}

@Tool
String charlie() {
String charlie(DayOfWeek day) {
checkExecutionModel(true);
checkDuplicatedContext();
checkRequestContext();
return "charlie1";
return DayOfWeek.MONDAY.equals(day) ? "charlie11" : "charlie1";
}

@Tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.time.DayOfWeek;
import java.util.function.Consumer;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -72,7 +73,8 @@ public void testTools() throws URISyntaxException {
.put("price", 1));
assertToolCall("Hello 1!", endpoint, "uni_bravo", new JsonObject()
.put("price", 1));
assertToolCall("charlie1", endpoint, "charlie", new JsonObject());
assertToolCall("charlie1", endpoint, "charlie", new JsonObject().put("day", DayOfWeek.FRIDAY.toString()));
assertToolCall("charlie11", endpoint, "charlie", new JsonObject().put("day", DayOfWeek.MONDAY.toString()));
assertToolCall("charlie2", endpoint, "uni_charlie", new JsonObject());
assertToolCall("charlie3", endpoint, "list_charlie", new JsonObject());
assertToolCall("charlie4", endpoint, "uni_list_charlie", new JsonObject());
Expand Down

0 comments on commit 2a0acba

Please sign in to comment.