feat(core): dynamic tool annotations for multi-mode tools on read-only sources - #3816
Open
anubhav756 wants to merge 1 commit into
Open
feat(core): dynamic tool annotations for multi-mode tools on read-only sources#3816anubhav756 wants to merge 1 commit into
anubhav756 wants to merge 1 commit into
Conversation
Contributor
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 13, 2026 07:49
8930b29 to
53be9fe
Compare
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 13, 2026 08:14
53be9fe to
5fade7d
Compare
3 tasks
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 13, 2026 08:33
5fade7d to
f36035b
Compare
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
3 times, most recently
from
August 13, 2026 10:24
ee8f29a to
9dc7d07
Compare
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
2 times, most recently
from
August 13, 2026 13:11
dd8d903 to
2b6758a
Compare
Yuan325
requested changes
Aug 13, 2026
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 13, 2026 15:49
2b6758a to
43ada14
Compare
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 13, 2026 15:49
43ada14 to
d2f4003
Compare
Yuan325
approved these changes
Aug 13, 2026
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 14, 2026 06:05
d2f4003 to
a8b4325
Compare
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 14, 2026 15:11
a8b4325 to
1f3900f
Compare
anubhav756
force-pushed
the
anubhav-readonly-annotation
branch
from
August 17, 2026 05:45
1f3900f to
aa93c11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enables multi-mode tools (e.g., SQL execution tools) to dynamically advertise
readOnlyHint: trueanddestructiveHint: falsein MCP tool manifests when bound to a read-only data source, and centralizes tool suppression logic across the server.Context & Motivation
postgres-execute-sqlandmysql-execute-sqlare multi-mode (capable of both reads and writes) and default toreadOnlyHint: false/destructiveHint: true. When connected to areadOnly: truedatabase source (where session-level locks prevent modifications), these tools should dynamically reportreadOnlyHint: trueanddestructiveHint: falseto MCP clients without requiring separate read-only tool implementations.ShouldSuppressfrom aBaseToolmethod into a package-level functiontools.ShouldSuppress(ctx, t, src)that operates on theToolinterface, allowing suppression to dynamically evaluatet.GetAnnotations(src)without requiring concrete tool method overrides.Changes
Tool.GetAnnotations(sources.Source) *ToolAnnotationsto make annotations source-aware (matching the design pattern ofGetParameters(sources.Source)andManifest(sources.Source)).BaseTool.GetAnnotations(_ sources.Source)to return static annotations by default.DynamicReadOnlyAnnotations(base *ToolAnnotations) *ToolAnnotationsininternal/tools/tools.goto safely copy base annotations and setReadOnlyHint: true/DestructiveHint: falsewhile preserving other custom hints (e.g.idempotentHint,openWorldHint).postgres-execute-sqlandmysql-execute-sqlto implementGetAnnotations(src)usingtools.DynamicReadOnlyAnnotations(t.BaseTool.GetAnnotations(src))whensrc.IsReadOnly().ShouldSuppressmethod overrides from concrete SQL tool structs.v20241105,v20250326,v20250618,v20251125,v20260728) ininternal/server/mcp/to passsrcintotool.GetAnnotations(src).tools.DynamicReadOnlyAnnotationsininternal/tools/tools_test.goverifying nil handling, default flipping, custom hint preservation, and pointer immutability.internal/server/server_test.goandinternal/tools/tools_test.goto testtools.ShouldSuppresswith both write and destructive tools usingtools.NewWriteAnnotations()andtools.NewDestructiveAnnotations().tool.GetAnnotations(nil).