-
Notifications
You must be signed in to change notification settings - Fork 273
Closed
Labels
documentation/errorsImprovements or additions to documentation or error messages.Improvements or additions to documentation or error messages.
Milestone
Description
Describe the bug
A struct containing an embedded time.Time is reported by jsonschema to be of type object but it gets marshalled to JSON as string.
To Reproduce
Steps to reproduce the behavior:
- Create a tool:
type MyDate struct {
time.Time
}
type MyToolArgs struct {
Date MyDate `json:"date" jsonschema:"The date"`
}
type MyToolResponse struct {
Date MyDate `json:"date" jsonschema:"The date"`
}
var MyTool = mcp.Tool{
Name: "MyTool",
Description: "My tool",
}
func MyToolHandler(
ctx context.Context,
req *mcp.CallToolRequest,
args MyToolArgs) (*mcp.CallToolResult, *MyToolResponse, error) {
return &mcp.CallToolResult{
Content: []mcp.Content{&mcp.TextContent{Text: "Hello, world!"}},
}, &MyToolResponse{Date: args.Date}, nil
}
- Look at the JSON:
myToolArgs := MyToolArgs{
Date: tools.MyDate{Time: time.Date(2023, 11, 7, 0, 0, 0, 0, time.UTC)},
}
jsonBytes, err := json.Marshal(myToolArgs)
fmt.Println(string(jsonBytes))
// output: {"date":"2023-11-07T00:00:00Z"}
- Look at the schema:
{"description":"My tool","inputSchema":{"type":"object","required":["date"],"properties":{"date":{"type":"object","description":"The date","additionalProperties":false}},"additionalProperties":false},"name":"MyTool","outputSchema":{"type":"object","required":["date"],"properties":{"date":{"type":"object","description":"The date","additionalProperties":false}},"additionalProperties":false}}
Expected behavior
Schema would contain type "string" for "date"
(This example may seem a bit contrived but the real-world MyDate marshals to a "YYYY-MM-DD" format with the same problem.)
Metadata
Metadata
Assignees
Labels
documentation/errorsImprovements or additions to documentation or error messages.Improvements or additions to documentation or error messages.