fix(validators): reject valueHint on named arguments#1339
Open
rinaldofesta wants to merge 1 commit into
Open
Conversation
valueHint identifies a positional slot for transport URL variable substitution, so it is only valid on positional arguments. The model carries ValueHint flat on Argument and validateArgument never checked it for named arguments, and the JSON schema does not catch it (the argument union branches do not set additionalProperties: false), so a named argument with a valueHint validated. Enforce it in the semantic validator with ErrValueHintOnNamedArgument (code valuehint-on-named-argument), with tests both directions. Closes modelcontextprotocol#662.
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.
Summary
Closes #662.
valueHintidentifies a positional slot for transport URL variable substitution, so it belongs only on positional arguments. Right now nothing stops a named argument from carrying one: the model holdsValueHintflat onArgument(pkg/model/types.go), andvalidateArgumentchecks the name and value fields for named arguments but not the hint.The JSON schema does not catch it either.
valueHintis declared onPositionalArgumentonly, butArgumentis ananyOfunion and neither branch setsadditionalProperties: false, so a named argument with avalueHintstill validates against theNamedArgumentbranch. That leaves the semantic validator as the enforcement point.Change
ErrValueHintOnNamedArgument.validateArgument, reject a non-emptyValueHinton a named argument (codevaluehint-on-named-argument), beside the existing named-argument checks.valueHintis rejected; a positional argument with avalueHintstays valid.The check is additive and matches the schema's positional-only declaration, so existing valid data is unaffected. I kept this at the validator level rather than tightening the generated schema, which felt like the smaller change; happy to put
additionalProperties: falseon the argument branches instead if you'd rather the schema carry it.Test
go test ./internal/validators/...passes.