Skip to content

bug: ToolAnnotations cannot have false values #259

@pottekkat

Description

@pottekkat

ToolAnnotation allows defining annotations as specified in https://modelcontextprotocol.io/docs/concepts/tools#tool-annotations

But right now, it is impossible to explicitly set false values to any of the annotations through the ToolAnnotation struct.

For example, if I set:

...
mcp.WithToolAnnotation(mcp.ToolAnnotation{
	Title:           "tool name",
	ReadOnlyHint:    false,
	DestructiveHint: true,
	IdempotentHint:  true,
	OpenWorldHint:   false,
}),

The resulting annotations in JSON returned by the server would only be:

...
annotations: {
  title: "tool name",
  destructiveHint: true,
  idempotentHint: true,
}

which does not contain the false values.

This is because when you Marshal the JSON, because of the omitempty option, it omits boolean fields with false values as described in its docs:

https://pkg.go.dev/encoding/json#Marshal
The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any array, slice, map, or string of length zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions