Skip to content

MCP with scoped OAuth access

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

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. For connecting an MCP client, see Supabase MCP server.

Supported OAuth apps

The following table lists how each OAuth client type behaves with the Supabase MCP server.

Client typeBehavior
Static OAuth app with scoped access onEnforces member permissions, project selection, or both on every MCP connection and tool call.
Static OAuth app with scoped access offUnchanged. An Owner or Administrator authorizes the app for the whole organization and all projects.
Dynamically registered clientUnchanged. 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.

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). 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 URLModeBehavior with a project-scoped grant
/mcpAccount modeWorks across all projects covered by the grant and enforces the grant on each tool call. Account tools stay listed.
/mcp?project_ref=YOUR_PROJECT_REFProject modeScopes 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), 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 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.

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 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.

SituationResponseRecovery
Scope isn't registered on the OAuth appHTTP 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 scopeHTTP 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 removedHTTP 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 it403 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.