Skip to content

jsonschema reporting type "object" that should be "string" for nested time.Time struct #467

@iwyrkore

Description

@iwyrkore

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:

  1. 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
}
  1. 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"}
  1. 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

No one assigned

    Labels

    documentation/errorsImprovements or additions to documentation or error messages.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions