Skip to content

fix: do not omitempty ReadOnlyHint in ToolAnnotations#908

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

fix: do not omitempty ReadOnlyHint in ToolAnnotations#908
pvlbzn wants to merge 9 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
@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 👍

guglielmo-san
guglielmo-san previously approved these changes May 4, 2026
@maciej-kisiel
Copy link
Copy Markdown
Contributor

One last thing: I believe this is a behavior change that may result for example in breaking tests of our users. Given that, I would introduce a MCPGODEBUG flag to be able to temporarily revert to previous behavior. Please look for usages of mcpgodebug on how to set this up.

@pvlbzn
Copy link
Copy Markdown
Author

pvlbzn commented May 5, 2026

Great call @maciej-kisiel , implemented compatibility mechanism according to mcpgodebug, and updated documentation.

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