Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix database tools scope (#72617)

Alexander Polyankin152349982000
diff --git a/src/metabase/agent_api/api.clj b/src/metabase/agent_api/api.clj
index 5f72f6c41b1..5ea4e9c9750 100644
--- a/src/metabase/agent_api/api.clj
+++ b/src/metabase/agent_api/api.clj
@@ -212,14 +212,14 @@
(api.macros/defendpoint :get "/v1/database" :- [:sequential ::database]
"List all databases the current user has access to."
- {:scope "agent:database:read"
+ {:scope metabot/agent-database-read
:tool {:name "list_databases"}}
[]
(check-tool-result (entity-details/list-databases)))
(api.macros/defendpoint :get "/v1/database/:id" :- ::database
"Get details for a database by ID."
- {:scope "agent:database:read"
+ {:scope metabot/agent-database-read
:tool {:name "get_database"}}
[{:keys [id]} :- [:map [:id ms/PositiveInt]]
{:keys [with-tables with-fields with-field-values with-related-tables with-metrics with-measures with-segments]
diff --git a/src/metabase/api/macros/defendpoint/tools_manifest.clj b/src/metabase/api/macros/defendpoint/tools_manifest.clj
index 30dfa71f31a..80fbbf97cb9 100644
--- a/src/metabase/api/macros/defendpoint/tools_manifest.clj
+++ b/src/metabase/api/macros/defendpoint/tools_manifest.clj
@@ -249,8 +249,10 @@
(cond-> {:name tool-name
:description description
:endpoint {:method (u/upper-case-en (name method))
- :path full-path}}
- input-schema (assoc :inputSchema input-schema)
+ :path full-path}
+ ;; MCP requires every tool to have an inputSchema object, so default to an empty
+ ;; object for no-arg endpoints
+ :inputSchema (or input-schema {:type "object" :properties {}})}
resp-schema (assoc :responseSchema resp-schema)
(seq annotations) (assoc :annotations annotations)
task-support (assoc :execution {:taskSupport (name task-support)})
diff --git a/src/metabase/metabot/core.clj b/src/metabase/metabot/core.clj
index e62f87a80c1..dca34338a07 100644
--- a/src/metabase/metabot/core.clj
+++ b/src/metabase/metabot/core.clj
@@ -11,6 +11,7 @@
metabase-provider?
provider-and-model->provider]
[metabase.metabot.scope
+ agent-database-read
agent-metric-read
agent-query-construct
agent-query-execute
diff --git a/src/metabase/metabot/scope.clj b/src/metabase/metabot/scope.clj
index 74f256ca2f8..4365dff3ae3 100644
--- a/src/metabase/metabot/scope.clj
+++ b/src/metabase/metabot/scope.clj
@@ -96,6 +96,10 @@
(api-scope/defscope agent-metric-read "agent:metric:read"
(deferred-tru "View metric definitions"))
+;; Database
+(api-scope/defscope agent-database-read "agent:database:read"
+ (deferred-tru "View database metadata"))
+
;;; ──────────────────────────────────────────────────────────────────
;;; Metabot permission type definitions
;;; ──────────────────────────────────────────────────────────────────
@@ -143,7 +147,7 @@
"Map from metabot permission type to the wildcard scope strings granted when
that permission is `:yes`."
{:permission/metabot-sql-generation #{"agent:sql:*" "agent:transforms:*" "agent:snippets:*"}
- :permission/metabot-nlq #{"agent:notebook:*" "agent:query:*" "agent:table:*" "agent:metric:*"}
+ :permission/metabot-nlq #{"agent:notebook:*" "agent:query:*" "agent:table:*" "agent:metric:*" "agent:database:*"}
:permission/metabot-other-tools #{"agent:viz:*" "agent:dashboard:*" "agent:document:*" "agent:alert:*"}})
(def always-granted-scopes
diff --git a/test/metabase/mcp/api_test.clj b/test/metabase/mcp/api_test.clj
index fb5cbd9b775..d214d124f8a 100644
--- a/test/metabase/mcp/api_test.clj
+++ b/test/metabase/mcp/api_test.clj
@@ -168,15 +168,16 @@
(is (= 200 (:status post-response))))))
(deftest tools-list-test
- (testing "tools/list returns the 8 agent tools"
+ (testing "tools/list returns the 10 agent tools"
(let [[session-id _] (initialize!)
response (mcp-request (jsonrpc-request "tools/list")
{"mcp-session-id" session-id})
tools (get-in response [:body :result :tools])]
(is (= 200 (:status response)))
(is (pos? (count tools)))
- (is (= #{"search" "get_table" "get_metric" "get_table_field_values"
- "get_metric_field_values" "construct_query" "execute_query" "query"}
+ (is (= #{"search" "list_databases" "get_database" "get_table" "get_metric"
+ "get_table_field_values" "get_metric_field_values"
+ "construct_query" "execute_query" "query"}
(set (map :name tools))))
(testing "each tool has a description and inputSchema"
(doseq [tool tools]
@@ -443,7 +444,7 @@
(deftest tools-list-scope-filtering-test
(testing "tools/list with unrestricted scopes returns all tools"
(let [tools (mcp.tools/list-tools #{::scope/unrestricted})]
- (is (= 8 (count tools)))))
+ (is (= 10 (count tools)))))
(testing "tools/list with specific scope only returns matching tools"
(let [tools (mcp.tools/list-tools #{"agent:search"})
@@ -456,11 +457,11 @@
(testing "tools/list with wildcard scope matches all agent tools"
(let [tools (mcp.tools/list-tools #{"agent:*"})]
- (is (= 8 (count tools)))))
+ (is (= 10 (count tools)))))
(testing "tools/list with nil scopes returns all tools"
(let [tools (mcp.tools/list-tools nil)]
- (is (= 8 (count tools)))))
+ (is (= 10 (count tools)))))
(testing "tools/list with empty scopes does not return all tools"
(let [tools (mcp.tools/list-tools #{})]