Question: How to omit annotations when not explicitly set?
Author: S-ReaganCreated Jan 31, 2026Updated Jan 31, 2026
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
- A new option like
WithoutDefaultAnnotations() - Conditional serialization in
MarshalJSON()when all fields are nil/empty
Happy to implement if there's interest. What approach would fit best?
Source: mark3labs/mcp-go