Skip to content

Commit

Permalink
Merge pull request #72 from mkouba/fix-tool-list-schemas
Browse files Browse the repository at this point in the history
tools: fix input schema generation
  • Loading branch information
mkouba authored Jan 17, 2025
2 parents eecefbd + 015e2c6 commit cdcfa31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void toolsList(JsonObject message, Responder responder) {
JsonObject tool = toolMetadata.asJson();
JsonObject properties = new JsonObject();
JsonArray required = new JsonArray();
for (FeatureArgument a : toolMetadata.info().arguments()) {
for (FeatureArgument a : toolMetadata.info().serializedArguments()) {
properties.put(a.name(), generateSchema(a.type(), a));
if (a.required()) {
required.add(a.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import jakarta.inject.Inject;

import io.quarkiverse.mcp.server.Content;
import io.quarkiverse.mcp.server.McpConnection;
import io.quarkiverse.mcp.server.McpLog;
import io.quarkiverse.mcp.server.TextContent;
import io.quarkiverse.mcp.server.Tool;
import io.quarkiverse.mcp.server.ToolArg;
Expand Down Expand Up @@ -58,7 +60,7 @@ Uni<Content> uni_bravo(int price) {
}

@Tool
String charlie(DayOfWeek day) {
String charlie(DayOfWeek day, McpConnection connection, McpLog log) {
checkExecutionModel(true);
checkDuplicatedContext();
checkRequestContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,28 @@ public void testTools() throws URISyntaxException {
assertEquals(8, tools.size());

// alpha, bravo, charlie, list_charlie, uni_alpha, uni_bravo, uni_charlie, uni_list_charlie
assertTool(tools.getJsonObject(0), "alpha", null, schema -> {
assertTool(tools, "alpha", null, schema -> {
JsonObject properties = schema.getJsonObject("properties");
assertEquals(1, properties.size());
JsonObject priceProperty = properties.getJsonObject("price");
assertNotNull(priceProperty);
assertEquals("integer", priceProperty.getString("type"));
assertEquals("Define the price...", priceProperty.getString("description"));
});
assertTool(tools.getJsonObject(4), "uni_alpha", null, schema -> {
assertTool(tools, "uni_alpha", null, schema -> {
JsonObject properties = schema.getJsonObject("properties");
assertEquals(1, properties.size());
JsonObject priceProperty = properties.getJsonObject("uni_price");
assertNotNull(priceProperty);
assertEquals("number", priceProperty.getString("type"));
});
assertTool(tools, "charlie", null, schema -> {
JsonObject properties = schema.getJsonObject("properties");
assertEquals(1, properties.size());
JsonObject dayProperty = properties.getJsonObject("day");
assertNotNull(dayProperty);
assertEquals("string", dayProperty.getString("type"));
});

assertToolCall("Hello 1!", endpoint, "alpha", new JsonObject()
.put("price", 1));
Expand All @@ -81,8 +88,14 @@ public void testTools() throws URISyntaxException {
assertToolCall("charlie4", endpoint, "uni_list_charlie", new JsonObject());
}

private void assertTool(JsonObject tool, String name, String description, Consumer<JsonObject> inputSchemaAsserter) {
assertEquals(name, tool.getString("name"));
private void assertTool(JsonArray tools, String name, String description, Consumer<JsonObject> inputSchemaAsserter) {
JsonObject tool = null;
for (int i = 0; i < tools.size(); i++) {
JsonObject t = tools.getJsonObject(i);
if (name.equals(t.getString("name"))) {
tool = t;
}
}
if (description != null) {
assertEquals(description, tool.getString("description"));
}
Expand Down

0 comments on commit cdcfa31

Please sign in to comment.