Skip to content

fix: do not omitempty ReadOnlyHint in ToolAnnotations#908

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

fix: do not omitempty ReadOnlyHint in ToolAnnotations#908
pvlbzn wants to merge 3 commits 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 Outdated
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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, great take. This enables us to have symmetry: *bool are with omitempty since *bool is a ternary here, and bool are without omitempty, defaulting to false.

@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.

@pvlbzn
Copy link
Copy Markdown
Author

pvlbzn commented Apr 30, 2026

Thanks for the review and suggestions @maciej-kisiel @guglielmo-san. Updated the branch 👍

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