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
GHY-4939: Ensure no MCP scopes are accepted by REST (#84248)
Eric Normand24f8ac0a3a24
diff --git a/src/metabase/api/macros.clj b/src/metabase/api/macros.cljindex ff9cce3131c..937e2d4006f 100644--- a/src/metabase/api/macros.clj+++ b/src/metabase/api/macros.clj@@ -1120,7 +1120,7 @@([](ns-routes *ns*))([nmspace :- ::nmspace]- (-> nmspace the-ns meta :api/endpoints))+ (-> nmspace the-ns meta :api/endpoints (or {})))([nmspace :- ::nmspacemethod :- ::method](let [routes (ns-routes nmspace)]diff --git a/src/metabase/mcp/README.md b/src/metabase/mcp/README.mdindex d37e8416252..0ac6881d64d 100644--- a/src/metabase/mcp/README.md+++ b/src/metabase/mcp/README.md@@ -54,17 +54,19 @@ Access tokens are scoped to limit what tools a client can use:| Scope | Tools it grants || ----- | --------------- |-| `agent:content:read` | `browse_collection`, `browse_data`, `get_content`, `get_parameter_values`, `glossary`, `learn`, `search` |+| `agent:content:read` | `browse_collection`, `browse_data`, `get_content`, `get_parameter_values`, `glossary`, `learn`, `search`, and the `catalog://metabase/fields` data resource (see [Resources](#resources)) || `agent:content:write` | `bookmark_content`, `collection_write`, `dashboard_write`, `document_write`, `duplicate_content`, `measure_write`, `metric_write`, `question_write`, `segment_write` || `agent:delivery:write` | `alert_write`, `subscription_write` || `agent:query:run` | `execute_query`, `refresh_ui_credential`, `render_drill_through`, `run_saved_question`, `visualize_query` || `agent:sql:run` | `execute_sql` |-| `agent:resource:read` | No tools: it gates reading the `catalog://metabase/fields` data resource (see [Resources](#resources)). |Wildcard patterns (e.g. `agent:*`) match any scope with that prefix.+These scopes gate the MCP surface only. No REST endpoint may declare one as its `:scope`, so a new token issued to an+MCP client grants nothing on the REST API.+Clients start with a baseline. The protected-resource metadata's `scopes_supported` and the `scope` of the 401-challenge both list only `agent:content:read agent:query:run agent:resource:read`: a fresh connection can read,+challenge both list only `agent:content:read agent:query:run`: a fresh connection can read,query, and chart. Writes (`agent:content:write`), raw SQL (`agent:sql:run`), and alerts and subscriptions(`agent:delivery:write`) need a step-up. The surface still accepts every scope in the table, and the authorizationserver metadata still advertises all of them.@@ -153,7 +155,7 @@ clients can fetch supplementary content by URI without inflating tool descriptio| ------------ | ----- | ----------- || `ui://metabase/visualize-query.html` | `agent:query:run` (UI credential only) | The MCP Apps iframe shell `visualize_query` points a capable client at. || `ui://metabase/render-drill-through.html` | `agent:query:run` (UI credential only) | The shell `render_drill_through` points at. |-| `catalog://metabase/fields` | `agent:resource:read` | The dot-paths each content type accepts in `fields` arguments. |+| `catalog://metabase/fields` | `agent:content:read` | The dot-paths each content type accepts in `fields` arguments. |Every resource is listed whatever the token's scopes. A data resource, such as the fields catalog, is read only by atoken holding its scope; otherwise the read gets the 403 `insufficient_scope` challenge described underdiff --git a/src/metabase/mcp/paths.clj b/src/metabase/mcp/paths.cljindex baca3d25415..f2528712b19 100644--- a/src/metabase/mcp/paths.clj+++ b/src/metabase/mcp/paths.clj@@ -53,13 +53,12 @@Spelled as literals rather than read from `metabot.scope` because requiring that namespace here would closethe load cycle described above; `v2-surface-scopes-match-metabot-scope-test` is what keeps them in step.- Scopes are never renamed — issued tokens carry literal strings — so this only ever grows."+ Scopes are never renamed — issued tokens carry literal strings."["agent:content:read""agent:content:write""agent:query:run""agent:sql:run"- "agent:delivery:write"- "agent:resource:read"])+ "agent:delivery:write"])(def v2-baseline-scopes"The subset of [[v2-surface-scopes]], in its order, that an MCP client is told to request when it first connects:@@ -68,5 +67,4 @@;; `agent:query:run` is here because charts must not need a step-up: Claude Desktop retries a tool after step-up;; over a session that declares no MCP Apps support, so a stepped-up `visualize_query` is refused and never embeds.["agent:content:read"- "agent:query:run"- "agent:resource:read"])+ "agent:query:run"])diff --git a/src/metabase/mcp/v2/resources.clj b/src/metabase/mcp/v2/resources.cljindex 7beb1383691..db5cc36895a 100644--- a/src/metabase/mcp/v2/resources.clj+++ b/src/metabase/mcp/v2/resources.clj@@ -132,5 +132,5 @@:name "Fields Catalog":description "The dot-paths each content type supports in `fields` arguments (e.g. get_content), keyed by type.":mimeType "application/json"- :scope metabot.scope/agent-resource-read+ :scope metabot.scope/agent-content-read:render-fn (fn [_opts] (json/encode (projections/all-catalogs)))}))diff --git a/src/metabase/oauth_server/api/oauth.clj b/src/metabase/oauth_server/api/oauth.cljindex 8d1be731793..7866795f483 100644--- a/src/metabase/oauth_server/api/oauth.clj+++ b/src/metabase/oauth_server/api/oauth.clj@@ -103,8 +103,7 @@(def ^:private consent-scope-order"The MCP v2 scopes in the order the consent page lists them, least to most harmful."- ["agent:resource:read"- "agent:content:read"+ ["agent:content:read""agent:query:run""agent:content:write""agent:sql:run"diff --git a/src/metabase/oauth_server/core.clj b/src/metabase/oauth_server/core.cljindex 97e1e915e29..a983028bf1d 100644--- a/src/metabase/oauth_server/core.clj+++ b/src/metabase/oauth_server/core.clj@@ -117,9 +117,7 @@;; scope still needs the user's consent. The rest of the ceiling -- the agent-API extras -- is added only while;; registration is enabled, so an admin who turned it off leaves existing clients without those.;;- ;; The MCP kill switch is the one thing that stops the widening entirely. Some MCP surface scopes also gate the agent- ;; API (`agent:resource:read` is the declared scope of `POST /api/agent/v1/read-resource`), which has its own lever,- ;; so widening with MCP off would hand a client a scope its registration never included for a surface still serving.+ ;; The MCP kill switch stops the MCP part of the widening: with MCP off, no surface serves those scopes.(reify oidc.proto/ClientStore(get-client [_ client-id](widen-to-grant-ceiling (oidc.proto/get-client client-store client-id)diff --git a/test/metabase/agent_api/api_test.clj b/test/metabase/agent_api/api_test.cljindex 7f4f68f1fa4..cf35f324a82 100644--- a/test/metabase/agent_api/api_test.clj+++ b/test/metabase/agent_api/api_test.clj@@ -15,6 +15,8 @@[metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.normalize :as lib.normalize]+ [metabase.mcp.core :as mcp]+ [metabase.oauth-server.test-util :as oauth-server.tu][metabase.permissions.core :as perms][metabase.permissions.models.data-permissions :as data-perms][metabase.permissions.models.permissions-group :as perms-group]@@ -26,6 +28,7 @@[metabase.test.http-client :as client][metabase.util :as u][metabase.util.json :as json]+ [oidc-provider.util :as oidc.util][toucan2.core :as t2]))(set! *warn-on-reflection* true)@@ -1942,6 +1945,46 @@(is (nil? (-> resp :resources first :content)))(is (some? (-> resp :resources first :error))))))+(deftest read-resource-refuses-mcp-scopes-test+ (testing "GHY-4939: MCP scopes gate the MCP surface only. An OAuth token issued to an MCP client must not reach a+ REST endpoint, so a token holding every MCP scope is refused by POST /v1/read-resource."+ (mt/with-temporary-setting-values [site-url "http://localhost:3000"]+ (oauth-server.tu/with-oauth-client [client-id]+ (mt/with-model-cleanup [:model/OAuthAccessToken]+ (let [token (str (random-uuid))]+ (t2/insert! :model/OAuthAccessToken+ {:token (oidc.util/hash-token token)+ :user_id (mt/user->id :crowberto)+ :client_id client-id+ :scope (vec (mcp/v2-scopes))+ :expiry (+ (System/currentTimeMillis) 3600000)})+ (is (= 403 (:status (client/client-full-response+ :post "agent/v1/read-resource"+ {:request-options {:headers {"authorization" (str "Bearer " token)}}}+ {:uris ["metabase://databases"]}))))))))))++(deftest endpoint-without-scope-refuses-mcp-scopes-test+ (testing "GHY-4939: MCP scopes gate the MCP surface only. An endpoint that declares no `:scope` must refuse every+ scoped token, so a token holding every MCP scope is refused by GET /api/user/:id."+ (testing "the endpoint itself works for a normal session"+ (is (= (mt/user->id :crowberto)+ (:id (mt/user-http-request :crowberto :get 200 (str "user/" (mt/user->id :crowberto)))))))+ (mt/with-temporary-setting-values [site-url "http://localhost:3000"]+ (oauth-server.tu/with-oauth-client [client-id]+ (mt/with-model-cleanup [:model/OAuthAccessToken]+ (let [token (str (random-uuid))+ _ (t2/insert! :model/OAuthAccessToken+ {:token (oidc.util/hash-token token)+ :user_id (mt/user->id :crowberto)+ :client_id client-id+ :scope (vec (mcp/v2-scopes))+ :expiry (+ (System/currentTimeMillis) 3600000)})+ response (client/client-full-response+ :get (str "user/" (mt/user->id :crowberto))+ {:request-options {:headers {"authorization" (str "Bearer " token)}}})]+ (is (= 403 (:status response)))+ (is (= "scope_not_permitted" (get-in response [:body :error])))))))))+(deftest decode-and-validate-query-strips-extra-keys-test(testing "base64 query payloads are decoded, validated, and stripped of the query processor's internal keys";; `:qp/source-card-id` and `:qp/stage-had-source-card` are keys the QP adds to a query while it runs and thatdiff --git a/test/metabase/mcp/transport_test.clj b/test/metabase/mcp/transport_test.cljindex fc8ad73e043..32884c80132 100644--- a/test/metabase/mcp/transport_test.clj+++ b/test/metabase/mcp/transport_test.clj@@ -926,8 +926,7 @@(mt/with-temporary-setting-values [site-url "http://localhost:3000"](oauth-server.tu/with-oauth-client [client-id](mt/with-model-cleanup [:model/OAuthAccessToken]- (let [;; One per-entity scope the v2 surface never gates on, plus `agent:resource:read`, which gates a- ;; resource rather than any tool.+ (let [;; Two agent-API scopes the v2 surface never gates on.token (issue-bearer! (mt/user->id :rasta) client-id["agent:question:create" "agent:resource:read"])headers (fn [& {:as extra}]diff --git a/test/metabase/mcp/v2/api_test.clj b/test/metabase/mcp/v2/api_test.cljindex f9749530a5a..31415c570b0 100644--- a/test/metabase/mcp/v2/api_test.clj+++ b/test/metabase/mcp/v2/api_test.clj@@ -3,7 +3,9 @@[clojure.string :as str][clojure.test :refer :all][metabase.ai-tracing.core :as ait]+ [metabase.api.macros :as api.macros][metabase.auth-identity.core :as auth-identity]+ [metabase.config.core :as config][metabase.mcp.db :as mcp.db][metabase.mcp.http-handler :as mcp.http-handler][metabase.mcp.paths :as mcp.paths]@@ -528,10 +530,23 @@metabot.scope/agent-content-writemetabot.scope/agent-query-runmetabot.scope/agent-sql-run- metabot.scope/agent-delivery-write- metabot.scope/agent-resource-read]+ metabot.scope/agent-delivery-write]mcp.paths/v2-surface-scopes))))+(deftest ^:parallel no-rest-endpoint-declares-an-mcp-scope-test+ (testing "GHY-4939: MCP scopes gate the MCP surface only. A REST endpoint that declares one lets an OAuth token+ issued to an MCP client reach it."+ (require 'metabase.api-routes.routes)+ (when config/ee-available?+ (require 'metabase-enterprise.api-routes.routes))+ (let [mcp-scopes (set mcp.paths/v2-surface-scopes)]+ (is (= []+ (for [nmspace (all-ns)+ [[method route] {:keys [form]}] (api.macros/ns-routes nmspace)+ :let [scope (get-in form [:metadata :scope])]+ :when (contains? mcp-scopes scope)]+ [(ns-name nmspace) method route scope]))))))+(deftest ^:parallel challenge-scopes-are-grantable-test(testing "GHY-4226: the 401 challenge tells an uninstructed client what to ask for, and a dynamic client'sceiling always includes the default grant, which is what the OAuth server validates a requested scope@@ -544,7 +559,7 @@(is (contains? grantable scope)"a scope the v2 challenge asks for must be one the OAuth server will actually grant")))))(testing "GHY-4543: the challenge asks for the baseline, a subset of what the surface accepts, in surface order"- (is (= ["agent:content:read" "agent:query:run" "agent:resource:read"] @#'v2.api/default-ask-scopes))+ (is (= ["agent:content:read" "agent:query:run"] @#'v2.api/default-ask-scopes))(is (= @#'v2.api/default-ask-scopes (filterv (set @#'v2.api/default-ask-scopes) mcp.paths/v2-surface-scopes)))))(def ^:private mcp-app-ui-capabilities@@ -772,7 +787,7 @@{:request-options {:headers {}}}(jsonrpc-request "initialize"))](is (str/ends-with? (get-in response [:headers "WWW-Authenticate"] "")- ", scope=\"agent:content:read agent:query:run agent:resource:read\""))))))+ ", scope=\"agent:content:read agent:query:run\""))))))(testing "GHY-4543: an invalid bearer token's challenge asks for the same baseline"(doseq [path ["metabase-mcp" "mcp"]](testing path@@ -783,7 +798,7 @@(is (= (str "Bearer realm=\"mcp\", ""resource_metadata=\"http://localhost:3000/.well-known/oauth-protected-resource""/api/" path "\", "- "scope=\"agent:content:read agent:query:run agent:resource:read\", "+ "scope=\"agent:content:read agent:query:run\", ""error=\"invalid_token\"")(get-in response [:headers "WWW-Authenticate"])))))))(testing "auth-params are comma-delimited per RFC 7235, the form every spec and vendor example@@ -794,7 +809,7 @@(is (= (str "Bearer realm=\"mcp\", ""resource_metadata=\"http://localhost:3000/.well-known/oauth-protected-resource""/api/metabase-mcp\", "- "scope=\"agent:content:read agent:query:run agent:resource:read\"")+ "scope=\"agent:content:read agent:query:run\"")(get-in response [:headers "WWW-Authenticate"])))))));;; ------------------------------------------------ Auth methods --------------------------------------------------@@ -1148,8 +1163,7 @@:arguments {:method "create" :name "Step-up probe"}}))](is (str/starts-with? (get-in response [:headers "WWW-Authenticate"] "")(str "Bearer error=\"insufficient_scope\", "- "scope=\"agent:content:read agent:content:write agent:query:run "- "agent:resource:read\", "+ "scope=\"agent:content:read agent:content:write agent:query:run\", ""resource_metadata=\"" metadata-url "/api/metabase-mcp\", "))))))))(defn- orders-query@@ -1193,7 +1207,7 @@(is (str/starts-with?(get-in response [:headers "WWW-Authenticate"])(str "Bearer error=\"insufficient_scope\", "- "scope=\"agent:content:read agent:query:run agent:sql:run agent:resource:read\", "+ "scope=\"agent:content:read agent:query:run agent:sql:run\", ""resource_metadata=\"" metadata-url "/api/metabase-mcp\", ""error_description=\"execute_sql requires agent:sql:run ""(" (registry/english-scope-label "agent:sql:run") ")")))))))))))@@ -1204,26 +1218,26 @@session is unrestricted and never exercises scopes at all."(mcp.ui-resource/with-fallback-template(do-with-bearer-token!- #{"agent:content:read"}+ #{"agent:query:run"}(fn [headers](let [post! (bearer-session-post! headers)read-of (fn [uri] (jsonrpc-request "resources/read" {:uri uri}))denied (read-of v2.resources/fields-catalog-uri)]- (testing "the fields catalog without agent:resource:read"+ (testing "the fields catalog without agent:content:read"(let [response (post! 403 denied)](is (= 403 (:status response)))(is (str/starts-with?(get-in response [:headers "WWW-Authenticate"])(str "Bearer error=\"insufficient_scope\", "- "scope=\"agent:content:read agent:resource:read\", "+ "scope=\"agent:content:read agent:query:run\", ""resource_metadata=\"" metadata-url "/api/metabase-mcp\", "- "error_description=\"catalog://metabase/fields requires agent:resource:read "- "(" (registry/english-scope-label "agent:resource:read") ")")))+ "error_description=\"catalog://metabase/fields requires agent:content:read "+ "(" (registry/english-scope-label "agent:content:read") ")")))(testing "the body is the JSON-RPC error, with no transport-internal marker"(is (= #{:jsonrpc :id :error} (set (keys (:body response)))))(is (= {:code -32600:message (str "Insufficient scope to read resource: \"catalog://metabase/fields\". "- "Requires \"agent:resource:read\"; your token holds \"agent:content:read\".")}+ "Requires \"agent:content:read\"; your token holds \"agent:query:run\".")}(get-in response [:body :error]))))))(testing "resource_metadata names the alias the client connected through"(is (str/includes? (get-in (post! 403 denied :path "mcp") [:headers "WWW-Authenticate"] "")@@ -1244,7 +1258,7 @@"no transport-internal marker leaks into a batch element")))))))))))(deftest baseline-token-reads-the-fields-catalog-test- (testing "GHY-4543: the advertised baseline carries agent:resource:read, so a freshly connected client reads the+ (testing "GHY-4543, GHY-4939: the advertised baseline carries agent:content:read, so a freshly connected client reads thefields catalog without stepping up"(do-with-bearer-token!(set mcp.paths/v2-baseline-scopes)@@ -1313,20 +1327,20 @@(fn [& args](swap! minted inc)(apply (mt/original-fn #'mcp.session/issue-ui-credential) args))]- (let [without-query-run (shell-text #{"agent:content:read" "agent:resource:read"})]+ (let [without-query-run (shell-text #{"agent:content:read"})](testing "a token without agent:query:run reads the shell, but the credential slot renders empty and none isminted"(is (str/includes? without-query-run "metabaseConfig"))(is (re-find #"uiCredential:\s*\}" without-query-run))(is (nil? (embedded-credential without-query-run)))(is (zero? @minted)))- (testing "a token without even agent:resource:read reads the shell too, and still mints none"- (is (nil? (embedded-credential (shell-text #{"agent:content:read"}))))+ (testing "a token without even agent:content:read reads the shell too, and still mints none"+ (is (nil? (embedded-credential (shell-text #{"agent:delivery:write"}))))(is (zero? @minted)))(testing "a token holding every scope a read could need reads the fields catalog, and mints none: onlya shell embeds a credential"(do-with-bearer-token!- #{"agent:content:read" "agent:query:run" "agent:resource:read"}+ #{"agent:content:read" "agent:query:run"}(fn [headers](let [response ((bearer-session-post! headers)200@@ -1347,7 +1361,7 @@(testing "GHY-4543: with shell reads open to every token, `refresh_ui_credential` is how the iframe gets a credential.A capable client without agent:query:run is challenged for it, and handed nothing."(do-with-bearer-token!- #{"agent:content:read" "agent:resource:read"}+ #{"agent:content:read"}(fn [headers](let [session-id (-> (client/client-full-response :post 200 endpoint{:request-options {:headers headers}}@@ -1360,7 +1374,7 @@(is (= 403 (:status response)))(is (str/starts-with? (get-in response [:headers "WWW-Authenticate"] "")(str "Bearer error=\"insufficient_scope\", "- "scope=\"agent:content:read agent:query:run agent:resource:read\", ")))+ "scope=\"agent:content:read agent:query:run\", ")))(is (= #{:jsonrpc :id :error} (set (keys (:body response)))))(is (= -32600 (get-in response [:body :error :code]))))))))diff --git a/test/metabase/mcp/v2/tools/visualize_test.clj b/test/metabase/mcp/v2/tools/visualize_test.cljindex 2d4f4031f6d..d7059d45445 100644--- a/test/metabase/mcp/v2/tools/visualize_test.clj+++ b/test/metabase/mcp/v2/tools/visualize_test.clj@@ -340,7 +340,7 @@could never read, or a shell that never gets a credential"(let [advertised (set (mcp.core/all-scopes))](testing "GHY-4543: data resources count, not just UI shells"- (is (contains? (v2.resources/resource-scopes) "agent:resource:read")))+ (is (contains? (v2.resources/resource-scopes) "agent:content:read")))(doseq [scope (v2.resources/resource-scopes)](is (contains? advertised scope) scope)))))@@ -380,10 +380,10 @@(is (true? minted?))))))(testing "GHY-4543: a data resource is denied without its scope, naming the scope so the transport canchallenge for it"- (is (= {:status :scope-denied :required-scope "agent:resource:read"}- (v2.resources/read-resource v2.resources/fields-catalog-uri #{"agent:content:read"} {}))))- (testing "the fields catalog reads with agent:resource:read, and a data resource mints no credential"- (let [{:keys [status minted?]} (read-with v2.resources/fields-catalog-uri #{"agent:resource:read"})]+ (is (= {:status :scope-denied :required-scope "agent:content:read"}+ (v2.resources/read-resource v2.resources/fields-catalog-uri #{"agent:query:run"} {}))))+ (testing "GHY-4939: the fields catalog reads with agent:content:read, and a data resource mints no credential"+ (let [{:keys [status minted?]} (read-with v2.resources/fields-catalog-uri #{"agent:content:read"})](is (= :ok status))(is (false? minted?))))(testing "GHY-4157: an unknown URI is not found"diff --git a/test/metabase/oauth_server/api_test.clj b/test/metabase/oauth_server/api_test.cljindex 550599a6888..86cb8881eab 100644--- a/test/metabase/oauth_server/api_test.clj+++ b/test/metabase/oauth_server/api_test.clj@@ -64,7 +64,7 @@(testing url(let [response (mt/user-http-request :crowberto :get 200 url)resource-path (str/replace (:resource response) "http://localhost:3000" "")]- (is (= #{"agent:content:read" "agent:query:run" "agent:resource:read"}+ (is (= #{"agent:content:read" "agent:query:run"}(set (:scopes_supported response))))(is (empty? (remove (set (oauth-server/mcp-resource-scopes resource-path))(:scopes_supported response))))))))))@@ -77,7 +77,7 @@(let [advertised (set (:scopes_supported (mt/user-http-request :crowberto :get 200".well-known/oauth-authorization-server")))](doseq [scope ["agent:content:read" "agent:content:write" "agent:query:run"- "agent:sql:run" "agent:delivery:write" "agent:resource:read"]]+ "agent:sql:run" "agent:delivery:write"]](testing scope(is (contains? advertised scope))))(is (= (set (oauth-server/supported-scopes)) advertised))))))@@ -93,7 +93,7 @@response))(testing "the bare path is the one clients probe, so it advertises the same baseline as the canonicalpath it names, and none of the retired per-entity agent-API scopes"- (is (= #{"agent:content:read" "agent:query:run" "agent:resource:read"}+ (is (= #{"agent:content:read" "agent:query:run"}(set (:scopes_supported response))))(is (not (contains? (set (:scopes_supported response)) "agent:question:create"))))))))@@ -1489,9 +1489,9 @@"pre-v2 per-entity agent scopes, and `validate-scope` rejects any requested scope absent from that ""snapshot, so a user forced to re-authorize is answered with a 400 `invalid_scope` JSON body ""rendered raw in their browser tab and has no in-product recovery path. "- "`WidenDynamicOAuthClientScopesForMcpV2` unions the six v2 scopes into every dynamically registered "+ "`WidenDynamicOAuthClientScopesForMcpV2` unions the v2 scopes into every dynamically registered ""client's snapshot so the request validates and reaches consent.")- ;; GHY-4543: reading a dynamic client now adds the six v2 scopes whatever the registration setting says, so the+ ;; GHY-4543: reading a dynamic client now adds the five v2 scopes whatever the registration setting says, so the;; request reaches consent with or without the migration applied. Registration is disabled so only that MCP part;; of the ceiling applies. A static client carrying the same legacy snapshot is the control: it is never widened,;; so it shows what the stored snapshot alone decides.@@ -1500,7 +1500,7 @@(t2/with-transaction [_conn nil {:rollback-only true}](let [legacy-scopes ["agent:question:create" "agent:sql:construct" "agent:viz:mcp-ui:query"]v2-scopes ["agent:content:read" "agent:content:write" "agent:query:run"- "agent:sql:run" "agent:delivery:write" "agent:resource:read"]+ "agent:sql:run" "agent:delivery:write"]authorize! (fn [client-id expected-status](mt/user-http-request-full-response:crowberto :get expected-status "oauth/authorize"@@ -1513,11 +1513,11 @@(is (str/includes? (get-in response [:headers "Content-Type"]) "text/html")"the user sees a consent page, not a JSON error body rendered in their browser tab")(is (str/includes? (:body response) "agent:content:read")- "and the six v2 scopes are what they are consenting to"))+ "and the five v2 scopes are what they are consenting to"))static-id (:client_id (create-test-client! {:scopes legacy-scopes}))dynamic-id (:client_id (create-test-client! {:scopes legacy-scopes:registration_type "dynamic"}))]- (testing "control: the six v2 scopes are refused against the legacy snapshot alone"+ (testing "control: the five v2 scopes are refused against the legacy snapshot alone"(is (= {:error "invalid_scope":error_description invalid-request-description}(:body (authorize! static-id 400)))))@@ -1575,10 +1575,8 @@(refused? (authorize "dynamic" false not-mcp))))))(deftest grant-ceiling-widening-respects-mcp-kill-switch-test- (testing (str "GHY-4543: the MCP-scope widening stops when an admin turns MCP off. `agent:resource:read` is an MCP "- "surface scope and also the declared scope of `POST /api/agent/v1/read-resource`, which a separate "- "lever (`agent-api-enabled`) gates — so widening onto it with MCP off hands a dynamic client a scope "- "its registration never included, and with the agent API on, a live endpoint to spend it at.")+ (testing (str "GHY-4543: the MCP-scope widening stops when an admin turns MCP off, so a dynamic client gets no scope "+ "its registration never included for a surface that no longer serves.")(let [authorize (fn [mcp-on?](mt/with-temporary-setting-values [site-url "http://localhost:3000"mcp-enabled? mcp-on?@@ -1596,7 +1594,7 @@:client_id client-id:redirect_uri "https://example.com/callback":response_type "code"- :scope "agent:resource:read"+ :scope "agent:query:run":state "test-state")))))](testing "with MCP enabled a dynamic client is widened onto the MCP scopes and reaches consent"(let [response (authorize true)]@@ -1951,7 +1949,7 @@(def ^:private v2-scope-set#{"agent:content:read" "agent:content:write" "agent:query:run"- "agent:sql:run" "agent:delivery:write" "agent:resource:read"})+ "agent:sql:run" "agent:delivery:write"})(defn- mcp-resource-uri [](str "http://localhost:3000" (mcp/mcp-canonical-path)))@@ -2032,7 +2030,7 @@(some-> (:scope token-response) (str/split #" ") set))(def ^:private v2-baseline-scope-set- #{"agent:content:read" "agent:query:run" "agent:resource:read"})+ #{"agent:content:read" "agent:query:run"})(deftest registration-scope-does-not-narrow-step-up-test(testing (str "GHY-4543: Claude Code registers with the scope it read from the protected-resource metadata, then "@@ -2043,7 +2041,7 @@oauth-server-dynamic-registration-enabled true](t2/with-transaction [_conn nil {:rollback-only true}](let [{:keys [authorize token]} (register-then-authorize-mcp!- {:scope "agent:content:read agent:query:run agent:resource:read"}+ {:scope "agent:content:read agent:query:run"}(str/join " " (sort v2-scope-set)))](testing "the step-up request reaches the consent page"(is (= 200 (:status authorize)) (pr-str (:body authorize)))@@ -2080,7 +2078,7 @@(t2/with-transaction [_conn nil {:rollback-only true}](let [not-mcp (first (remove v2-scope-set (oauth-server/default-grant-scopes))){:keys [authorize token]} (register-then-authorize-mcp!- {:scope "agent:content:read agent:query:run agent:resource:read"}+ {:scope "agent:content:read agent:query:run"}(str/join " " (conj (sort v2-scope-set) not-mcp)))](is (some? not-mcp) "the default ceiling holds a scope the MCP resource does not accept")(is (= 200 (:status authorize)) (pr-str (:body authorize)))@@ -2111,13 +2109,13 @@(t2/with-transaction [_conn nil {:rollback-only true}](testing "control: the same flow reaches consent for a scope inside the default ceiling"(let [response (register-then-authorize-without-resource!- {:scope "agent:content:read agent:query:run agent:resource:read"}+ {:scope "agent:content:read agent:query:run"}"agent:content:write")](is (= 200 (:status response)) (pr-str (:body response)))))(doseq [scope [oauth-server/full-access-scope "*" "agent:*" "bogus:nonsense"]](testing scope(let [response (register-then-authorize-without-resource!- {:scope "agent:content:read agent:query:run agent:resource:read"}+ {:scope "agent:content:read agent:query:run"}scope)](is (= 400 (:status response)))(is (= "invalid_scope" (get-in response [:body :error]))))))))))@@ -2139,7 +2137,7 @@(str/join " " (sort v2-scope-set)))(deftest decision-mints-only-chosen-scopes-test- (testing (str "GHY-4555: a client requests all six v2 scopes and the user ticks only `agent:content:write`. The "+ (testing (str "GHY-4555: a client requests all five v2 scopes and the user ticks only `agent:content:write`. The ""token carries that plus the always-granted baseline, and neither the token response nor the stored ""token holds the scopes the user left unticked.")(mt/with-temporary-setting-values [site-url "http://localhost:3000"@@ -2148,7 +2146,7 @@(let [client (register-mcp-client! {})consent-resp (get-mcp-consent-page! (:client_id client) all-v2-scopes)expected (conj v2-baseline-scope-set "agent:content:write")]- (is (= v2-scope-set (set (offered-scopes consent-resp))) "the page offers all six")+ (is (= v2-scope-set (set (offered-scopes consent-resp))) "the page offers all five")(let [token (exchange-code! client (post-mcp-decision! (:client_id client) consent-resp["agent:content:write"] 302))stored (:scopes (oauth-server/resolve-access-token (:access_token token)))]@@ -2168,7 +2166,7 @@(let [client (register-mcp-client! {})consent-resp (get-mcp-consent-page!(:client_id client)- "agent:content:read agent:query:run agent:resource:read agent:content:write")]+ "agent:content:read agent:query:run agent:content:write")](doseq [granted [["agent:sql:run"]["agent:content:write" "agent:delivery:write"][oauth-server/full-access-scope]@@ -2221,7 +2219,7 @@(mt/with-temporary-setting-values [site-url "http://localhost:3000"oauth-server-dynamic-registration-enabled true](t2/with-transaction [_conn nil {:rollback-only true}]- (testing "all six offered, nothing chosen: the token carries the baseline"+ (testing "all five offered, nothing chosen: the token carries the baseline"(let [client (register-mcp-client! {})consent-resp (get-mcp-consent-page! (:client_id client) all-v2-scopes)token (exchange-code! client (post-mcp-decision! (:client_id client) consent-resp nil 302))]@@ -2258,14 +2256,14 @@:disabled? (boolean (re-find #"\sdisabled[\s=/>]" tag))}))(deftest consent-page-scope-order-test- (testing (str "GHY-4555: the six v2 scopes are listed least to most harmful whatever order they were requested in, "+ (testing (str "GHY-4555: the five v2 scopes are listed least to most harmful whatever order they were requested in, ""and any other requested scope follows in request order")(mt/with-temporary-setting-values [site-url "http://localhost:3000"](t2/with-transaction [_conn nil {:rollback-only true}];; a registered non-v2 scope: GHY-4542 drops unregistered scopes before the page is rendered(let [not-v2 (first-non-mcp-default-scope)requested [not-v2 "agent:delivery:write" "agent:sql:run" oauth-server/full-access-scope- "agent:content:write" "agent:query:run" "agent:content:read" "agent:resource:read"]+ "agent:content:write" "agent:query:run" "agent:content:read"]client-id (:client_id (create-test-client! {:scopes requested}))body (:body (mt/user-http-request-full-response:crowberto :get 200 "oauth/authorize"@@ -2274,13 +2272,12 @@:response_type "code":scope (str/join " " requested):state "test-state"))]- (is (= ["agent:resource:read" "agent:content:read" "agent:query:run"+ (is (= ["agent:content:read" "agent:query:run""agent:content:write" "agent:sql:run" "agent:delivery:write"not-v2 oauth-server/full-access-scope](map :scope (consent-checkboxes body))))(testing "the baseline is ticked and locked; everything else, `mb:full` included, starts ticked (GHY-4826)"- (is (= {"agent:resource:read" [true true]- "agent:content:read" [true true]+ (is (= {"agent:content:read" [true true]"agent:query:run" [true true]"agent:content:write" [true false]"agent:sql:run" [true false]@@ -2360,8 +2357,7 @@(into {} (map (juxt :scope (juxt :checked? :disabled?))) (consent-checkboxes (:body response))))(def ^:private baseline-locked- {"agent:resource:read" [true true]- "agent:content:read" [true true]+ {"agent:content:read" [true true]"agent:query:run" [true true]})(deftest consent-page-ignores-held-scopes-test@@ -2511,7 +2507,7 @@:state "test-state"resource))](is (some? not-mcp) "the default ceiling holds a scope the MCP surface does not accept")- (testing "the client reaches consent for all six v2 scopes against the MCP resource"+ (testing "the client reaches consent for all five v2 scopes against the MCP resource"(let [response (authorize (str/join " " (sort v2-scope-set)) :resource mcp-uri)](is (= 200 (:status response)) (pr-str (:body response)))(is (= v2-scope-set (some-> (extract-hidden-field "scope" (:body response)) (str/split #" ") set)))))diff --git a/test/metabase/oauth_server/core_test.clj b/test/metabase/oauth_server/core_test.cljindex 84361a34183..68d1a7e500f 100644--- a/test/metabase/oauth_server/core_test.clj+++ b/test/metabase/oauth_server/core_test.clj@@ -54,7 +54,7 @@but not SQL, writes or delivery. Every tool is listed whatever the token holds, and a call needing more isanswered with a 403 `insufficient_scope` step-up, so asking for less degrades to a consent prompt ratherthan a hidden tool."- (is (= #{"agent:content:read" "agent:query:run" "agent:resource:read"} (set @#'v2.api/default-ask-scopes)))+ (is (= #{"agent:content:read" "agent:query:run"} (set @#'v2.api/default-ask-scopes)))(testing "the surface still accepts every scope asked for, or narrowing strips the ask at consent"(is (empty? (remove (set (oauth-server/mcp-resource-scopes (mcp/mcp-canonical-path)))@#'v2.api/default-ask-scopes))))@@ -200,7 +200,7 @@(testing "GHY-4543: every v2 scope survives narrowing on every alias, although the resource metadataadvertises only the baseline — otherwise a step-up for a write scope is stripped at consent"(let [v2-scopes ["agent:content:read" "agent:content:write" "agent:query:run"- "agent:sql:run" "agent:delivery:write" "agent:resource:read"]]+ "agent:sql:run" "agent:delivery:write"]](doseq [path (mcp/mcp-endpoint-paths)](testing path(is (= (set v2-scopes)