Connectors
MCP servers an organization connects, each user's OAuth grant behind a credential reference, MCP sessions per chat and tool list fingerprints an admin approves.
The connectors block stores the MCP servers an organization lets its
assistants call. Tokens never sit in these tables: a grant holds a
credential_ref that a credential provider
resolves, and removing a grant or its server revokes the credential.
better-supabase add connectors # adds tenant and access as well| Table | Holds |
|---|---|
connector_servers | The server URL, transport (http or sse), auth type and scopes |
connector_grants | One active grant per user and server, with its credential_ref |
connector_sessions | The MCP session id and initialize result per user, server and chat |
connector_tool_fingerprints | A digest of each tool list the server returned, and its review status |
A server's auth type is none, header (an app credential sent as
headers) or oauth (one grant per user). A header server's
credentialRef must carry the server's tenant
(tenant refs), or the save fails
with CREDENTIAL_REF_FOREIGN. Server URLs must use https
unless allowHttp is on, and sessions expire after sessionTtl (1 hour
by default).
Exports leave out credential_ref on servers and grants. The organization
purge in data lifecycle revokes a server's credential and each grant's (for the
grant's user) before it deletes the rows, when the ref carries the
organization; a grant ref without a tenant comes back in
credentials.unrevoked.
| Permission | Lets a member | Default roles |
|---|---|---|
connectors.read | see the organization's servers | owner, admin, member |
connectors.use | connect and call a server | owner, admin, member |
connectors.manage | add servers and approve tool lists | owner, admin |
Rename the keys with blocks.connectors.permissions.read, .use and
.manage.
Server
Server code calls the connectors instance on db, in the caller's organization. With gen.hooks set, better-supabase gen writes the hooks:
export const { useList: useConnectors } = defineDataHooks(
"connectors",
(db: AppDb) => db.connectors,
);const rows = await db.connectors.list({ limit: 50 }).orThrow();"use client";
import { useConnectors } from "@/lib/supabase/hooks";
const rows = useConnectors({ limit: 50 });| Group | Methods |
|---|---|
servers | list, get, create, update, remove |
grants | record, revoke, expiring, renew |
sessions | get, save, forget, purge |
fingerprints | check, approve, reject |
servers.get(id) returns the caller's active grant with the server.
grants.record runs as the service role after the provider stored the
credential, and revokes the grant it replaces. grants.expiring(before)
lists grants to renew.
Your own columns
Add columns to connector_servers with alter table in your own schema files, then
pass a Standard Schema for them as fields. servers.create and
servers.update validate the fields you pass and write them in the same
upsert_connector_server call as the server's own columns; a column you
leave out keeps its value. servers.list, servers.get, create and
update return the columns parsed under fields, keyed by column name.
alter table "better_supabase"."connector_servers" add column "region" text not null default 'eu';import {
createConnectors,
rpcTransport,
} from "better-supabase/blocks/connectors";
import { z } from "zod";
const connectors = createConnectors({
transport: rpcTransport(supabase),
fields: z.object({ region: z.enum(["eu", "us"]) }),
});
const server = await connectors.servers
.create(organizationId, {
name: "GitHub",
url: "https://mcp.example.com/mcp",
fields: { region: "us" },
})
.orThrow();
server.fields.region; // "eu" | "us"The block also takes hooks around its methods; see
extending blocks.
Tool list changes
A server can change its tools at any time. fingerprints.check records the
digest of the tool list and returns its status: the first list of a server
is approved, a later different list waits as pending until an admin
approves or rejects it. With trustFirstUse: false the first list waits
too. Until then the assistant gets none of the server's
tools.
AI SDK
better-supabase/ai-sdk/mcp runs the OAuth flow,
connects to a server with the stored session and returns its tools.
Without the client
db.connectors is this client. Code that does not go through bsb.db() builds it with a transport and an organization id:
import { vaultCredentials } from "better-supabase/credentials";
import {
createConnectors,
rpcTransport,
} from "better-supabase/blocks/connectors";
export const connectorsFor = (
supabase: SupabaseClient,
admin: SupabaseClient,
) =>
createConnectors({
transport: rpcTransport(supabase),
service: rpcTransport(admin),
credentials: vaultCredentials({ transport: rpcTransport(admin) }),
});Last updated on
Durable streams
Resumable output for chats, workflows and agents, stored in Postgres or Redis, with a cancel flag the writer reads on its next write.
Automations
Tenant-editable rules that test a subject against a filter tree when a trigger event happens and name the actions your app runs, evaluated the same way in SQL and TypeScript.