Skip to content

fix(validators): reject valueHint on named arguments#1339

Open
rinaldofesta wants to merge 1 commit into
modelcontextprotocol:mainfrom
rinaldofesta:fix/valuehint-on-named-argument
Open

fix(validators): reject valueHint on named arguments#1339
rinaldofesta wants to merge 1 commit into
modelcontextprotocol:mainfrom
rinaldofesta:fix/valuehint-on-named-argument

Conversation

@rinaldofesta

Copy link
Copy Markdown

Summary

Closes #662.

valueHint identifies 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 holds ValueHint flat on Argument (pkg/model/types.go), and validateArgument checks the name and value fields for named arguments but not the hint.

The JSON schema does not catch it either. valueHint is declared on PositionalArgument only, but Argument is an anyOf union and neither branch sets additionalProperties: false, so a named argument with a valueHint still validates against the NamedArgument branch. That leaves the semantic validator as the enforcement point.

Change

  • Add ErrValueHintOnNamedArgument.
  • In validateArgument, reject a non-empty ValueHint on a named argument (code valuehint-on-named-argument), beside the existing named-argument checks.
  • Tests: a named argument with a valueHint is rejected; a positional argument with a valueHint stays 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: false on the argument branches instead if you'd rather the schema carry it.

Test

go test ./internal/validators/... passes.

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.
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.

Prevent valueHint from being submitted with NamedArguments

1 participant