feat(validator): explicit description max-length feedback (#1184)#1267
Open
rhinocap wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
feat(validator): explicit description max-length feedback (#1184)#1267rhinocap wants to merge 2 commits intomodelcontextprotocol:mainfrom
rhinocap wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…xtprotocol#1184) Replaces the upstream jsonschema library's terse `length must be <= N, but got M` message with an explicit, actionable error that names the offending field, restates the limit, and includes a truncated value the publisher can paste back. Applies to any string field that has a maxLength constraint, but the trigger case from the issue is `description` (max 100). Example output: field "description" is too long: 312 chars (max 100). Truncate to: "<first 97 chars>..." Adds unit tests for the new message format plus the truncation and field-name helpers (rune-safe truncation included). Closes modelcontextprotocol#1184
Author
|
Hey @rdimitrov — CI is green and the PR is mergeable. Happy to defer, split, or merge as-is per your preference. Let me know how you'd like to proceed. |
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.
Closes #1184
Why
Today when a publisher submits a
server.jsonwith a description (or any string field) over the schema'smaxLength, they get the upstream jsonschema library's terse phrasing:…with no field name in the message itself, and no concrete suggestion of what to send instead. The reporter on #1184 had to discover the 100-char limit by trial and error.
What
Rewrites the message in
addDetailedErrorsto be self-contained and actionable:Done by detecting
maxLengtherrors viaKeywordLocationsuffix, looking up the offending value atInstanceLocation, and emitting an explicit message with field name, observed length, max, and a rune-safe truncation hint that fits withinmaxLength. Applies to any string field with amaxLengthconstraint —descriptionis just the trigger case.The bracket path (e.g.
description) is still set asIssue.Path, so any tooling that reads the structuredValidationIssueis unaffected.Test plan
TestValidateServerJSON_MaxLengthFeedbackconstructs a server.json with a 312-char description and asserts the new message format (field name, observed length, max, truncation suggestion ending in..., and absence of the raw jsonschema phrasing).TestExtractFieldNamecovers leaf-name extraction from bracket paths.TestTruncateForSuggestioncovers the rune-safe truncation helper, including unicode and very-smallmaxLen.go test ./internal/validators/...passes locally.go build ./...clean.golangci-lint runno new findings (baseline 51 issues unchanged).