nodecode-supabase
A Nodecode cell: your Supabase projects, tables, SQL, row selects, migrations and logs as tools the model calls. Read-only unless you turn writes on.
Written for Nodecode from Supabase's documented Management API and PostgREST's query syntax; no code of Supabase's is in it. MIT.
Tools
| Tool | What it does |
|---|---|
supabase_projects |
Every project the access token reaches: ref, name, region, status, Postgres version, organization, created date. |
supabase_tables |
A project's tables in the schemas asked for (public by default): schema, name, kind, row level security on and forced, the planner's row estimate, size on disk. |
supabase_query |
One SQL statement. A read goes to the read-only endpoint (POST /v1/projects/{ref}/database/query/read-only), which runs it as the role supabase_read_only_user; name tables with their schema (public.orders). A statement that changes anything needs write: true in the call and allow_writes in the section, and then goes to POST /v1/projects/{ref}/database/query with read_only: false. |
supabase_select |
Rows of one table or view of the section's project through its Data API (PostgREST GET /rest/v1/{table}): columns, filters (eq, neq, gt, gte, lt, lte, like, ilike, is, in, ANDed), order, limit (up to max_rows), offset, and schema (sent as Accept-Profile). It runs as the API key's role, so a publishable key keeps row level security on. |
supabase_migrations |
The migrations applied to a project's database, newest first: version and name. |
supabase_logs |
Recent log entries of one source (edge_logs by default; postgres_logs, auth_logs, function_logs, function_edge_logs, storage_logs, realtime_logs, postgrest_logs, supavisor_logs), newest first, optionally holding a search text, over the last minutes (60 by default, at most 1440), from GET /v1/projects/{ref}/analytics/endpoints/logs. Or your own ClickHouse sql over the logs table in the same window. |
Every tool but supabase_select takes an optional project_ref; without it
the section's project_ref is used. /supabase checks the access token by
listing the projects it reaches, and says whether the Data API key is set and
whether writes are allowed. (help :supabase) gives the model the workflow.
Setup
- Create a personal access token at
https://supabase.com/dashboard/account/tokens and export it as
SUPABASE_ACCESS_TOKEN. - For
supabase_select, setproject_refand export the project's publishable key (dashboard, Project Settings, API Keys) asSUPABASE_KEY. - Add a
supabasesection to~/.nodecode/config.jsonc(seeconfig.example.jsonc) and run/supabase.
Settings
| Setting | Default | Meaning |
|---|---|---|
base_url |
https://api.supabase.com |
Where the Management API answers. |
access_token_env |
SUPABASE_ACCESS_TOKEN |
The environment variable holding the personal access token. |
access_token |
none | A token written in the config instead; the environment variable wins. |
project_ref |
empty | The default project, twenty lowercase letters. supabase_select always reads this one. |
project_url |
empty | Where the project's Data API answers; https://<project_ref>.supabase.co when empty. |
api_key_env |
SUPABASE_KEY |
The environment variable holding the project's API key for the Data API. |
api_key |
none | A key written in the config instead; the environment variable wins. |
allow_writes |
false |
Let supabase_query run a statement that changes anything when the call passes write: true. |
timeout |
60 |
One API call's ceiling, in seconds. |
max_rows |
100 |
The most rows, log entries or migrations one answer carries (and supabase_select's default and largest limit). |
max_chars |
30000 |
How many characters one answer carries in all. |
Safety
- Reads are read-only on the server. The guarantee is Supabase's
read-only endpoint, which runs the statement as
supabase_read_only_user. In front of it the cell reads the SQL the way PostgreSQL's lexer does (identifiers and dollar-quote tags with non-ASCII characters,$inside identifiers,E'...'escapes, nested block comments) and refuses a call holding more than one statement, a string, quote or comment left open, an empty statement, a NUL, or a statement whose first keyword is notSELECT,WITH,VALUES,TABLE,EXPLAINorSHOWunless the call writes. The keyword is the whole first word as PostgreSQL reads it (letters, digits,_,$), soSELECT_1is notSELECT. - Writes need two switches:
write: truein the call andallow_writesin the section. With either off, a statement goes only to the read-only endpoint, or is refused before anything is sent. - The keys ride headers only. The access token goes only to the
Management API as
Authorization: Bearer; the project's API key goes only to the Data API asapikey(and asAuthorization: Bearerwhen it is a legacy JWT key). Neither ever rides a URL or a body, and every answer and error has both replaced by[redacted]; the replacement resumes past each match, so no key can make it loop, and an earlier[redacted]is left whole. Text is scrubbed before any cut (max_chars, a 300-character table cell or error body), so a key the cut would split leaves no prefix. - No key leaves for the wrong host.
base_urlandproject_urlmust be plainhttps://host[:port]addresses, orhttp://only to this machine (localhost,127.0.0.0/8,::1); userinfo (user@), backslashes, blanks and control characters, a query, a fragment and a malformed port are refused, and the scheme is read in any case. Where Nodecode's HTTP client allows it no redirect is followed, so a key reaches only the host named. - Nothing a call carries becomes syntax. Project refs must be twenty
lowercase letters. Tables, schemas, columns and order keys must be plain
names (letters, digits,
_,$; not opening with a digit or a dash), and a filter cannot name a PostgREST parameter (select,order,limit,offset,and,or,not,on_conflict,columns). Filter values are percent-encoded,inlists are double-quoted with their quotes and backslashes escaped,istakes onlynull,true,falseorunknown.supabase_tablesschemas become SQL string literals; the log search becomes an escaped ClickHouse literal. - Answers are bounded: at most
max_rowsrows andmax_charscharacters, with the full count said.