mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The server and middleware reference pages on supabase.com still carry alpha labels that were dropped from the source partials weeks ago. #51031 (Sep 30) removed the alpha wording from the partials and #51276 (Oct 5) added the adapter removal date, but neither change reached the live site. The reference build (`apps/docs/scripts/build-reference-content.ts`, `writeNewMarkdownPartials`) copies a partial to `docs/ref/<library>/<name>.mdx` only when that file does not exist, and the page renderer reads from `docs/ref`. Once a page has been seeded, later edits to the partial are never picked up. The three affected pages were seeded before those PRs merged. The UI library MCP page has the same stale wording: it says the `pipeline` entry form of `withSupabase` is alpha and tracks `@supabase/middleware` 0.x. Middleware is at 1.x and `@supabase/server` dropped the alpha label in supabase/server#185. Linear: [SDK-2161](https://linear.app/supabase/issue/SDK-2161/remove-the-public-beta-designation-from-supabaseserver). Companion package PR: supabase/server#192. ## Solution Copy the current partial bodies over their rendered twins. The frontmatter is identical in each pair, and the partials are left untouched: - `apps/docs/docs/ref/server/frameworks.mdx`: adapters are now described as deprecated with the December 1, 2026 removal date, the Versions note tells readers to add `@supabase/middleware` as a direct dependency, the migration steps include `npm install @supabase/middleware`, and "The entry form is alpha" is gone. - `apps/docs/docs/ref/middleware/introduction.mdx`: the "Alpha" admonition is gone. - `apps/docs/docs/ref/middleware/usage-examples.mdx`: the entry form note no longer says alpha. Rewrite one paragraph in `apps/ui-library/content/docs/headless/mcp.mdx` so it states the version requirement (`@supabase/server` 1.6.0 or later) and that the nested form behaves the same, without the alpha or 0.x claims. After this PR each `docs/ref` file is byte-identical to its partial, so `diff` between the two is empty. ## Preview links | Site | Live | Preview | Search for | | ---------- | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | | Docs | [/docs/reference/server/frameworks](https://supabase.com/docs/reference/server/frameworks) | [/docs/reference/server/frameworks](https://docs-git-docs-drop-stale-alpha-labels-supabase.vercel.app/docs/reference/server/frameworks) | `December 1, 2026` | | Docs | [/docs/reference/middleware/introduction](https://supabase.com/docs/reference/middleware/introduction) | [/docs/reference/middleware/introduction](https://docs-git-docs-drop-stale-alpha-labels-supabase.vercel.app/docs/reference/middleware/introduction) | `is in alpha` (live only) | | Docs | [/docs/reference/middleware/usage-examples](https://supabase.com/docs/reference/middleware/usage-examples) | [/docs/reference/middleware/usage-examples](https://docs-git-docs-drop-stale-alpha-labels-supabase.vercel.app/docs/reference/middleware/usage-examples) | `The entry form of` | | UI library | [/ui/docs/headless/mcp](https://supabase.com/ui/docs/headless/mcp) | [/ui/docs/headless/mcp](https://ui-library-git-docs-drop-stale-alpha-labels-supabase.vercel.app/ui/docs/headless/mcp) | `Composing` | ## Review instructions 1. Open the live and preview links for the frameworks page side by side. Search for `alpha`: present on live, absent on preview. Search for `December 1, 2026`: absent on live, present on preview. 2. Open the middleware introduction. The "Alpha" caution box is gone on preview. 3. Open the middleware usage examples and expand the CORS example details. The entry form note reads "needs `@supabase/server` 1.6.0 or later" with no alpha. 4. Open the UI library MCP page. The paragraph after the `whoami` note states the version requirement and no longer mentions alpha or 0.x. 5. Optional, in a checkout: `diff apps/docs/spec/reference/server/v1/partials/frameworks.mdx apps/docs/docs/ref/server/frameworks.mdx` prints nothing. Same for the two middleware pages. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide) The docs text is copied verbatim from partials that already went through review in #51031 and #51276. The one rewritten paragraph in the UI library page follows the Supabase writing style guide.
223 lines
7.8 KiB
Plaintext
223 lines
7.8 KiB
Plaintext
---
|
|
title: MCP Server
|
|
description: Add a user-scoped MCP server to your product
|
|
preview: <BlockOverview name="mcp" showFiles />
|
|
---
|
|
|
|
Give embedded product agents and external clients such as Codex, Claude Code,
|
|
and ChatGPT secure, user-scoped access to your product through MCP tools. This
|
|
block runs as a Supabase Edge Function, verifies Supabase user access tokens,
|
|
and gives every tool an RLS-scoped client.
|
|
|
|
## Installation
|
|
|
|
<BlockItem name="mcp" showOpenInV0={false} />
|
|
|
|
Installs Deno Edge Function files into a Supabase project or empty directory. No
|
|
`components.json` is required. Backend files stay in `supabase/` at the project
|
|
root even when the frontend uses `src/`.
|
|
|
|
In a frontend app, add `"supabase/functions/**"` to the app's `tsconfig.json` `exclude`
|
|
list, preserving existing entries. Check the function separately with Deno.
|
|
|
|
## Configure the project
|
|
|
|
The function verifies access tokens itself, so disable the gateway JWT check:
|
|
|
|
```toml
|
|
[functions.mcp]
|
|
verify_jwt = false
|
|
```
|
|
|
|
The project must sign JWTs with an asymmetric key. `withSupabase` verifies user
|
|
tokens against the project JWKS and rejects legacy HS256 tokens, so a project
|
|
that still uses the legacy secret cannot authenticate embedded product sessions
|
|
or external MCP clients. Switch to an ES256 or RS256 key in
|
|
[JWT Keys](https://supabase.com/dashboard/project/_/settings/jwt).
|
|
|
|
Use Supabase CLI 2.117.0 or later. It supplies asymmetric signing keys for local
|
|
development and injects the function slug into the Edge Function, so the URL
|
|
advertised in the OAuth discovery metadata is canonical whatever path a request
|
|
arrives on.
|
|
|
|
## Choose how agents authenticate
|
|
|
|
### Embedded product agents
|
|
|
|
A trusted product backend can forward its signed-in user's Supabase access
|
|
token as `Authorization: Bearer <token>`. This reuses the product session, so
|
|
the user does not need to authorize their own product again.
|
|
|
|
Keep the token inside your backend or agent orchestrator. Never place it in a
|
|
prompt or expose it directly to a model provider.
|
|
|
|
### External MCP clients
|
|
|
|
External clients authenticate with OAuth, so users approve and revoke each
|
|
client separately. Install the [OAuth Consent block](../nextjs/oauth-consent),
|
|
then enable OAuth in `supabase/config.toml`:
|
|
|
|
```toml
|
|
[auth.oauth_server]
|
|
enabled = true
|
|
authorization_url_path = "/oauth/consent"
|
|
allow_dynamic_registration = true
|
|
```
|
|
|
|
Set the Auth **Site URL** to the origin that serves `/oauth/consent`. Use HTTPS
|
|
in production. Run `supabase config push` or restart the local stack to apply the
|
|
change.
|
|
|
|
`allow_dynamic_registration` lets any compatible client register itself. Set it
|
|
to `false` if you register clients yourself.
|
|
|
|
## Authentication
|
|
|
|
The function is a `pipeline` from `@supabase/middleware` with two entries from
|
|
`@supabase/server`, in this order:
|
|
|
|
```ts
|
|
Deno.serve(
|
|
pipeline(
|
|
[withOAuthProtectedResource(), withSupabase({ auth: 'user', cors: { headers: CORS_HEADERS } })],
|
|
handleMcp
|
|
)
|
|
)
|
|
```
|
|
|
|
`withOAuthProtectedResource()` runs before the auth gate. It serves RFC 9728
|
|
metadata at `/functions/v1/mcp/oauth-protected-resource` and adds a
|
|
`WWW-Authenticate` challenge to `401` responses so MCP clients can discover the
|
|
authorization server. On Edge Functions it derives the public URLs itself, locally
|
|
and hosted; off Edge Functions pass `resourceServer` and `authorizationServer`.
|
|
|
|
`withSupabase({ auth: 'user' })` is the gate. It verifies the JWT and hands
|
|
`handleMcp` an RLS-scoped client. It accepts both product session tokens and
|
|
OAuth access tokens. OAuth tokens include `client_id`; ordinary product sessions
|
|
do not. The included `whoami` tool exposes that difference.
|
|
|
|
Composing `withSupabase` as a `pipeline` entry needs `@supabase/server` 1.6.0
|
|
or later.
|
|
|
|
Any holder of a valid user token can call this function directly. Treat its
|
|
tools as an authenticated product API: keep RLS enabled, check authorization for
|
|
business operations, and do not add admin clients to the shared tool context.
|
|
|
|
OAuth scopes control identity, not database or tool access. Use `client_id` for
|
|
client-specific policies when it is present, and define the intended behavior
|
|
for product sessions where it is null. Never use user-editable metadata for
|
|
authorization decisions.
|
|
|
|
## Add tools
|
|
|
|
Each tool module exports one registration function:
|
|
|
|
```ts
|
|
// supabase/functions/mcp/tools/tasks.ts
|
|
import type { McpServer } from 'npm:@modelcontextprotocol/server@2.0.0'
|
|
import { z } from 'npm:zod@4.4.3'
|
|
|
|
import { jsonResult, runtimeErrorResult } from './result.ts'
|
|
import type { ToolContext } from './types.ts'
|
|
|
|
export function registerTasksTools(server: McpServer, { supabase }: ToolContext): void {
|
|
server.registerTool(
|
|
'close_task',
|
|
{
|
|
description: 'Mark a task as closed.',
|
|
inputSchema: z.object({ id: z.string().uuid() }),
|
|
annotations: { readOnlyHint: false, idempotentHint: true },
|
|
},
|
|
async ({ id }) => {
|
|
try {
|
|
const { data, error } = await supabase
|
|
.from('tasks')
|
|
.update({ closed: true })
|
|
.eq('id', id)
|
|
.select()
|
|
if (error) throw error
|
|
return jsonResult(data)
|
|
} catch (error) {
|
|
return runtimeErrorResult(error)
|
|
}
|
|
}
|
|
)
|
|
}
|
|
```
|
|
|
|
Then add one call in `tools/index.ts`, the server's composition point:
|
|
|
|
```ts
|
|
import type { McpServer } from 'npm:@modelcontextprotocol/server@2.0.0'
|
|
|
|
import { registerTasksTools } from './tasks.ts'
|
|
import type { ToolContext } from './types.ts'
|
|
import { registerWhoamiTool } from './whoami.ts'
|
|
|
|
export function registerTools(server: McpServer, context: ToolContext): void {
|
|
registerWhoamiTool(server, context)
|
|
registerTasksTools(server, context)
|
|
}
|
|
```
|
|
|
|
Each registration function receives:
|
|
|
|
- `supabase`, a user-scoped client for Database, Auth, Storage, and Functions
|
|
- `userClaims`, the normalized signed-in user identity
|
|
- `jwtClaims`, including `client_id` when the caller used OAuth
|
|
|
|
The context deliberately excludes `supabaseAdmin`. The MCP SDK rejects duplicate
|
|
tool names, and `jsonResult` returns both structured data and a text fallback for
|
|
older clients.
|
|
|
|
For typed table and column autocomplete, generate `database.types.ts` and make
|
|
the `SupabaseClient` in `tools/types.ts` a `SupabaseClient<Database>`.
|
|
|
|
## Environment
|
|
|
|
| Variable | Default | Purpose |
|
|
| ------------------------ | ---------------- | -------------------------------- |
|
|
| `MCP_SERVER_NAME` | `supabase-mcp` | Server name shown to MCP clients |
|
|
| `MCP_SERVER_DESCRIPTION` | Generic sentence | Instructions shown to clients |
|
|
|
|
The block includes `supabase/functions/mcp/.env.example`. Copy it before
|
|
serving locally, then customize the name and description:
|
|
|
|
```bash
|
|
cp supabase/functions/mcp/.env.example supabase/functions/.env
|
|
```
|
|
|
|
Add `supabase/functions/.env` to `.gitignore`. Supabase supplies the project URL,
|
|
API keys, and function slug to Edge Functions automatically; OAuth discovery
|
|
combines the slug with the public origin the gateway forwards to advertise the
|
|
function's public URL.
|
|
|
|
## Deploy
|
|
|
|
Check the function before serving or deploying it:
|
|
|
|
```bash
|
|
cd supabase/functions/mcp
|
|
deno task check
|
|
cd ../../..
|
|
supabase functions serve mcp --env-file supabase/functions/.env
|
|
```
|
|
|
|
Then deploy:
|
|
|
|
```bash
|
|
supabase config push
|
|
supabase secrets set --env-file supabase/functions/.env
|
|
supabase functions deploy mcp
|
|
```
|
|
|
|
## Further reading
|
|
|
|
- [OAuth Consent block](../nextjs/oauth-consent)
|
|
- [`withOAuthProtectedResource` and `pipeline` composition](https://github.com/supabase/server/blob/main/docs/api-reference.md)
|
|
- [MCP authentication](https://supabase.com/docs/guides/auth/oauth-server/mcp-authentication)
|
|
- [OAuth 2.1 server](https://supabase.com/docs/guides/auth/oauth-server/getting-started)
|
|
- [Token security and RLS](https://supabase.com/docs/guides/auth/oauth-server/token-security)
|
|
- [OAuth grant management](https://supabase.com/docs/guides/auth/oauth-server/oauth-flows#managing-user-grants)
|
|
- [Edge Functions](https://supabase.com/docs/guides/functions)
|