Skip to content

fix: do not omitempty ReadOnlyHint in ToolAnnotations#908

Open
pvlbzn wants to merge 1 commit intomodelcontextprotocol:mainfrom
pvlbzn:fix/do-not-omitempty-for-ReadOnlyHint
Open

fix: do not omitempty ReadOnlyHint in ToolAnnotations#908
pvlbzn wants to merge 1 commit intomodelcontextprotocol:mainfrom
pvlbzn:fix/do-not-omitempty-for-ReadOnlyHint

Conversation

@pvlbzn
Copy link
Copy Markdown

@pvlbzn pvlbzn commented Apr 24, 2026

ReadOnlyHint is a bool with omitempty, so the zero value (false) is indistinguishable from unset, and drops out of marshaled JSON.

The current behavior causes an issue with the OpenAI MCP app submission because they require explicit hints.

Consumers that explicitly set ReadOnlyHint: false on write tools lose the field on the wire. Removing omitempty ensures false is always serialized, which matches the MCP spec default.

ReadOnlyHint is a bare bool with omitempty, so the zero value (false)
is indistinguishable from unset and drops out of marshaled JSON.
Consumers that explicitly set ReadOnlyHint: false on write tools lose
the field on the wire. Removing omitempty ensures false is always
serialized, which matches the MCP spec default.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread mcp/protocol.go
// (This property is meaningful only when ReadOnlyHint == false.)
//
// Default: false
IdempotentHint bool `json:"idempotentHint,omitempty"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about removing the omitempty from here as well, to keep it consistent?

@maciej-kisiel
Copy link
Copy Markdown
Contributor

I would also suggest adding a new point to internal/docs/rough_edges.src.md (don't forget to run go generate ./...) that all hints should be been specified as *bool for full control of whether they are sent on the wire or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants