Fix MCP tool output schemas to match actual serialized output#26556
Open
monrax wants to merge 5 commits into
Open
Fix MCP tool output schemas to match actual serialized output#26556monrax wants to merge 5 commits into
monrax wants to merge 5 commits into
Conversation
The generated outputSchema for MCP tools did not match what the server actually serializes, so schema-validating MCP clients rejected every search_messages, aggregate_messages, and list_fields response: - Joda DateTime was described as a bare object instead of an ISO-8601 string (effective_timerange.from/to) - java.lang.Object (TabularResponse datarows cells) was stamped "type": "object" by EmptyObjectAsObjectModule instead of remaining unconstrained - @nullable fields (e.g. MappedFieldTypeDTO#unit) were not declared nullable although they serialize as null Add a DateTimeAsStringModule mapping date/time types to {"type": "string", "format": "date-time"}, skip java.lang.Object in EmptyObjectAsObjectModule, and honor javax/jakarta @nullable via a nullable check in SchemaGeneratorProvider. A new round-trip test validates serialized tool output against the generated schemas using the MCP SDK's own JsonSchemaValidator. Co-Authored-By: Claude Fable 5 <[EMAIL_ADDRESS_REDACTED]>
8426a5a to
1cce41c
Compare
Validate structuredContent payloads captured verbatim from a live server against the generated schemas. Unlike the round-trip tests, which prove generator and serializer are consistent with each other, these pin the wire format itself and fail if both sides ever drift together. Co-Authored-By: Claude Fable 5 <[EMAIL_ADDRESS_REDACTED]>
Validate an ISO-8601 date-time JSON value against the generated schema for a metadata timerange, and assert that epoch millis and objects (the shape the schema wrongly declared before the fix) are rejected. Co-Authored-By: Claude Fable 5 <[EMAIL_ADDRESS_REDACTED]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The MCP
outputSchemagenerated for tool output types did not match what the server actually serializes, so MCP clients that validatestructuredContentagainst the advertised schema (the official MCP SDKs do) rejected everysearch_messages,aggregate_messages, andlist_fieldsresponse. Three mismatches, all fixed at the schema-generator level (SchemaGeneratorProvider/ victools config):DateTime→{"type": "object"}:effective_timerange.from/.toserialize as ISO-8601 strings. A newDateTimeAsStringModulemaps date/time types (JodaReadableInstant,java.util.Date,java.timeinstant types, i.e. everything the object mapper writes as ISO-8601 strings) to{"type": "string", "format": "date-time"}java.lang.Object→{"type": "object", "properties": {}}: the cells ofTabularResponse#datarows(List<List<Object>>) hold strings, numbers, or null.EmptyObjectAsObjectModulenow skipsjava.lang.Objectso it stays an unconstrained{}schema.@Nullablefields declared non-nullable: e.g.MappedFieldTypeDTO#unitserializes asnullfor most fields. A nullable check for javax/jakarta@Nullablenow produces e.g.{"type": ["object", "null"]}.A new round-trip test (
ToolOutputSchemaComplianceTest) generates schemas andstructuredContentexactly the wayTool/McpServicedo and validates one against the other using the MCP SDK's ownJsonSchemaValidatorso this class of mismatch can't silently regress.Motivation and Context
Fixes #23980
Fixes #25314
Fixes #26402
All three issues are the same underlying bug reported against different MCP clients (Strands agents, Claude Desktop, Claude Code). With
enable_output_schematurned on, the core search tools were unusable from any schema-validating client. The schema changes are strictly relaxing: every previously-valid payload remains valid, so nothing breaks for existing clients.How Has This Been Tested?
ToolOutputSchemaComplianceTest(round-trip schema-vs-serialization validation forTabularResponseandListFieldsTool.Result, plus targeted assertions for theDateTimeandObjectschema shapes).org.graylog.mcp.*test suite passes (McpServiceTest,McpRestResourceTest,MarkdownBuilderTest, resource provider tests).enable_output_schema: true: before the fix, exhaustive JSON-Schema validation ofstructuredContentagainst the advertisedoutputSchemaproduced errors on everysearch_messages/aggregate_messages/list_fieldscall; after the fix, zero validation errors across all four schema-advertising tools (includingget_system_status, confirming no regression).Screenshots (if appropriate):
N/A
Types of changes
Checklist:
🤖 Generated with Claude Code