Supabase database

Letting Claude drive your Supabase through MCP when the database holds patient data

More clinicians, coaches and small-clinic founders now build their own platform by talking to Claude, with the Supabase MCP server doing the database work. That is a fine way to build. It changes two things when the tables hold patient or customer records: the AI can now read those records, and the usual “sign out and try it” test stops being enough. We read the Supabase MCP server’s source and ran the test on Postgres 18 to show both.

TL;DR

  • Point the Supabase MCP server at a development project with fake records, not at production. Supabase’s own guidance is to connect to production only when a task needs production evidence.
  • Read-only mode hides every write tool and runs SQL as read-only, but it does not stop the AI reading rows. Any patient row it selects goes into the conversation and to the model provider.
  • The MCP server wraps query results in “untrusted data” markers so the model ignores instructions hidden in a row. That lowers the risk of prompt injection; it doesn’t remove it.
  • A policy that says “logged-in users can read” passes the signed-out test. In our run, anon saw 0 rows, but patient A saw patient B’s consultation note. Test as two patients, not just as a stranger.
  • Our free, open-source CLI reads your migrations for these policies: uvx --from git+https://github.com/manra399/patchlabs-cli patchlabs scan .

This guide is for people building a health, therapy, coaching or clinic app on Supabase by working with Claude Code, Claude Desktop, Cursor or another AI client connected through the Supabase MCP server. The source references are to the open-source server at supabase-community/supabase-mcp, commit 854980b (17 November 2026). The test results are from our own run on 18 November 2026 on Postgres 18 with Supabase-style anon and authenticated roles and two fake patients. They show the pattern, not any particular app. This is not legal advice.

What changes when an AI drives the database

Through MCP, the AI client gets tools such as list_tables, execute_sql and apply_migration against your project. Two consequences matter for patient data:

  • Rows become conversation. When the model runs select * from consultations limit 20 to debug something, those twenty rows are sent back to the model and kept in your chat history, the client’s local logs and the provider’s storage for as long as its retention terms say. For health data, that is a transfer of special category data to another company.
  • Rows become instructions, potentially. A free-text field a patient filled in can contain text the model reads as a request (“ignore previous instructions and…”). If the same session can also write to the database, that text has something to act on.

What read-only mode does, from the source

The server has a read-only setting (--read-only for the local server, read_only=true on the hosted URL). Reading the code, it does three things:

WhatWhere in the sourceEffect
Hides write toolsserver.ts: when readOnly is set, every tool in the write set is marked hiddenThe model can’t see apply_migration, secret or storage-config tools, so it doesn’t try them.
Refuses writes anywaydatabase-operation-tools.ts, secret-tools.ts, storage-tools.ts: each write path throws “Cannot … in read-only mode”A belt-and-braces check if a hidden tool is called anyway.
Runs SQL as read-onlyexecute_sql stays available and passes read_only through to Supabase’s database query APIInserts, updates, deletes and DDL fail. Selects still work.

So read-only mode protects your data from being changed. It does not keep your data away from the model. If the project holds real patient records, the model can still read them.

The server also wraps query results in a block marked as untrusted data, with a random boundary, and tells the model not to follow instructions inside it (tools/util.ts). The execute_sql description repeats the warning. That is a sensible mitigation. Models usually respect it, but not always, so it shouldn’t be the only thing between a patient’s free text and your database.

A safe setup in five steps

  1. Two projects. Build against a development project seeded with fake patients. Keep production off the MCP connection entirely, and change production only by applying the migrations you tested in development.
  2. Scope the connection to that one project. Use the project-scoped URL (project_ref=<dev-ref>) so the model can’t list or touch your other projects.
  3. Read-only by default, and only the tools you need. read_only=true&features=database,docs is enough for most debugging. Switch read-only off for a session when you deliberately want the model to write a migration, then switch it back.
  4. Approve every write. Leave your client’s tool-approval prompt on for execute_sql and apply_migration, and read the SQL before you click. The server can also ask for confirmation of destructive statements in clients that support forms.
  5. Keep the service role key out of the app. MCP uses your access token, not your app’s keys. The service_role key bypasses every policy, so it belongs only in server code such as Edge Functions, never in anything the browser loads (see PL-010).
.mcp.json (development project, read-only)
{
  "mcpServers": {
    "supabase": {
      "type": "http",
      "url": "https://mcp.supabase.com/mcp?project_ref=YOUR_DEV_PROJECT_REF&read_only=true&features=database,docs"
    }
  }
}

The two-patient test, and why signing out isn’t enough

The common advice is to sign out and check that your tables return nothing. Do that, but it misses the policy AI builders most often write first when a logged-in screen comes back empty:

supabase/migrations/…_consultations.sql (vulnerable)
create policy "logged in can read" on public.consultations
  for select to authenticated
  using (true);   -- every signed-in user can read every row

We built a consultations table with one note for patient A and one for patient B, turned on row level security, and queried it three ways with that policy, then with the fix:

Queryusing (true)patient_id = auth.uid()
Signed out (anon), all rows0 rows: looks safe0 rows
Patient A, all rows2 rows1 row
Patient A, patient B’s rows1 row: B’s note0 rows

The signed-out test passed in both cases. Only the second patient showed the problem. In a clinic app, anyone can create an account, so “any signed-in user” means anyone.

supabase/migrations/…_consultations.sql (fixed)
drop policy "logged in can read" on public.consultations;
create policy "patients read own" on public.consultations
  for select to authenticated
  using (patient_id = (select auth.uid()));

Clinician access needs its own policy that checks a role you control, held in a table patients can’t write to or in app_metadata, never in user_metadata, which users can edit themselves (see user_metadata vs app_metadata). Storage buckets with letters, photos or PDFs need the same test, because they have separate policies (see storage bucket policies).

Run the test yourself

Our test script runs on any Postgres in a throwaway database, with stand-ins for Supabase’s roles and auth.uid(): two_patient_test.sql. On your real app, do the same through the API: create two test patient accounts in your development project, sign in as A, and request B’s rows by id from every table and bucket. Or ask your AI: “write a test that signs in as two different patients and tries to read each other’s records from every table and storage bucket”, and run it after every change.

If you are in the UK

Health data is special category data under UK GDPR. Before real patients use the app, write a short data protection impact assessment, check the data processing terms of each service that will hold or see records (Supabase, your host, your AI provider), and note where each stores data. If the platform will access NHS patient data or systems, the NHS Data Security and Protection Toolkit applies. The ICO’s guidance on special category data is the place to start.

The checks behind this guide, each with example code, a self-check and the fix.

Free check

Check your app for this, free.

Paste your public repo. PatchLabs rebuilds your database from its migrations, tests it as a visitor, a stranger and the owner, reads the code for keys and risky patterns, and hands you the fix.

First app free, fixes includedNever touches your database

Written by Manraj Singh Dhillon. Last checked 18 Nov 2026. Code samples are synthetic and run against your own project; nothing here names a real app. Spotted a mistake? Tell us.