Skip to content

Conversation

@matheuscscp
Copy link

@matheuscscp matheuscscp commented Nov 26, 2025

This change introduces a non-breaking API for passing options to mcp.AddTool(). The first option introduced is the jsonschema.ForOptions, which allows jsonschema to use a specified mapping of Go types to schemas defined by the caller, which are used instead of inference via reflection. This is very useful for example for Go structs implementing the MarshalJSON and UnmarshalJSON interfaces in order to represent the struct as a string. For example, imagine a MonthID struct containing Year and Month as integers, and whose serialization format implemented by MarshalJSON is YYYYMM. From the jsonschema perspective the type must be string, but the representation in Go can be rich through a struct.

Fixes #658

This change introduces a non-breaking API for passing
options to mcp.AddTool(). The first option introduced
is the jsonschema.ForOptions, which allows jsonschema
to use a specified mapping of Go types to static types
defined by the caller, which are used when generating
schemas instead inference via reflection. This is very
useful for example for Go structs implementing the
MarshalJSON and UnmarshalJSON interfaces in order to
represent the struct as a string. For example, imagine
a MonthID struct containing Year and Month as integers,
and whose serialization format implemented by MarshalJSON
is YYYYMM. From the jsonschema perspective the type
must be string, but the representation in Go can be
rich through a struct.

Fixes modelcontextprotocol#658

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
@findleyr
Copy link
Contributor

As I mentioned on the issue, this is a breaking change (a minor one, admittedly, but still a breaking change). Therefore, we'd have to only consider it for v2, which will happen eventually.

@findleyr
Copy link
Contributor

findleyr commented Dec 8, 2025

Have to decline this for now. The issue tracks reconsidering tool options in v2.

@findleyr findleyr closed this Dec 8, 2025
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.

Proposal: Support custom jsonschema type mappings

2 participants