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
drop disable mcp tools setting (#82533)
Aleksandr Lesnenko00232ddc3a81
diff --git a/src/metabase/mcp/settings.clj b/src/metabase/mcp/settings.cljindex 18f62367f79..91faf986b75 100644--- a/src/metabase/mcp/settings.clj+++ b/src/metabase/mcp/settings.clj@@ -56,16 +56,6 @@:export? true:doc false)-(defsetting mcp-v2-disabled-tools- (deferred-tru "v2 MCP tool names to disable, stored as CSV. Disabled tools are hidden from tools/list and rejected by tools/call.")- :type :csv- :default []- :visibility :admin- :export? false- :encryption :no- :audit :getter- :doc false)-(def ^:private ^:const default-query-handle-ttl-hours"Default for [[mcp-query-handle-ttl-hours]]. One source, referenced by both the setting's `:default`and its getter's fallback, so the two can't drift."diff --git a/src/metabase/mcp/v2/registry.clj b/src/metabase/mcp/v2/registry.cljindex da4f2977e82..734897ea627 100644--- a/src/metabase/mcp/v2/registry.clj+++ b/src/metabase/mcp/v2/registry.clj@@ -2,16 +2,15 @@"The v2 MCP tool registry. Tools are in-code registry entries declared with [[deftool]].The v2 surface builds its own manifest and dispatch:- - `tools/list` ([[list-tools]]) filters by token scopes, the `mcp-v2-disabled-tools` CSV,- and the client extensions the caller advertised (a tool needing MCP Apps UI is hidden from- a client that can't render an iframe, rather than failing at call time);- - `tools/call` ([[call-tool]]) re-checks all three, validates arguments against the tool's+ - `tools/list` ([[list-tools]]) filters by token scopes and the client extensions the caller+ advertised (a tool needing MCP Apps UI is hidden from a client that can't render an iframe,+ rather than failing at call time);+ - `tools/call` ([[call-tool]]) re-checks both, validates arguments against the tool'sMalli schema with teaching errors, dispatches to the handler under the already-boundcurrent user, and logs every outcome through the shared usage path.- The three filters are not three boundaries. Scopes come from the verified token and the- disabled-tools CSV from instance settings, but the extension set is reconstructed from the- unsigned capability payload the client echoes back in its session id — a client can claim any+ The two filters are not two boundaries. Scopes come from the verified token, but the+ extension set is reconstructed from the unsigned capability payload the client echoes back in its session id — a client can claim anyextension it likes, and never has to `initialize` to do so. Treat `:required-extensions` as aclient-declared hint that keeps a tool out of a list where it could not render, and put nothingbehind it that the tool's `:scope` does not already protect."@@ -22,7 +21,6 @@[metabase.api.common :as api][metabase.api.macros.defendpoint.tools-manifest :as tools-manifest][metabase.mcp.scope :as mcp.scope]- [metabase.mcp.settings :as mcp.settings][metabase.mcp.ui-resource :as mcp.ui-resource][metabase.mcp.usage :as mcp.usage][metabase.mcp.v2.common :as common]@@ -184,14 +182,9 @@(or @manifest-cache(reset! manifest-cache (generate-manifest))))-(defn- disabled-tool-names- []- (set (mcp.settings/mcp-v2-disabled-tools)))-(defn list-tools- "Return the tool definitions for the v2 MCP `tools/list` response, filtered by `token-scopes`,- the `mcp-v2-disabled-tools` setting, and the client extensions- `options` advertises (`:supports-mcp-ui?` — MCP Apps tools are hidden from clients that+ "Return the tool definitions for the v2 MCP `tools/list` response, filtered by `token-scopes`+ and the client extensions `options` advertises (`:supports-mcp-ui?` — MCP Apps tools are hidden from clients thatcan't render an iframe rather than failing at call time).The 1-arity assumes full extension support: it backs [[tools-hash]], whose transport hook@@ -199,12 +192,9 @@([token-scopes](list-tools token-scopes {:supports-mcp-ui? true}))([token-scopes options]- (let [disabled (disabled-tool-names)- supported (mcp.ui-resource/supported-extensions options)]+ (let [supported (mcp.ui-resource/supported-extensions options)](into [](comp- ;; no disabled tools- (filter #(not (contains? disabled (:name %))));; has all required extensions(filter #(empty? (mcp.ui-resource/missing-required-extensions % supported)));; required scope is available@@ -215,7 +205,7 @@(defn tools-hash"Stable 8-character hex hash of the tool list visible to `token-scopes`; polled by theGET/SSE keepalive to emit `notifications/tools/list_changed` when the visible set changes- (scope changes, `mcp-v2-disabled-tools` edits, feature flips). Hashes the JSON encoding of+ (scope changes, feature flips). Hashes the JSON encoding ofthe wire-visible schema, so the result never depends on Clojure's `hash` of non-data leaves."[token-scopes](format "%08x"@@ -257,10 +247,7 @@missing (mcp.ui-resource/missing-required-extensionstool (mcp.ui-resource/supported-extensions options))](cond- ;; Disabled tools are absent from tools/list, so calling one is indistinguishable from- ;; calling a tool that never existed.- (or (nil? tool)- (contains? (disabled-tool-names) tool-name))+ (nil? tool){:error {:code common/error-code-method-not-found :message (str "Unknown tool: " tool-name)}}(not (map? (or arguments {})))@@ -271,7 +258,7 @@:message (insufficient-scope-message tool-name (:scope tool) token-scopes)}};; A UI tool the client can't render is a caller error, not a hidden tool: unlike the- ;; scope/disabled cases it stays listed for capable clients, so name what's missing.+ ;; scope case it stays listed for capable clients, so name what's missing.(seq missing){:error {:code common/error-code-invalid-params :message (mcp.ui-resource/missing-extensions-error tool-name missing)}}diff --git a/test/metabase/mcp/v2/api_test.clj b/test/metabase/mcp/v2/api_test.cljindex ce3066fab43..5523d62dccf 100644--- a/test/metabase/mcp/v2/api_test.clj+++ b/test/metabase/mcp/v2/api_test.clj@@ -146,21 +146,6 @@(is (= "Unknown tool: nope" (get-in response [:body :error :message])))(is (not (contains? (:body response) :result)))))))-(deftest disabled-tools-kill-switch-test- (let [[session-id _] (initialize!)]- (mt/with-temporary-setting-values [mcp.settings/mcp-v2-disabled-tools ["test_echo"]]- (testing "a disabled tool disappears from tools/list"- (let [response (mcp-request (jsonrpc-request "tools/list")- {"mcp-session-id" session-id})]- (is (not (some #(= "test_echo" (:name %))- (get-in response [:body :result :tools]))))))- (testing "a disabled tool is rejected by tools/call as if it never existed"- (let [response (mcp-request (jsonrpc-request "tools/call" {:name "test_echo" :arguments {}})- {"mcp-session-id" session-id})]- (is (= -32601 (get-in response [:body :error :code])))- (is (= "Unknown tool: test_echo" (get-in response [:body :error :message])))- (is (not (contains? (:body response) :result))))))))-(deftest method-dispatch-fallthrough-test(let [[session-id _] (initialize!)](testing "methods the surface can't serve fall through to JSON-RPC method-not-found"diff --git a/test/metabase/mcp/v2/registry_test.clj b/test/metabase/mcp/v2/registry_test.cljindex 9c5bd4bcf5c..d8641623760 100644--- a/test/metabase/mcp/v2/registry_test.clj+++ b/test/metabase/mcp/v2/registry_test.clj@@ -4,7 +4,6 @@[clojure.string :as str][clojure.test :refer :all][metabase.api.macros.scope :as scope]- [metabase.mcp.settings :as mcp.settings][metabase.mcp.usage :as mcp.usage][metabase.mcp.v2.common :as common][metabase.mcp.v2.registry :as registry]@@ -88,16 +87,6 @@(is (= "Internal error" (-> result :content first :text))"the raw exception message must not reach the client")))))))-(deftest disabled-tools-test- (mt/with-temporary-setting-values [mcp.settings/mcp-v2-disabled-tools ["test_echo"]]- (testing "a disabled tool is hidden from tools/list"- (is (not (some #(= "test_echo" (:name %)) (registry/list-tools nil)))))- (testing "and rejected by tools/call as unknown"- (let [{:keys [error]} (registry/call-tool nil nil "test_echo" {})]- (is (= {:code common/error-code-method-not-found- :message "Unknown tool: test_echo"}- error))))))-(deftest ^:parallel registered-scopes-test(testing "registered-scopes reports the scopes of the landed tools. (It does not feed the DCR grant: that reads`mcp.paths/v2-surface-scopes`, and a tool whose :scope is outside that set is unreachable over OAuth