Free toolGenerate .mcp.json configs for Claude Code, Cursor & Codex →

Based on Supabase's and Anthropic's official docs, checked

How to add a Supabase database with Claude Code

Supabase scores 5/5 on our Claude Code fit scale: it ships an official Anthropic-marketplace plugin with an MCP server and 2 skills. Supabase is Postgres with auth, storage, and an auto-generated API on top, so you get a real database without running one yourself. This guide takes you from an empty project to a table your app can read, with Row Level Security switched on before any real user data lands in it. Every step links its source.

  1. 1. Create a Supabase project and open Claude Code

    You need Claude Code installed and a Supabase account. Create a new project from the Dashboard of any organization you belong to. Give it a name, set a database password, and pick a region near your users, then wait for the project to finish provisioning. Save the database password somewhere safe. You need it for direct Postgres connections, and you cannot read it back later from the Dashboard.

    cd my-app
    claude

    Source: https://supabase.com/docs/guides/getting-started/quickstarts/nextjs

  2. 2. Install the official Supabase plugin

    The Supabase plugin for AI coding agents bundles the Supabase MCP server and the Supabase agent skills into one install, so your agent can query your database, manage migrations, deploy Edge Functions, and follow Supabase and Postgres best practices without manual configuration. Run the install inside Claude Code, then reload plugins to activate it.

    /plugin install supabase@claude-plugins-official
    /reload-plugins

    Source: https://supabase.com/docs/guides/ai-tools/plugins

  3. 3. Connect the MCP server and sign in

    The plugin already includes the MCP server, but if you want it on its own, or you want to control the scope, add the hosted server from your terminal. The command below scopes it to your project. Add read_only=true to the URL when you only want to explore, so every query runs as a read-only Postgres user. After adding it, run claude /mcp, select the supabase server, and choose Authenticate to sign in through your browser.

    claude mcp add --scope project --transport http supabase "https://mcp.supabase.com/mcp?project_ref=YOUR_PROJECT_REF"
    claude mcp list

    Source: https://supabase.com/docs/guides/ai/mcp

  4. 4. Create your first table in the SQL Editor

    Open the SQL Editor in your Supabase Dashboard and run the snippet below. It creates a todos table where every row belongs to one user, through a user_id column that references auth.users. Keep your first table small. You can add columns later with a migration instead of rebuilding the table.

    create table public.todos (
      id uuid primary key default gen_random_uuid(),
      user_id uuid references auth.users not null,
      title text not null,
      done boolean not null default false,
      created_at timestamptz not null default now()
    );

    Source: https://supabase.com/docs/guides/getting-started/quickstarts/nextjs

  5. 5. Turn on Row Level Security before you ship data

    Row Level Security (RLS) is the rule engine that decides which rows each user can see. Once RLS is enabled on a table, no data is accessible through the API with a publishable key until you create policies. Add one policy per operation, and name the role each policy applies to with the to clause. The two policies below let a signed-in user read and insert only their own rows. The auth.uid() helper returns the ID of the user making the request.

    alter table public.todos enable row level security;
    
    create policy "Users can read their own todos"
      on public.todos for select to authenticated
      using ((select auth.uid()) = user_id);
    
    create policy "Users can insert their own todos"
      on public.todos for insert to authenticated
      with check ((select auth.uid()) = user_id);
    
    grant select, insert, update, delete
      on public.todos to authenticated;

    Source: https://supabase.com/docs/guides/database/postgres/row-level-security

  6. 6. Add the client to your app and set your keys

    For a new Next.js app, use the with-supabase template. It comes pre-configured with cookie-based auth, TypeScript, and Tailwind CSS, and it already installs the Supabase client libraries. For an existing app, install supabase-js yourself. Then rename .env.example to .env.local and fill in your Project URL and publishable key from the project Connect panel. The publishable key starts with sb_publishable_ and is safe to use in browser code. Never commit .env.local to git.

    npx create-next-app -e with-supabase
    npm install @supabase/supabase-js
    NEXT_PUBLIC_SUPABASE_URL=https://your-project-ref.supabase.co
    NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_...

    Source: https://supabase.com/docs/guides/auth/quickstarts/nextjs

  7. 7. Ask Claude Code to wire up the first query

    Now let the agent do the wiring. Paste the prompt below into Claude Code, then review the plan before it changes files. The supabase skill carries the current patterns for auth, server-side rendering, and migrations, so the agent works from Supabase's own guidance instead of its training data. When it is done, run the dev server and open the page to confirm your rows render. If the page comes back empty, check your RLS policies first, not your query.

    Add a page at /todos that lists rows from the public.todos table
    using the Supabase server client. Follow the supabase skill and the
    supabase-postgres-best-practices skill. Keep keys in environment
    variables, do not change the RLS policies, and show me the plan
    before you change files.
    npm run dev

    Source: https://supabase.com/docs/guides/ai/mcp

What the plugin gives you

The MCP server exposes tools your agent can call against the live project: list_tables to see your schema, execute_sql to run queries, apply_migration to change the schema, generate_typescript_types to build types from your tables, and get_advisors for security and performance warnings. Ask it in plain language, for example "What tables are there in the database? Use MCP tools."

The two skills carry the procedural knowledge. The supabase skill covers the core products: Database, Auth, Edge Functions, Storage, and Realtime. The supabase-postgres-best-practices skill covers query optimization, schema design, connection management, and RLS patterns. Claude loads a skill when the work matches it, or you can call one directly with its name.

The RLS rules that save you

Postgres runs two checks before a client touches a table. Grants decide whether a role can run an operation on the table at all, and policies decide which rows that operation applies to. Set both for every table you expose. A missing grant raises a 42501 error before any policy runs, so when a request fails that your policy should allow, check the grants before you change the policy.

A new table in the public schema starts with every privilege already granted to the anon, authenticated, and service_role roles. That means a table protected only by policies still hands anon an insert path if you never revoke the grant. Revoke what each role does not need, then grant back only the operations your app actually uses.

Keep secrets out of the browser

The publishable key is safe in browser code because RLS still applies to every request made with it. The secret key is different. It authorizes access through the service_role Postgres role, which bypasses RLS entirely, so keep it server-side only and never paste it into chat, model input, or MCP tool arguments. The same rule applies to Edge Function secrets: enter the value in the Supabase Dashboard, never in a conversation with the agent.

Before you deploy, set your Supabase credentials as environment variables on your hosting platform instead of committing them to source control, and review your RLS policies against real user data, not just sample rows.

Test your policies

Supabase's own guidance is to prove every policy with a test, not just to eyeball it. Create one test file per table under supabase/tests/, assert allow and deny for select, insert, update, and delete, for both anon and authenticated, then run the suite with supabase test db. Until the suite passes, you do not know whether the policies do what you intended. Ask Claude Code to write the test file for your table and run it for you.

Tips

Then just ask

Example prompt (our suggestion, not from vendor docs):

"Help me add a Supabase database in this project. Follow the Supabase skills, keep secrets in environment variables, and show me the plan before changing files."

Next steps

Frequently asked questions

No. The Supabase plugin bundles the MCP server and both agent skills into one install. Add the MCP server separately only if you want to control the scope, for example read-only mode or a single project.

Sources