Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -765,22 +764,11 @@ void testJsonSchema() throws Exception {
}
""";

// Deserialize the original string to a JsonSchema object
Map<String, Object> schema = JSON_MAPPER.readValue(schemaJson, new TypeRef<HashMap<String, Object>>() {
});

// Serialize the object back to a string
String serialized = JSON_MAPPER.writeValueAsString(schema);

// Deserialize again
Map<String, Object> deserialized = JSON_MAPPER.readValue(serialized, new TypeRef<HashMap<String, Object>>() {
});

// 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
Expand Down Expand Up @@ -810,22 +798,11 @@ void testJsonSchemaWithDefinitions() throws Exception {
}
""";

// Deserialize the original string to a JsonSchema object
Map<String, Object> schema = JSON_MAPPER.readValue(schemaJson, new TypeRef<HashMap<String, Object>>() {
});

// Serialize the object back to a string
String serialized = JSON_MAPPER.writeValueAsString(schema);

// Deserialize again
Map<String, Object> deserialized = JSON_MAPPER.readValue(serialized, new TypeRef<HashMap<String, Object>>() {
});

// 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
Expand Down Expand Up @@ -922,10 +899,9 @@ void testToolWithMeta() throws Exception {
}
""";

Map<String, Object> inputSchema = Map.of("inputSchema", schemaJson);
Map<String, Object> 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)
Expand Down