The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Mark MCP write and delivery tools as destructive and open-world (#84362)
Chris Truter4fb635c69f2b
diff --git a/docs/ai/mcp-tools.md b/docs/ai/mcp-tools.mdindex cbaa0e08dc3..ca4329954fc 100644--- a/docs/ai/mcp-tools.md+++ b/docs/ai/mcp-tools.md@@ -23,7 +23,7 @@ Your agent will use `execute_query` for anything Metabase's query language can e- Tool name: `alert_write`- Permission scope: `agent:delivery:write` — Set up scheduled delivery of your data to email addresses and Slack channels it chooses-- Creates or changes content.+- Can overwrite or delete existing data or content.Arguments:@@ -43,7 +43,7 @@ Arguments:- Tool name: `bookmark_content`- Permission scope: `agent:content:write` — Create, edit and trash Metabase content-- Creates or changes content.+- Can overwrite or delete existing data or content.- Running it again with the same arguments has the same effect as running it once.Arguments:@@ -147,7 +147,7 @@ Arguments:- Tool name: `document_write`- Permission scope: `agent:content:write` — Create, edit and trash Metabase content-- Creates or changes content.+- Can overwrite or delete existing data or content.Arguments:@@ -415,7 +415,7 @@ Arguments:- Tool name: `subscription_write`- Permission scope: `agent:delivery:write` — Set up scheduled delivery of your data to email addresses and Slack channels it chooses-- Creates or changes content.+- Can overwrite or delete existing data or content.Arguments:diff --git a/src/metabase/cmd/mcp_tools_dox.clj b/src/metabase/cmd/mcp_tools_dox.cljindex 00a0c10f4b2..2719cf6f9d8 100644--- a/src/metabase/cmd/mcp_tools_dox.clj+++ b/src/metabase/cmd/mcp_tools_dox.clj@@ -149,7 +149,7 @@"The bullet for each [[tool-effect]]."{:read-only "Read-only.":destructive "Can overwrite or delete existing data or content."- ;; a hint, not a contract: `document_write` carries it and rewrites whole bodies+ ;; `destructiveHint false` is only a hint, so this promises nothing about what a writer won't touch:writes "Creates or changes content."})(defn- facts-bulletsdiff --git a/src/metabase/mcp/v2/registry.clj b/src/metabase/mcp/v2/registry.cljindex 2af7a385b18..a9415f16ee0 100644--- a/src/metabase/mcp/v2/registry.clj+++ b/src/metabase/mcp/v2/registry.clj@@ -224,8 +224,9 @@(def ^:private default-annotations"`readOnlyHint`, `destructiveHint`, and `openWorldHint` are always present — some MCP clients- (e.g. the ChatGPT Apps SDK) reject tools that omit them. `openWorldHint` is false because- Metabase tools stay within the user's own instance."+ (e.g. the ChatGPT Apps SDK) reject tools that omit them.+ `openWorldHint` defaults to false because most tools stay inside the user's own Metabase.+ A tool that sends outside it sets it to true."{:readOnlyHint false:destructiveHint false:openWorldHint false})diff --git a/src/metabase/mcp/v2/tools/alert.clj b/src/metabase/mcp/v2/tools/alert.cljindex 99d728e4802..5308657fec5 100644--- a/src/metabase/mcp/v2/tools/alert.clj+++ b/src/metabase/mcp/v2/tools/alert.clj@@ -481,7 +481,9 @@{:name "alert_write":default-access :allowed:scope metabot.scope/agent-delivery-write- :annotations {:readOnlyHint false :destructiveHint false}+ ;; `destructiveHint`: an update can replace the recipients.+ ;; `openWorldHint`: it sends to email addresses and Slack channels outside Metabase.+ :annotations {:readOnlyHint false, :destructiveHint true, :openWorldHint true}:args alert-write-args-schema}[args {:keys [token-scopes]}](let [[op a b] (v2.write/dispatch-write {:create-required [:card_id :schedule]} args)]diff --git a/src/metabase/mcp/v2/tools/bookmark.clj b/src/metabase/mcp/v2/tools/bookmark.cljindex 1fbf3f3e966..b78601b48d6 100644--- a/src/metabase/mcp/v2/tools/bookmark.clj+++ b/src/metabase/mcp/v2/tools/bookmark.clj@@ -80,7 +80,8 @@{:name "bookmark_content":default-access :allowed:scope metabot.scope/agent-content-write- :annotations {:readOnlyHint false :destructiveHint false :idempotentHint true}+ ;; `destructiveHint`: `bookmarked: false` removes a bookmark.+ :annotations {:readOnlyHint false, :destructiveHint true, :idempotentHint true}:args bookmark-content-args-schema}[{:keys [type id bookmarked]} {:keys [token-scopes]}](let [row (fetch-item type id)diff --git a/src/metabase/mcp/v2/tools/document.clj b/src/metabase/mcp/v2/tools/document.cljindex d685f7d537d..c0e8aa67397 100644--- a/src/metabase/mcp/v2/tools/document.clj+++ b/src/metabase/mcp/v2/tools/document.clj@@ -536,7 +536,8 @@{:name "document_write":default-access :allowed:scope metabot.scope/agent-content-write- :annotations {:readOnlyHint false :destructiveHint false}+ ;; `destructiveHint`: `archived: true` trashes the document, and a full-body rewrite orphans its comments.+ :annotations {:readOnlyHint false, :destructiveHint true}:args document-write-args-schema}[args {:keys [token-scopes]}](let [[op a b] (v2.write/dispatch-writediff --git a/src/metabase/mcp/v2/tools/subscription.clj b/src/metabase/mcp/v2/tools/subscription.cljindex 9ecfdd13636..9ac77eb5782 100644--- a/src/metabase/mcp/v2/tools/subscription.clj+++ b/src/metabase/mcp/v2/tools/subscription.clj@@ -494,7 +494,9 @@{:name "subscription_write":default-access :allowed:scope metabot.scope/agent-delivery-write- :annotations {:readOnlyHint false :destructiveHint false}+ ;; `destructiveHint`: `archived: true` trashes the subscription, and an update can replace the recipients.+ ;; `openWorldHint`: it sends to email addresses and Slack channels outside Metabase.+ :annotations {:readOnlyHint false, :destructiveHint true, :openWorldHint true}:args subscription-write-args-schema}[args {:keys [token-scopes]}](let [[op a b] (v2.write/dispatch-write subscription-write-entry args)diff --git a/test/metabase/cmd/mcp_tools_dox_test.clj b/test/metabase/cmd/mcp_tools_dox_test.cljindex 05a4d944150..95ae64dbc98 100644--- a/test/metabase/cmd/mcp_tools_dox_test.clj+++ b/test/metabase/cmd/mcp_tools_dox_test.clj@@ -69,8 +69,7 @@(deftest ^:parallel tool-effect-test(are [expected annotations] (= expected (#'mcp-tools-dox/tool-effect {:annotations annotations})):read-only {:readOnlyHint true}- ;; `destructiveHint false` is a hint: `document_write` carries it and rewrites whole bodies, so the page- ;; promises nothing about what a writer won't touch+ ;; `destructiveHint false` is only a hint, so the page promises nothing about what a writer won't touch:writes {:destructiveHint false}:destructive {:destructiveHint true};; the registry always merges `destructiveHint false` in, so a tool with neither hint is a writerdiff --git a/test/metabase/mcp/v2/registry_test.clj b/test/metabase/mcp/v2/registry_test.cljindex cdeed2f1797..c6fd5be092c 100644--- a/test/metabase/mcp/v2/registry_test.clj+++ b/test/metabase/mcp/v2/registry_test.clj@@ -5,12 +5,12 @@[clojure.test :refer :all][metabase.api-scope.core :as api-scope][metabase.mcp.usage :as mcp.usage]+ ;; Required for its side effect: loading it loads every tool namespace, which registers itself.+ [metabase.mcp.v2.api][metabase.mcp.v2.common :as common][metabase.mcp.v2.message :as message][metabase.mcp.v2.registry :as registry][metabase.mcp.v2.test-util :as v2.tu]- [metabase.mcp.v2.tools.query]- [metabase.mcp.v2.tools.search][metabase.test :as mt][metabase.util.json :as json]))@@ -427,6 +427,14 @@(testing tool-name(is (contains? mutating tool-name))))))))+(deftest delivery-tools-are-open-world-test+ (testing "delivery tools are open-world: they send to email addresses and Slack channels outside Metabase"+ (let [delivery (filter #(= "agent:delivery:write" (:scope %)) (@#'registry/manifest))]+ (is (seq delivery))+ (doseq [{tool-name :name :keys [annotations]} delivery]+ (testing tool-name+ (is (true? (:openWorldHint annotations))))))))+(deftest mutating-tools-gate-on-a-write-scope-test(testing "every mutating tool gates on one of the write scopes, so a token can be granted readaccess without also being able to change anything"