Skip to content

Question: How to omit annotations when not explicitly set? #710

@S-Reagan

Description

@S-Reagan

Question

Is there a way to create tools where the annotations field is only included in JSON output when annotations are explicitly provided?

Current Behavior

NewTool() initializes annotations with defaults, and MarshalJSON() always includes them:

{
  "name": "my_tool",
  "inputSchema": {...},
  "annotations": {
    "readOnlyHint": false,
    "destructiveHint": true,
    "idempotentHint": false,
    "openWorldHint": true
  }
}

Desired Behavior

For tools where I don't have annotation metadata, I'd like to omit the field entirely:

{
  "name": "my_tool",
  "inputSchema": {...}
}

This would let clients distinguish between "explicitly annotated" vs "no annotation data available."

Potential Approaches

  1. A new option like WithoutDefaultAnnotations()
  2. Conditional serialization in MarshalJSON() when all fields are nil/empty

Happy to implement if there's interest. What approach would fit best?

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