Skip to content

Tool input schema does not include $schema property #761

@vivekschauhan

Description

@vivekschauhan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions