-
Notifications
You must be signed in to change notification settings - Fork 792
Description
Bug description
Based on specification Tool input schema follows the JSON schema usage guideline(https://modelcontextprotocol.io/specification/2025-11-25/basic#schema-dialect) that states the use of $schema field to specify explicit dialect and defaults to JSON Schema 2020-12 if the field is not present, however JsonSchema record used for defining inputSchema property in Tool does not include $schema property.
This causes the $schema property not to be included in the serialized response for tool/list request and may causes ambiguity for MCP clients when interpreting which schema version to use.
Steps to reproduce
Diff with test included in java-sdk/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java
diff --git a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java
index 82ffe9e..c943a40 100644
--- a/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java
+++ b/mcp-core/src/test/java/io/modelcontextprotocol/spec/McpSchemaTests.java
@@ -920,6 +920,53 @@ public class McpSchemaTests {
"""));
}
+ @Test
+ void testToolWithVersionedInputSchema() throws Exception {
+ String inputSchemaJson = """
+ {
+ "$schema": "https://json-schema.org/draft-07/schema#",
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "value": {
+ "type": "number"
+ }
+ },
+ "required": ["name"],
+ "additionalProperties": false
+ }
+ """;
+
+ McpSchema.Tool tool = McpSchema.Tool.builder()
+ .name("test-tool")
+ .description("A test tool")
+ .inputSchema(JSON_MAPPER, inputSchemaJson)
+ .build();
+
+ String value = JSON_MAPPER.writeValueAsString(tool);
+ assertThatJson(value).when(Option.IGNORING_ARRAY_ORDER)
+ .when(Option.IGNORING_EXTRA_ARRAY_ITEMS)
+ .isObject()
+ .isEqualTo(json("""
+ {
+ "name":"test-tool",
+ "description":"A test tool",
+ "inputSchema":{
+ "$schema":"https://json-schema.org/draft-07/schema#",
+ "type":"object",
+ "properties":{
+ "name":{"type":"string"},
+ "value":{"type":"number"}
+ },
+ "required":["name"],
+ "additionalProperties": false
+ }
+ }
+ """));
+ }
+
@Test
void testToolWithOutputSchema() throws Exception {
String inputSchemaJson = """
Expected behavior
$schema property included in tool inputSchema if implementation uses explicit JSON schema dialect