Skip to content

Commit 04faab3

Browse files
committed
mcp: 2.0.0
fix #3974
1 parent 529a7c3 commit 04faab3

5 files changed

Lines changed: 34 additions & 21 deletions

File tree

modules/jooby-apt/src/main/java/io/jooby/internal/apt/mcp/McpRoute.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -723,18 +723,24 @@ private List<String> generateToolDefinition(boolean kt) {
723723
buffer.add(
724724
statement(
725725
indent(6),
726-
"return io.modelcontextprotocol.spec.McpSchema.Tool(",
726+
"return io.modelcontextprotocol.spec.McpSchema.Tool.builder(",
727727
string(toolName),
728-
", ",
728+
", this.json.convertValue(schema, java.util.Map::class.java) as java.util.Map<String,"
729+
+ " Any>)",
730+
".title(",
729731
titleArg,
730-
", ",
732+
")",
733+
".description(",
731734
string(description),
732-
", this.json.convertValue(schema,"
733-
+ " io.modelcontextprotocol.spec.McpSchema.JsonSchema::class.java), ",
735+
")",
736+
".outputSchema(",
734737
outputSchemaArg,
735-
", ",
738+
")",
739+
".annotations(",
736740
annotationsArg,
737-
", null)"));
741+
")",
742+
".build()"));
743+
738744
} else {
739745
if (toolAnnotation != null) {
740746
annotationsArg = "annotations";
@@ -760,18 +766,22 @@ private List<String> generateToolDefinition(boolean kt) {
760766
buffer.add(
761767
statement(
762768
indent(6),
763-
"return new io.modelcontextprotocol.spec.McpSchema.Tool(",
769+
"return io.modelcontextprotocol.spec.McpSchema.Tool.builder(",
764770
string(toolName),
765-
", ",
771+
", this.json.convertValue(schema, java.util.Map.class))",
772+
".title(",
766773
titleArg,
767-
", ",
774+
")",
775+
".description(",
768776
string(description),
769-
", this.json.convertValue(schema,"
770-
+ " io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), ",
777+
")",
778+
".outputSchema(",
771779
outputSchemaArg,
772-
", ",
780+
")",
781+
".annotations(",
773782
annotationsArg,
774-
", null)",
783+
")",
784+
".build()",
775785
semicolon(kt)));
776786
}
777787
buffer.add(statement(indent(4), "}\n"));

modules/jooby-apt/src/test/java/tests/i3830/Issue3830.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private io.modelcontextprotocol.spec.McpSchema.Tool addToolSpec(com.github.victo
125125
props.put("b", schema_b);
126126
req.add("b");
127127
var annotations = new io.modelcontextprotocol.spec.McpSchema.ToolAnnotations("Add two numbers.A simple calculator.", true, true, false, true, null);
128-
return new io.modelcontextprotocol.spec.McpSchema.Tool("calculator", "Add two numbers.", "A simple calculator.", this.json.convertValue(schema, io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), null, annotations, null);
128+
return io.modelcontextprotocol.spec.McpSchema.Tool.builder("calculator", this.json.convertValue(schema, java.util.Map.class)).title("Add two numbers.").description("A simple calculator.").outputSchema(null).annotations(annotations).build();
129129
}
130130
131131
private io.modelcontextprotocol.spec.McpSchema.CallToolResult add(io.modelcontextprotocol.server.McpSyncServerExchange exchange, io.modelcontextprotocol.common.McpTransportContext transportContext, io.jooby.mcp.McpOperation operation) {

modules/jooby-apt/src/test/java/tests/i3830/OutputSchemaTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private io.modelcontextprotocol.spec.McpSchema.Tool schemaOffToolSpec(com.github
2828
schema.put("properties", props);
2929
var req = new java.util.ArrayList<String>();
3030
schema.put("required", req);
31-
return new io.modelcontextprotocol.spec.McpSchema.Tool("schemaOff", null, null, this.json.convertValue(schema, io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), null, null, null);
31+
return io.modelcontextprotocol.spec.McpSchema.Tool.builder("schemaOff", this.json.convertValue(schema, java.util.Map.class)).title(null).description(null).outputSchema(null).annotations(null).build();
3232
}
3333
""");
3434
});
@@ -56,7 +56,7 @@ private io.modelcontextprotocol.spec.McpSchema.Tool schemaMapToolSpec(com.github
5656
schemaMapOutputSchemaWrapped.put("type", "object");
5757
schemaMapOutputSchemaWrapped.put("additionalProperties", schemaMapOutputSchemaMap);
5858
schemaMapOutputSchema = schemaMapOutputSchemaWrapped;
59-
return new io.modelcontextprotocol.spec.McpSchema.Tool("schemaMap", null, null, this.json.convertValue(schema, io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), schemaMapOutputSchema, null, null);
59+
return io.modelcontextprotocol.spec.McpSchema.Tool.builder("schemaMap", this.json.convertValue(schema, java.util.Map.class)).title(null).description(null).outputSchema(schemaMapOutputSchema).annotations(null).build();
6060
}
6161
""");
6262
});
@@ -84,7 +84,7 @@ private io.modelcontextprotocol.spec.McpSchema.Tool schemaListToolSpec(com.githu
8484
schemaListOutputSchemaWrapped.put("type", "array");
8585
schemaListOutputSchemaWrapped.put("items", schemaListOutputSchemaMap);
8686
schemaListOutputSchema = schemaListOutputSchemaWrapped;
87-
return new io.modelcontextprotocol.spec.McpSchema.Tool("schemaList", null, null, this.json.convertValue(schema, io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), schemaListOutputSchema, null, null);
87+
return io.modelcontextprotocol.spec.McpSchema.Tool.builder("schemaList", this.json.convertValue(schema, java.util.Map.class)).title(null).description(null).outputSchema(schemaListOutputSchema).annotations(null).build();
8888
}
8989
""");
9090
});
@@ -109,7 +109,7 @@ private io.modelcontextprotocol.spec.McpSchema.Tool explicitSchemaToolSpec(com.g
109109
var explicitSchemaOutputSchemaNode = schemaGenerator.generateSchema(tests.i3830.Pet.class);
110110
var explicitSchemaOutputSchemaMap = this.json.convertValue(explicitSchemaOutputSchemaNode, java.util.Map.class);
111111
explicitSchemaOutputSchema = explicitSchemaOutputSchemaMap;
112-
return new io.modelcontextprotocol.spec.McpSchema.Tool("explicitSchema", null, null, this.json.convertValue(schema, io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), explicitSchemaOutputSchema, null, null);
112+
return io.modelcontextprotocol.spec.McpSchema.Tool.builder("explicitSchema", this.json.convertValue(schema, java.util.Map.class)).title(null).description(null).outputSchema(explicitSchemaOutputSchema).annotations(null).build();
113113
}
114114
""");
115115
});
@@ -136,7 +136,7 @@ private io.modelcontextprotocol.spec.McpSchema.Tool defaultSchemaToolSpec(com.gi
136136
var defaultSchemaOutputSchemaMap = this.json.convertValue(defaultSchemaOutputSchemaNode, java.util.Map.class);
137137
defaultSchemaOutputSchema = defaultSchemaOutputSchemaMap;
138138
}
139-
return new io.modelcontextprotocol.spec.McpSchema.Tool("defaultSchema", null, null, this.json.convertValue(schema, io.modelcontextprotocol.spec.McpSchema.JsonSchema.class), defaultSchemaOutputSchema, null, null);
139+
return io.modelcontextprotocol.spec.McpSchema.Tool.builder("defaultSchema", this.json.convertValue(schema, java.util.Map.class)).title(null).description(null).outputSchema(defaultSchemaOutputSchema).annotations(null).build();
140140
}
141141
""");
142142
});

modules/jooby-mcp/src/test/java/io/jooby/internal/mcp/McpExecutorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ void testToolErrorWithNullMessage() throws Throwable {
125125
Object result = executor.invoke(null, transportContext, operation, chain);
126126
McpSchema.CallToolResult toolResult = (McpSchema.CallToolResult) result;
127127
assertEquals(
128-
"Unknown error occurred", ((McpSchema.TextContent) toolResult.content().get(0)).text());
128+
"execution of test-op resulted in exception",
129+
((McpSchema.TextContent) toolResult.content().get(0)).text());
129130
}
130131

131132
private void checkMapping(Throwable t, StatusCode joobyCode, int expectedMcpCode)

modules/jooby-mcp/src/test/java/io/jooby/internal/mcp/transport/StreamableTransportProviderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ void testPost_Initialize_Success() throws Exception {
356356
when(body.valueOrNull()).thenReturn("body");
357357

358358
McpSchema.JSONRPCRequest req = mock(McpSchema.JSONRPCRequest.class);
359+
when(req.id()).thenReturn("operation-1");
359360
when(req.method()).thenReturn(McpSchema.METHOD_INITIALIZE);
360361

361362
try (MockedStatic<McpSchema> schema = mockStatic(McpSchema.class)) {
@@ -375,6 +376,7 @@ void testPost_Initialize_Success() throws Exception {
375376
Object res = postHandler.apply(ctx);
376377

377378
assertTrue(res instanceof McpSchema.JSONRPCResponse);
379+
assertEquals("operation-1", ((McpSchema.JSONRPCResponse) res).id());
378380
verify(ctx).setResponseHeader(HttpHeaders.MCP_SESSION_ID, "sess-init");
379381
}
380382
}

0 commit comments

Comments
 (0)