Skip to content

test: Make Tool inputSchema tests exercise McpSchema.Tool - #1145

Open
imuromtsev wants to merge 1 commit into
modelcontextprotocol:mainfrom
imuromtsev:imuromtsev/meaningful-tool-schema-tests
Open

imuromtsev wants to merge 1 commit into
modelcontextprotocol:mainfrom
imuromtsev:imuromtsev/meaningful-tool-schema-tests

Conversation

@imuromtsev

Copy link
Copy Markdown

Test-only follow-up to #749. After JsonSchema was replaced by Map<String, Object>, three tests in McpSchemaTests stopped checking what they were named for:

  • testJsonSchema and testJsonSchemaWithDefinitions only round-trip a HashMap through Jackson, so no change to McpSchema can fail them. Their comments still say "Deserialize the original string to a JsonSchema object". They now deserialize {"name": …, "inputSchema": <schema>} into McpSchema.Tool and assert that the serialized $.inputSchema equals the original schema document, so $defs and definitions are checked end to end through the record.
  • testToolWithMeta passed Map.of("inputSchema", schemaJson) as the input schema: a one-key map holding the whole schema as a string, which is not a schema. It now uses Tool.builder(name, JSON_MAPPER, schemaJson), like testTool and testToolWithComplexSchema.
  • The outdated comments are removed, together with the now-unused TypeRef import.

No production code changes.

Verification

  • ./mvnw -pl mcp-test -am -Dtest=McpSchemaTests test with -Pjackson2 and -Pjackson3 (JDK 21): 186 tests, 0 failures, 0 errors each; spring-javaformat:validate passes.
  • Mutation check that the rewritten tests can fail (reverted, not in the commit):
    • renaming the inputSchema property in Tool.fromJson fails testJsonSchema and testJsonSchemaWithDefinitions (missing: $.inputSchema.$defs / $.inputSchema.definitions); before this change both passed under the same mutation, since they never touched Tool;
    • dropping meta in Tool.Builder.meta fails testToolWithMeta.

A draft-07 definitions schema deserializes into Tool without any validation error: the 2020-12 meta-schema check (SEP-1613) runs only when a server registers a tool, not during deserialization.

Prepared with an AI coding agent and reviewed by me.

testJsonSchema and testJsonSchemaWithDefinitions only round-tripped a HashMap through Jackson since JsonSchema was replaced by Map in modelcontextprotocol#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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant