From e834d1bf357d3368ef9ac9bd0a4233996bf7b68a Mon Sep 17 00:00:00 2001 From: Ilya Muromtsev Date: Mon, 28 Sep 2026 20:27:10 +0300 Subject: [PATCH] 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 --- .../spec/McpSchemaTests.java | 42 ++++--------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java b/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java index ab9bc8643..29ac3a19a 100644 --- a/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java +++ b/mcp-test/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Map; -import io.modelcontextprotocol.json.TypeRef; import io.modelcontextprotocol.spec.McpSchema.TextResourceContents; import net.javacrumbs.jsonunit.core.Option; import org.assertj.core.api.InstanceOfAssertFactories; @@ -765,22 +764,11 @@ void testJsonSchema() throws Exception { } """; - // Deserialize the original string to a JsonSchema object - Map schema = JSON_MAPPER.readValue(schemaJson, new TypeRef>() { - }); - - // Serialize the object back to a string - String serialized = JSON_MAPPER.writeValueAsString(schema); - - // Deserialize again - Map deserialized = JSON_MAPPER.readValue(serialized, new TypeRef>() { - }); - - // Serialize one more time and compare with the first serialization - String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized); + McpSchema.Tool tool = JSON_MAPPER.readValue(""" + {"name": "addressTool", "inputSchema": %s} + """.formatted(schemaJson), McpSchema.Tool.class); - // The two serialized strings should be the same - assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized)); + assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson)); } @Test @@ -810,22 +798,11 @@ void testJsonSchemaWithDefinitions() throws Exception { } """; - // Deserialize the original string to a JsonSchema object - Map schema = JSON_MAPPER.readValue(schemaJson, new TypeRef>() { - }); - - // Serialize the object back to a string - String serialized = JSON_MAPPER.writeValueAsString(schema); - - // Deserialize again - Map deserialized = JSON_MAPPER.readValue(serialized, new TypeRef>() { - }); - - // Serialize one more time and compare with the first serialization - String serializedAgain = JSON_MAPPER.writeValueAsString(deserialized); + McpSchema.Tool tool = JSON_MAPPER.readValue(""" + {"name": "addressTool", "inputSchema": %s} + """.formatted(schemaJson), McpSchema.Tool.class); - // The two serialized strings should be the same - assertThatJson(serializedAgain).when(Option.IGNORING_ARRAY_ORDER).isEqualTo(json(serialized)); + assertThatJson(JSON_MAPPER.writeValueAsString(tool)).inPath("$.inputSchema").isEqualTo(json(schemaJson)); } @Test @@ -922,10 +899,9 @@ void testToolWithMeta() throws Exception { } """; - Map inputSchema = Map.of("inputSchema", schemaJson); Map meta = Map.of("metaKey", "metaValue"); - McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", inputSchema) + McpSchema.Tool tool = McpSchema.Tool.builder("addressTool", JSON_MAPPER, schemaJson) .title("addressTool") .description("Handles addresses") .meta(meta)