> Note for AI agents: For other pages, see [llms.txt](https://supabase.com/docs/llms.txt).

# MCP with scoped OAuth access

Connect MCP clients using project-scoped and member-bound OAuth grants

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](https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration#create-an-oauth-app). For connecting an MCP client, see [Supabase MCP server](https://supabase.com/docs/guides/ai-tools/mcp).

## Supported OAuth apps

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 | Unchanged. An Owner or Administrator authorizes the app for the whole organization and all projects.               |
| Dynamically registered client           | Unchanged. Clients that connect through dynamic client registration, such as Claude Code, don't use scoped grants. |

For how member permissions, project selection, partial grants, and grants created before you change a setting work, see [Scoped access for OAuth apps](https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration/scoped-access).

## Project access

Setting `project_ref` in the MCP connection URL only limits which tools the session exposes; it doesn't restrict the OAuth token itself (see [MCP configuration options](https://supabase.com/docs/guides/ai-tools/mcp#configuration-options)). A project-scoped OAuth grant enforces project limits at the token level regardless of how the client connects.

The following table shows how a project-scoped grant behaves with and without `project_ref` in the connection URL.

| Connection URL                      | Mode         | Behavior with a project-scoped grant                                                                                                     |
| ----------------------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `/mcp`                              | Account mode | Works across all projects covered by the grant and enforces the grant on each tool call. Account tools stay listed.                      |
| `/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. |

With a project-scoped grant, keep these behaviors in mind:

- **Discovering projects**: In account mode, call `list_projects` (requires `projects:read`) to see the projects the token can reach. With a specific-project grant, `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` and no `insufficient_scope` challenge, so the client doesn't loop back to the consent screen.
- **Preview branches**: As with the Management API ([project selection](https://supabase.com/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 project-scoped or member-bound grant 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`.

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.

Tip: 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 outside the selected grant are blocked.

## Missing-scope and permission errors

Tools that call the Management API check the OAuth scope they need before running. Ungated tools such as `search_docs` don't require a Management API 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](https://supabase.com/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](https://supabase.com/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](https://supabase.com/docs/guides/integrations/build-a-supabase-oauth-integration/manage-oauth-app-access): review and revoke OAuth grants in your organization.
