-
Notifications
You must be signed in to change notification settings - Fork 113
Description
Describe the bug
When using mcp.ToolHandlerFor
and a field with a custom JSON format (implementing json.Marshaler
, for example), the inferred schema will not match the resulting JSON output.
To Reproduce
Steps to reproduce the behavior:
- Define a struct with a custom JSON format, such as
time.Time
:type MyToolParams struct { MyTimestamp time.Time `json:"my_timestamp" jsonschema:"the timestamp for the tool call"` }
- Use the struct in a tool call:
func GetTime(ctx context.Context, cc *mcp.ServerSession, params *mcp.CallToolParamsFor[MyToolParams]) (*mcp.CallToolResultFor[MyToolParams], error) { return &mcp.CallToolResultFor[MyToolParams]{ StructuredContent: params, } }
When using the created endpoint, the schema will claim that my_timestamp
is an object, but of course the response will have my_timestamp
as a string.
Expected behavior
I'm not entirely sure what the solution is here, but this behavior was unexpected to me (since inference is mostly "just working").
Additional context
I think it's possible to work around this by specifying a custom InputSchema
and OutputSchema
when registering the tool. I'm mostly creating this so that we have a place to discuss this somewhat pointy edge that will likely hit many new users.