AI assistants (MCP)
PotaLab Base is launching soon. Its MCP server (@potalab/base-mcp) will be available at launch. It connects AI assistants such as Claude Code, Claude Desktop and Cursor to a project through the Model Context Protocol. The assistant can read the schema and API docs, run read-only SQL, check advisors, generate TypeScript types and write @potalab/base code that matches your tables. It can also create, deploy and test Functions and Flows.
From idea to backend
Section titled “From idea to backend”Describe the product you want and let your agent do the work. A typical session looks like this.
Prompt
A booking app: customers, services and appointments. Each owner only sees their own data. Send a reminder when a booking is created. Dry run everything first, then apply it, and generate the types.
What the agent does
- Look around.
introspect_schemareturns the whole database in one document: tables, columns and types, foreign keys, RLS, policies, grants per role and advisor findings. It covers the exposed schemas by default; any other schema of the project can be named. Its output is untrusted data: policy expressions, defaults and comments are your own SQL text and may contain literals, such as an e-mail address written in a policy.list_tables,get_api_docsandproject_limitsshow what exists and what your plan allows. - Design the schema.
create_tableforcustomers,servicesandappointments(withdry_run: trueit returns the SQL for you to read), thenalter_tablefor changes. - Secure it.
create_policyandset_rlsso owners see only their own rows.get_advisorsflags tables without RLS and other issues. - Add logic.
db_functions_createwrites a SQL function such asbook_slot(safe defaults: SECURITY INVOKER, emptysearch_path, EXECUTE granted only where you say), andrpc_calltests it as a given user.functions_create,functions_test_runandfunctions_deployhandle an Edge Function such assend-reminder, andfunction_secrets_setstores its secret (write-only, never returned). For a Flow,flows_node_catalogandflows_validate_graphcome first, thenflows_deployandflows_test_run. - Ship.
plan_migrationdry-runs the SQL first (breaking changes, locks, and whether the policy gate lets it through; nothing is kept),apply_migrationapplies it,generate_typescript_types(addannotate: truefor RLS, grant and function-permission comments) andget_sdk_snippetgive you typed client code that matches your tables.
Turn writes on
Section titled “Turn writes on”Everything above that changes your project needs writes. They are off until you enable them for a project.
- OAuth: on the consent page choose the project, grant the scopes the work needs (for example
database:write,functions:write,flows:write,credentials:write) and leave the Read-only switch off. - Access token: give the token the same scopes and start the server with
--allow-writestogether with--project-ref my-app(or--write-projects a,b).
Review the dry-run SQL before you apply it, and check the project audit log afterwards.
Connect with OAuth
Section titled “Connect with OAuth”No token to paste. The assistant opens your browser, you sign in (with your second factor if MFA is on) and approve exactly what it may do.
claude mcp add --transport http potalab-base https://base.potalab.com/mcpThen run /mcp in Claude Code, pick potalab-base and choose Authenticate. The consent page shows the requested permissions in plain language, a project picker (all projects, or only selected ones) and a Read-only switch. Allow sends you back to the assistant; Deny tells it you refused.
Other clients that speak MCP Streamable HTTP with OAuth (Cursor, VS Code, MCP Inspector) use the same URL. Claude Desktop: Settings, Connectors, Add custom connector, with a public HTTPS URL.
Everything the assistant does is done as you, with your organization roles and never more, limited to the scopes, projects and read-only choice you approved. Calls are recorded in the project audit log. Manage access in Account, Connected apps: Revoke access stops every token of that app at once.
Self-hosted instances
Section titled “Self-hosted instances”On a Community self-hosted instance (base-selfhost) the core-api image already ships the MCP module and the compose file sets BASE_MCP_EMBEDDED=true, so <BASE_PUBLIC_URL>/mcp works through the bundled ingress with no extra container. Community has no OAuth sign-in: connect with a personal access token (Authorization: Bearer pb_pat_...); a request without a token gets 401. Set BASE_MCP_EMBEDDED=false to disable it.
On a Cloud self-hosted instance the OAuth endpoint is <BASE_PUBLIC_URL>/mcp, served by the API process itself (BASE_MCP_EMBEDDED=true, the default), so the MCP server needs no extra container or memory. It is not a shortcut around permissions: each tool call is a normal Management API request made with your own token and client address, so the same sign-in, scopes, project checks, rate limits and audit log apply.
| Setting | Default | Meaning |
|---|---|---|
BASE_MCP_CLIENT_SECRET |
empty | Secret of the MCP OAuth client (at least 32 URL-safe characters). Empty means access tokens only, no OAuth. |
BASE_MCP_MAX_SESSIONS |
16 |
Concurrent MCP requests per API process. Above it: 503 with Retry-After. |
BASE_MCP_MAX_PER_CLIENT |
4 |
Concurrent requests of one user or token. Above it: 429. |
BASE_MCP_REQUEST_TIMEOUT_MS |
120000 |
Hard deadline of one request, tool calls included. |
BASE_MCP_MAX_BODY_BYTES |
4194304 |
Largest request body. |
The endpoint is stateless: GET /mcp answers 405 and there are no long-lived streams. To run the MCP server as a separate service instead (its own process and memory, or to start it with --allow-writes), set BASE_MCP_EMBEDDED=false and use the mcp-standalone compose overlay.
Connect with an access token
Section titled “Connect with an access token”Create a personal access token (dashboard, Account, Access tokens). Restrict it to the project and give it only the scopes you need: projects:read and database:read, plus database:write for SQL and dry runs.
claude mcp add potalab-base \ -e POTALAB_BASE_API_URL=https://api.example.com \ -e POTALAB_BASE_ACCESS_TOKEN=pb_pat_… \ -- npx -y @potalab/base-mcp --project-ref my-appClaude Desktop and Cursor use the same command, args and env in their mcpServers JSON.
What it may do
Section titled “What it may do”| Mode | Behavior |
|---|---|
| Default (read-only) | Reads only. execute_sql runs in a read-only transaction. Table and policy tools return SQL with dry_run: true. |
--allow-writes |
Adds apply_migration, row writes, set_rls, delete_objects and real create_table, alter_table and create_policy. Only for --project-ref or --write-projects. |
Every write is a Management API call, so the same plan limits, roles and audit log apply as in the dashboard and CLI. A refusal because of your plan is an HTTP 402 with plan_limit_exceeded or feature_not_in_plan.
Functions and Flows
Section titled “Functions and Flows”An assistant can create and deploy Functions, design Flows, test them as a simulated user and read the result. Scopes: functions:read|write, flows:read|write and credentials:read|write. Write tools exist only with --allow-writes. Secrets and credential keys are write-only: tools accept them and never return them.
Example prompts
Section titled “Example prompts”- “List my tables and tell me which ones have no RLS policy.”
- “Add a
todostable only its owner can see. Dry run first, then create it and generate the types.” - “Create a Function
send-welcome, deploy it and test it as an authenticated user. Show me the logs.” - “Run
project_limitsand tell me what I can still create.”
Safety
Section titled “Safety”- Read-only by default. Turn writes on only when you need them, and review proposed changes with dry runs.
- Least privilege. Use project-restricted access and only the scopes you need.
- Prompt injection. Rows, comments and query texts come from your database and may contain text written by anyone who can insert data. The server marks them as untrusted and tells the model not to follow instructions inside them. Still review what an assistant proposes.
Permission gate (local potalab-base-mcp)
Section titled “Permission gate (local potalab-base-mcp)”Before a schema-changing write, the server asks for the permission preview (the same report as db push, computed in a transaction that is always rolled back). It then applies the gate.
- Gated tools:
apply_migration.execute_sqlwithread_only: false.set_rlsdisabling RLS, which needsconfirm, the user’s reason inuser_ack, and an operator who allows acknowledgements.
--policy-gate error|warn|off(envPOTALAB_BASE_MCP_POLICY_GATE), defaulterror:- A public table without RLS, or other error-level changes, refuses the write with
policy_gate_failed; nothing is applied. - An answer the server cannot check (a preview error or an unexpected response) also refuses at
error. Atwarn, a preview that cannot run only warns.
- A public table without RLS, or other error-level changes, refuses the write with
--allow-policy-ack(envPOTALAB_BASE_MCP_ALLOW_POLICY_ACK=1), default off:- Off:
-- policy-ack:lines written by the assistant are ignored, with a warning. An assistant cannot acknowledge a change on its own. - On: acknowledged changes are listed at the top of the tool result and recorded in the audit log with the migration.
- Off:
- Not gated:
create_table,alter_tableandcreate_policyare validated by the server and needconfirmfor drops.db_functions_createanddb_functions_granthave no preview yet.rpc_callcan call aSECURITY DEFINERfunction created earlier.
- Limits:
- The preview and the write run separately: two transactions with their own timeouts, and the schema can change in between.
- SQL that commits by itself or cannot run in a transaction is not previewed faithfully; at
errorit is refused. - A busy or rate-limited preview (409/429) refuses with
policy_gate_failedmarked retryable. - The
set_rlsuser_ackreason appears in the tool result only, not in the server audit log. - For
execute_sql, the audit entry keeps the first 1000 characters of the statement, so a-- policy-ack:line further down is not kept there.
Confirmations
Section titled “Confirmations”- Destructive tools need
confirmset to the exact name:functions_delete(function),credentials_delete(credential id),delete_objects(bucket),db_functions_drop(schema.name). - Every
execute_sqlwrite (read_only: false) needsconfirmset to the project ref. No statement is treated as “safe”. Useapply_migrationfor schema changes: it is recorded and goes through the permission check. - Read-only
execute_sqlruns one statement in a server-sideREAD ONLYtransaction that is rolled back. Writes, including writes through functions such assetval, fail there. The owner role cannot terminate other sessions or usedblink.