Skip to content

feat: core agent-level suppression for read-only tools - #3615

Merged
anubhav756 merged 1 commit into
feat/read-onlyfrom
anubhav-readonly-core
Aug 27, 2026
Merged

anubhav756 merged 1 commit into
feat/read-onlyfrom
anubhav-readonly-core

Conversation

@anubhav756

@anubhav756 anubhav756 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR introduces core framework support for agent-level tool suppression and dynamic annotations in read-only mode.

When a data source or admin service is configured as readonly: true, write-capable and destructive tools bound to that source are automatically suppressed from tool registration and pruned from tool groups. This saves valuable LLM agent context window space, eliminates agent confusion by preventing tool hallucination/misuse on read-only resources, and acts as a defense-in-depth layer in conjunction with database-level session locking.

Design

  1. sources.Source Interface Extension:

    • Added IsReadOnly() bool to the sources.Source interface.
    • Implemented IsReadOnly() across all existing data source drivers (50+ sources).
    • Added readonly configuration support to alloydb-admin and cloud-sql-admin sources.
  2. Tool Suppression Protocol:

    • Added ShouldSuppress(sources.Source) bool to the tools.Tool interface.
    • In BaseTool, default suppression logic checks if the bound source is in read-only mode and suppresses any tool whose ReadOnlyHint annotation is false.
    • Read-only tools (ReadOnlyHint == true) and unannotated tools are preserved (with a warning logged for unannotated tools to encourage explicit annotation).
    • Tools like postgresexecutesql and mysqlexecutesql override ShouldSuppress to remain enabled because they enforce read-only semantics at the database connection/session level.
  3. Server-Level Tool Filtering & Group Pruning:

    • During tool initialization (initializeTools), write-capable tools bound to read-only sources are suppressed and omitted from the server's registered tools map with an informative log.
    • During group initialization (initializeGroups), suppressed tools are cleanly pruned from configured groups while keeping the group intact and preserving standard validation errors for genuinely missing tools.
  4. Dynamic Tool Annotations in MCP Manifests:

    • Updated MCP version manifests (v20241105, v20250326, v20250618, v20251125, v20260728) to query tool.Manifest(src) dynamically.
  5. Cloud SQL PG Vector Assist Annotations:

    • Updated vector assist tools (vectorassistapplyspec, vectorassistdefinespec, vectorassistgeneratequery, vectorassistgetspec, vectorassistimprovequeryrecall, vectorassistlistspecs, vectorassistmodifyspec) with annotations (ReadOnlyAnnotations vs DestructiveAnnotations) and support for custom YAML annotations.

PR Checklist

  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a mechanism to automatically suppress write-capable tools when their associated data source is configured in read-only mode. It defines a new ReadOnlySource interface, updates the tool initialization logic to inspect tool annotations (specifically readOnlyHint), and logs warnings for unannotated tools bound to read-only sources. The reviewer highlighted a potential startup failure when a suppressed tool is explicitly referenced in a configured toolset and IgnoreUnknownTools is false, suggesting that suppressed tools should be automatically filtered out from toolsets during initialization.

Comment thread internal/server/server.go Resolved
@anubhav756

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request introduces a mechanism to automatically suppress write-capable tools when their bound data source is configured in read-only mode, saving the agent's context window. It adds a ReadOnlySource interface, implements suppression logic in initializeTools using reflection, filters suppressed tools from toolsets, and updates the documentation and tests accordingly. Feedback was provided regarding mutating the cfg.ToolsetConfigs map directly in InitializeConfigs, which can cause side effects since maps are reference types in Go; it is recommended to copy the map before modifying it.

Comment thread internal/server/server.go Resolved
@anubhav756
anubhav756 marked this pull request as ready for review July 14, 2026 13:24
@anubhav756
anubhav756 requested a review from a team as a code owner July 14, 2026 13:24
@anubhav756 anubhav756 assigned Yuan325 and unassigned anubhav756 Jul 14, 2026
Comment thread internal/server/readonly_tools_test.go Resolved
Comment thread internal/server/readonly_tools_test.go Resolved
Comment thread internal/server/readonly_tools_test.go Resolved
Comment thread internal/server/server.go Resolved
Comment thread internal/server/server.go Resolved
Comment thread internal/server/server.go Resolved
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from 9e34992 to eec1dfb Compare July 20, 2026 12:05
@anubhav756
anubhav756 requested review from a team as code owners July 20, 2026 12:05
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 3 times, most recently from cd8b2df to 7ebdddb Compare July 20, 2026 13:33
@anubhav756
anubhav756 requested a review from Yuan325 July 20, 2026 13:52
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 5 times, most recently from 8011f00 to 1b964a1 Compare July 21, 2026 10:56
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 8 times, most recently from 9a9af5f to 7930439 Compare August 11, 2026 13:59

@Yuan325 Yuan325 left a comment

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.

Thank you! Please lmk if you have any questions on the comments

Comment thread internal/server/server.go Resolved
Comment thread internal/server/server.go Resolved
Comment thread internal/testutils/mocks.go Resolved
Comment thread internal/testutils/mocks.go Resolved
Comment thread internal/testutils/mocks.go Resolved
Comment thread internal/tools/tools.go Resolved
Comment thread internal/tools/tools_test.go Resolved
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 4 times, most recently from 6040eed to b165fbc Compare August 12, 2026 14:16
@anubhav756
anubhav756 requested a review from Yuan325 August 12, 2026 14:19
Comment thread internal/testutils/mocks.go Resolved
Comment thread internal/testutils/mocks.go Resolved
Comment thread internal/server/server_test.go Resolved
Comment thread internal/server/server_test.go Resolved
Comment thread internal/server/server_test.go Resolved
Comment thread internal/server/server_test.go Resolved
Comment thread internal/server/server_test.go Resolved
Comment thread internal/server/server_test.go Resolved
@Yuan325

Yuan325 commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Are we still planning to update this: Enables multi-mode tools (like SQL execution tools) to dynamically report ReadOnlyHint: true and DestructiveHint: false in MCP tool manifests when connected to a read-only source.

@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 2 times, most recently from 89c827a to 32de615 Compare August 13, 2026 01:31
@anubhav756

Copy link
Copy Markdown
Contributor Author

Are we still planning to update this: Enables multi-mode tools (like SQL execution tools) to dynamically report ReadOnlyHint: true and DestructiveHint: false in MCP tool manifests when connected to a read-only source.

As mentioned in this comment, the multi-mode tool dynamic annotation was implemented in Manifest() but following the suggestion, I removed it from there, and have implemented in a follow up PR here: #3816

Comment thread internal/sources/bigquery/bigquery.go Resolved
Comment thread internal/sources/mysql/mysql.go Resolved
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Cloudflare Preview Ready!

🔎 View Preview: https://pr-3615.toolbox-docs-6xc.pages.dev

(Note: Subsequent pushes to this PR will automatically update the preview at this same URL)

@github-actions

Copy link
Copy Markdown
Contributor

🧨 Preview deployments removed.

Cloudflare Pages environments for pr-3615 have been deleted.

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

Labels

priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. release candidate Use label to signal PR should be included in the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants