mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Follow-up to #54156. Some wording on the [MCP with scoped OAuth access](https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration/mcp-scoped-access) page assumes the reader knows how things worked before, like "Unchanged" in the supported OAuth apps table. A few other spots use terms the docs don't define anywhere, or name the same grant three different ways. ## Solution Reword those spots so the page reads on its own for a first-time reader. No new sections and no heading changes, so anchors stay the same. - Drop "Unchanged" from the supported OAuth apps table, and define scoped access before the table instead of after it. - Separate the two ways to limit projects: `project_ref` in the connection URL pins the session to one project, while choosing **Specific projects** on the consent screen limits the token to the projects the person selected. Replace "project-scoped", "member-bound", and "selected" grant with "grant that covers specific projects", using the consent screen label, and use the same wording on [Update your app for scoped access](https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration/update-for-scoped-access). "Specific-project grant" read as a single project. - Read-only SQL applies to any grant from an app with scoped access on, so say that instead of "project-scoped or member-bound grant", and link `read_only=true` to the MCP configuration options. - Replace "Ungated tools", "Account tools stay listed", and the "loop back to the consent screen" reference that came before the step-up flow is explained. ## Verification - `pnpm exec oxfmt --check` on the page passes. - Preview: [MCP with scoped OAuth access](https://docs-git-pedrorodrigues-mcp-scoped-access-first-read-supabase.vercel.app/docs/guides/integrations/build-a-supabase-oauth-integration/mcp-scoped-access)
75 lines
8.8 KiB
Plaintext
75 lines
8.8 KiB
Plaintext
---
|
|
title: 'MCP with scoped OAuth access'
|
|
subtitle: 'Connect MCP clients to OAuth apps that use member permissions or project selection'
|
|
description: 'Learn how the Supabase MCP server enforces scoped OAuth grants, project access, read-only SQL, and step-up authorization for static OAuth apps.'
|
|
---
|
|
|
|
Learn how the Supabase Model Context Protocol (MCP) server enforces scoped OAuth grants on connections and tool calls, so you can choose the right scopes, connection URL, and error-handling behavior. To register an OAuth app in Supabase, see [Build a Supabase OAuth integration](/docs/guides/integrations/build-a-supabase-oauth-integration#create-an-oauth-app). For connecting an MCP client, see [Supabase MCP server](/docs/guides/ai-tools/mcp).
|
|
|
|
## Supported OAuth apps
|
|
|
|
An OAuth app has scoped access when it turns on member permissions, project selection, or both. For how each setting works, see [Scoped access for OAuth apps](/docs/guides/integrations/build-a-supabase-oauth-integration/scoped-access).
|
|
|
|
The following table lists how each OAuth client type behaves with the Supabase MCP server.
|
|
|
|
| Client type | Behavior |
|
|
| --------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
| Static OAuth app with scoped access on | Enforces member permissions, project selection, or both on every MCP connection and tool call. |
|
|
| Static OAuth app with scoped access off | An Owner or Administrator authorizes the app for the whole organization and all projects. |
|
|
| Dynamically registered client | Clients that connect through dynamic client registration, such as Claude Code, don't use scoped grants. |
|
|
|
|
## Project access
|
|
|
|
You can limit which projects an MCP session reaches in two places:
|
|
|
|
- **The connection URL**: `project_ref` pins the session to one project. It only limits which tools the session exposes, not the OAuth token, which can still reach every project the grant covers (see [MCP configuration options](/docs/guides/ai-tools/mcp#configuration-options)).
|
|
- **The grant**: When the person chooses **Specific projects** on the consent screen, the token itself covers only the projects they selected. The server enforces this on every tool call, however the client connects.
|
|
|
|
The following table shows how a grant limited to specific projects behaves with and without `project_ref` in the connection URL.
|
|
|
|
| Connection URL | Mode | Behavior when the grant covers specific projects |
|
|
| ----------------------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
| `/mcp` | Account mode | Works across all projects covered by the grant and enforces the grant on each tool call. Account tools such as `list_projects` are available. |
|
|
| `/mcp?project_ref=YOUR_PROJECT_REF` | Project mode | Scopes the session to one project covered by the grant (or a preview branch's parent project). Rejects other refs with `403` at connect. |
|
|
|
|
When the grant covers specific projects, keep these behaviors in mind:
|
|
|
|
- **Discovering projects**: In account mode, call `list_projects` (requires `projects:read`) to see the projects the token can reach. `list_organizations` returns an empty list even with `organizations:read`, and organization-level tools such as `get_organization` are denied.
|
|
- **Projects outside the grant**: Calling a tool on a project in the same organization that isn't in the grant returns an error asking the user to re-authenticate and add that project. Calls for other projects also fail. In project mode, connecting with a `project_ref` outside the grant fails at connect time with `403 Forbidden`. The response has no [step-up challenge](#missing-scope-and-permission-errors), so the client doesn't prompt the user to update the grant.
|
|
- **Preview branches**: As with the Management API ([project selection](/docs/guides/integrations/build-a-supabase-oauth-integration/scoped-access#project-selection)), users grant access on the parent project rather than individual branch projects. If the parent project is in the grant, both branch tool calls and `?project_ref=YOUR_BRANCH_REF` connections succeed. If the parent project isn't in the grant, `?project_ref=YOUR_BRANCH_REF` connections fail with `403 Forbidden` and account-mode tool calls return a tool error without revealing the parent project ref.
|
|
|
|
## Read-only SQL
|
|
|
|
When a grant from an app with scoped access on includes `database:read` without `database:write`, `execute_sql` runs as a read-only Postgres user even if the connection URL doesn't set [`read_only=true`](/docs/guides/ai-tools/mcp#configuration-options).
|
|
|
|
If a query tries to write data or change the schema, Postgres rejects it and the server handles the denial using the [missing-scope rules](#missing-scope-and-permission-errors) for `database:write`. If the connection URL explicitly sets `read_only=true`, the server returns the Postgres read-only error directly instead of treating it as a missing scope.
|
|
|
|
<Admonition type="tip" title="Example: read-only SQL integration">
|
|
|
|
Registering `projects:read` and `database:read` on a static OAuth app with **Ask for specific projects** turned on lets an MCP client call `list_projects` to find granted projects and run read-only queries with `execute_sql`. Writes are blocked because the grant omits `database:write`, and projects the person didn't select are blocked.
|
|
|
|
</Admonition>
|
|
|
|
## Missing-scope and permission errors
|
|
|
|
Tools that call the Management API check the OAuth scope they need before running. Tools that don't call it, such as `search_docs`, don't need a scope.
|
|
|
|
Re-authenticating can grant a scope that wasn't in the original grant. When it can, the Supabase MCP server follows the [MCP step-up authorization flow](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization#scope-challenge-handling) from specification version `2026-07-28`, returning `403 Forbidden` with a `WWW-Authenticate` `insufficient_scope` challenge so the client prompts the user to update the grant. When re-authenticating can't fix the denial, the server returns a tool error in an HTTP `200` response instead so the client doesn't loop back to the consent screen.
|
|
|
|
The following table lists each denial case, the server response, and how to recover.
|
|
|
|
| Situation | Response | Recovery |
|
|
| ------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
| Scope isn't registered on the OAuth app | HTTP `200` tool error (no step-up challenge) | The app author adds the scope in app settings and the user re-authenticates, or uses an app that requests it. |
|
|
| Member's role can't grant the scope | HTTP `200` tool error (no step-up challenge) | An Owner or Administrator upgrades the member's role, then the user re-authenticates. |
|
|
| Member's role was lowered or membership was removed | HTTP `200` tool error (live permission check) | An Owner or Administrator restores the role or membership. Re-authenticating alone doesn't restore access. |
|
|
| App registers the scope and the member's role allows it | `403 Forbidden` (`WWW-Authenticate: insufficient_scope`) | The MCP client prompts the user to re-authenticate and update the grant. |
|
|
|
|
If member-level authorization is temporarily unavailable, the server also returns an HTTP `200` tool error without a step-up challenge; the client can retry later without changing the grant or connection. For permission denials, an AI agent should ask the user to update their grant or role, retry only after the grant or connection changes, and never ask for the OAuth client secret in chat.
|
|
|
|
## Related resources
|
|
|
|
- [Update your app for scoped access](/docs/guides/integrations/build-a-supabase-oauth-integration/update-for-scoped-access): see the lowest role required for each OAuth scope.
|
|
- [Test scoped access on a staging app](/docs/guides/integrations/build-a-supabase-oauth-integration/test-scoped-access): verify member and project scenarios before changing a production app.
|
|
- [Manage OAuth app access](/docs/guides/integrations/build-a-supabase-oauth-integration/manage-oauth-app-access): review and revoke OAuth grants in your organization.
|