Skip to content

Commit e834d1b

Browse files
committed
test: Make Tool inputSchema tests exercise McpSchema.Tool
testJsonSchema and testJsonSchemaWithDefinitions only round-tripped a HashMap through Jackson since JsonSchema was replaced by Map in #749, so no SDK change could fail them. They now deserialize the schema as a Tool inputSchema and compare the serialized inputSchema with the original document. testToolWithMeta passed Map.of("inputSchema", schemaJson), which is not a schema; it now builds the tool from the parsed schema JSON. Stale comments describing the old JsonSchema round trip are removed. Signed-off-by: Ilya Muromtsev <let4time@gmail.com>
1 parent c7fef64 commit e834d1b

1 file changed

Lines changed: 9 additions & 33 deletions

File tree

‎mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java‎

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.List;
1212
import java.util.Map;
1313

14-
import io.modelcontextprotocol.json.TypeRef;
1514
import io.modelcontextprotocol.spec.McpSchema.TextResourceContents;
1615
import net.javacrumbs.jsonunit.core.Option;
1716
import org.assertj.core.api.InstanceOfAssertFactories;
@@ -765,22 +764,11 @@ void testJsonSchema() throws Exception {
765764
}
766765
""";
767766

768-
// Deserialize the original string to a JsonSchema object
769-
Map<String, Object> schema = JSON_MAPPER.readValue(schemaJson, new TypeRef<HashMap<String, Object>>() {
770-
});
771-
772-
// Serialize the object back to a string
773-
String serialized = JSON_MAPPER.writeValueAsString(schema);
774-
775-
// Deserialize again
776-
Map<String, Object> deserialized = JSON_MAPPER.readValue(serialized, new TypeRef<HashMap<String, Object>>() {
777-
});
778-
779-
// Serialize one more time and compare with the first serialization
780-
String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized);
767+
McpSchema.Tool tool = JSON_MAPPER.readValue("""
768+
{"name": "addressTool", "inputSchema": %s}
769+
""".formatted(schemaJson), McpSchema.Tool.class);
781770

782-
// The two serialized strings should be the same
783-
assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized));
771+
assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson));
784772
}
785773

786774
@Test
@@ -810,22 +798,11 @@ void testJsonSchemaWithDefinitions() throws Exception {
810798
}
811799
""";
812800

813-
// Deserialize the original string to a JsonSchema object
814-
Map<String, Object> schema = JSON_MAPPER.readValue(schemaJson, new TypeRef<HashMap<String, Object>>() {
815-
});
816-
817-
// Serialize the object back to a string
818-
String serialized = JSON_MAPPER.writeValueAsString(schema);
819-
820-
// Deserialize again
821-
Map<String, Object> deserialized = JSON_MAPPER.readValue(serialized, new TypeRef<HashMap<String, Object>>() {
822-
});
823-
824-
// Serialize one more time and compare with the first serialization
825-
String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized);
801+
McpSchema.Tool tool = JSON_MAPPER.readValue("""
802+
{"name": "addressTool", "inputSchema": %s}
803+
""".formatted(schemaJson), McpSchema.Tool.class);
826804

827-
// The two serialized strings should be the same
828-
assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized));
805+
assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson));
829806
}
830807

831808
@Test
@@ -922,10 +899,9 @@ void testToolWithMeta() throws Exception {
922899
}
923900
""";
924901

925-
Map<String, Object> inputSchema = Map.of("inputSchema", schemaJson);
926902
Map<String, Object> meta = Map.of("metaKey", "metaValue");
927903

928-
McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", inputSchema)
904+
McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", JSON_MAPPER, schemaJson)
929905
.title("addressTool")
930906
.description("Handles addresses")
931907
.meta(meta)

0 commit comments

Comments
 (0)