Skip to content

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.

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

  1. Look around. introspect_schema returns 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_docs and project_limits show what exists and what your plan allows.
  2. Design the schema. create_table for customers, services and appointments (with dry_run: true it returns the SQL for you to read), then alter_table for changes.
  3. Secure it. create_policy and set_rls so owners see only their own rows. get_advisors flags tables without RLS and other issues.
  4. Add logic. db_functions_create writes a SQL function such as book_slot (safe defaults: SECURITY INVOKER, empty search_path, EXECUTE granted only where you say), and rpc_call tests it as a given user. functions_create, functions_test_run and functions_deploy handle an Edge Function such as send-reminder, and function_secrets_set stores its secret (write-only, never returned). For a Flow, flows_node_catalog and flows_validate_graph come first, then flows_deploy and flows_test_run.
  5. Ship. plan_migration dry-runs the SQL first (breaking changes, locks, and whether the policy gate lets it through; nothing is kept), apply_migration applies it, generate_typescript_types (add annotate: true for RLS, grant and function-permission comments) and get_sdk_snippet give you typed client code that matches your tables.

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

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.

Terminal window
claude mcp add --transport http potalab-base https://base.potalab.com/mcp

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

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.

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.

Terminal window
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-app

Claude Desktop and Cursor use the same command, args and env in their mcpServers JSON.

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.

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.

  • “List my tables and tell me which ones have no RLS policy.”
  • “Add a todos table 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_limits and tell me what I can still create.”
  • 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.

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_sql with read_only: false.
    • set_rls disabling RLS, which needs confirm, the user’s reason in user_ack, and an operator who allows acknowledgements.
  • --policy-gate error|warn|off (env POTALAB_BASE_MCP_POLICY_GATE), default error:
    • 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. At warn, a preview that cannot run only warns.
  • --allow-policy-ack (env POTALAB_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.
  • Not gated:
    • create_table, alter_table and create_policy are validated by the server and need confirm for drops.
    • db_functions_create and db_functions_grant have no preview yet.
    • rpc_call can call a SECURITY DEFINER function 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 error it is refused.
    • A busy or rate-limited preview (409/429) refuses with policy_gate_failed marked retryable.
    • The set_rls user_ack reason 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.
  • Destructive tools need confirm set to the exact name: functions_delete (function), credentials_delete (credential id), delete_objects (bucket), db_functions_drop (schema.name).
  • Every execute_sql write (read_only: false) needs confirm set to the project ref. No statement is treated as “safe”. Use apply_migration for schema changes: it is recorded and goes through the permission check.
  • Read-only execute_sql runs one statement in a server-side READ ONLY transaction that is rolled back. Writes, including writes through functions such as setval, fail there. The owner role cannot terminate other sessions or use dblink.