feat!: guard required MCP spec fields against null#928
Draft
chemicL wants to merge 3 commits intojson-compatibilityfrom
Draft
feat!: guard required MCP spec fields against null#928chemicL wants to merge 3 commits intojson-compatibilityfrom
chemicL wants to merge 3 commits intojson-compatibilityfrom
Conversation
Records in McpSchema whose fields the MCP spec marks as required were storing them as nullable Java types with no validation. A caller constructing one of these records with null for a required field would silently produce invalid wire JSON because @JsonInclude(NON_ABSENT) omits null values without complaint. Compact canonical constructors with Assert.notNull are added to seven records: - JSONRPCError (code, message), - ProgressNotification (progressToken, progress), - LoggingMessageNotification (level, data), - CreateMessageRequest (messages, maxTokens), - CallToolResult (content), - SamplingMessage (role, content), - ElicitRequest (message, requestedSchema). Test code that constructed these records without required fields was updated to supply valid values; those tests were testing capability-check or error-path logic that fires after construction, so the missing fields were incidental rather than intentional. Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
Deprecate no-arg builder() factories and Builder() constructors on CreateMessageRequest, ElicitRequest, and LoggingMessageNotification. Add new builder(required...) factories that validate required fields upfront. Add new builders for ProgressNotification and JSONRPCError. Null checks in private constructors and required-field setters ensure invalid state cannot be introduced at any point in the builder chain. Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
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.
Compact canonical constructors with Assert.notNull are added to seven records:
This PR is stacked on top of #927
Motivation and Context
Records in McpSchema whose fields the MCP spec marks as required were storing them as nullable Java types with no validation. A caller constructing one of these records with null for a required field would silently produce invalid wire JSON because @JsonInclude(NON_ABSENT) omits null values without complaint.
How Has This Been Tested?
Test code that constructed these records without required fields was updated to supply valid values; those tests were testing capability-check or error-path logic that fires after construction, so the missing fields were incidental rather than intentional.
Breaking Changes
Behavioural - validation failures for required fields that turn out to be null or missing.
Types of changes
Checklist