Permission Boundaries That Let Claude and GPT Agents Read Named Metrics Without a Supabase Service Role
A read-only role, RLS, and a semantic layer keep agents safe.

Claude and GPT agents can read named metrics from Supabase without a service role key or direct access to production tables. The safe path combines a dedicated read-only Postgres role, row-level security, a governed semantic layer, and an MCP server that keeps the credential outside the agent. An audit trail makes that boundary verifiable by recording what the agent actually requested.
Why giving AI agents a service role key is the wrong starting point
Giving an agent a service_role key, or its current replacement, an sb_secret_ key, starts with authority the task does not require. Under Supabase’s key model, these credentials have privileged access that bypasses all row-level security. Reads can return every row, while writes and deletes are unrestricted. The authority also outlives the individual task. Ending an agent session does not expire a static credential, and a shared privileged identity leaves no per-user trail to reconstruct whose authority a request represented.
That exposure is only half the problem. A broad credential permits queries without explaining what the data means, so the agent constructs metric definitions as it constructs SQL. Different constructions can produce different answers from the same records. The same trusted identity can also become a confused deputy, manipulated into modifying records or access groups under its legitimate authority. The database sees the intended task and the misuse as actions by an authorized caller.
How Supabase's permission model actually works, and what that means for agents
Supabase access control has two distinct layers. Grants determine which Postgres roles can reach a table through the Data API, while RLS policies determine which rows those roles can read or modify. Supabase’s API security guide requires both controls on every exposed object. A grant is therefore not a row filter, and a row filter does not replace a grant. An agent’s effective access depends on how the two work together.
A publishable key with the sb_publishable_ prefix, or a legacy anon key, runs as anon or as authenticated when paired with a user JWT, and remains subject to RLS. Supabase’s key model schedules the legacy anon key for deprecation by the end of 2026. By contrast, an sb_secret_ key and a legacy service_role key are server-side credentials that bypass RLS by design. Renaming the credential does not narrow its authority.
RLS requires both enabling and configuration. Supabase’s data security guide describes the default as deny-all when RLS is enabled without policies, while a read policy whose rule is simply true permits everyone to read. Supabase’s API security guide describes how revoking automatic grants makes exposure opt-in. Starting October 30, 2026, new tables on every project are not exposed to the Data API until access is explicitly granted. Existing tables keep the access they already had, so the change does not audit production tables that are already exposed.
The four credential shapes and what each one actually permits an agent to do
The four credential shapes differ in both authority and purpose. Shape 1 is a broad, static, long-lived secret key whose RLS bypass permits reads, writes, and deletes across tables. Its authority persists beyond the task that justified access. This is the shape to eliminate from the agent layer. Privileged authority belongs on the server, outside the agent.
Shape 2 uses an anon key with RLS enabled. The agent operates as the anon role and can see only what the relevant policies permit, provided RLS covers every relevant table. This can suit access that is intentionally available to that role. It is not read-only by default, however. Policies can permit writes and deletes, so an anon credential carries the permissions those policies grant.
Shape 3, the minimum configuration for metric-reading agents, has its own read-only Postgres role with grants that spell out what it can access. The concrete setup creates a login role limited to CONNECT, grants USAGE on the target schema and SELECT on its tables, and uses DEFAULT PRIVILEGES for future tables. Sensitive tables have SELECT revoked, with only safe columns re-granted. Session settings add SET default_transaction_read_only = on and a statement_timeout, while the grants make writes and deletes structurally unavailable.
Shape 4 uses JWT custom claims that say what the role is. Storing that role in app_metadata lets RLS policies read it from the token without a database lookup for every row evaluated. Users can modify user_metadata, so it must never supply authorization decisions. This shape supplies role context for policy evaluation rather than replacing the read-only grants that metric access requires.
Why RLS policies on their own are necessary but not sufficient for agent reads
A scoped read-only role with well-written RLS policies substantially reduces the blast radius. A SELECT still sends the rows it returns into the model’s context and out to the API. RLS limits which rows leave the database, leaving what happens to those rows afterward outside its control. A permission boundary can therefore work exactly as configured while exposing more content to a model than a metric question needs.
Content and query behavior create separate problems. Rows can contain injected instructions that redirect an agent, and read permissions do not sanitize those instructions. A read-only agent can also issue an expensive multi-table join against the largest tables in a schema. A statement_timeout caps duration but cannot prevent the work done before it fires.
Supabase’s API security guide places rate limits, quota enforcement, and blocking direct access to certain tables in pre-request checks through a db_pre_request function. RLS cannot substitute for those checks. The honest conclusion is that permissions are effective and necessary but incomplete. A trustworthy metric path must also constrain the content and query surface those permissions make available.
What a governed semantic layer does that permission boundaries alone cannot
A metrics layer, sometimes called headless BI, defines business metrics once in code so that every downstream consumer gets them in the same way. Its central contribution is an authoritative definition. Instead of allowing each tool or agent to decide what “ARR” or “monthly active users” means, the layer establishes that meaning before a query arrives. Permissions govern who may read the result. The semantic layer governs what that result represents.
A trusted intermediary keeps the credential, owns the definitions, and sends back pre-modeled, pre-calculated results. The agent queries a metric without constructing it. This narrows exposure from arbitrary rows and improvised SQL to the datasets required for the named metric. It does not turn permissions into optional controls or make content risks disappear. Rather, it supplies the constrained analytical surface that a read-only role alone cannot define.
For pre-product-market-fit startups, that distinction favors a small set of metrics they can trust over more dashboards. The governed layer serving the CEO dashboard should also serve the agent. When sales, finance, and product each have their own definitions of ARR, the executive team must work out why the numbers differ before they can discuss decisions. Using the same definition removes that source of disagreement. Claude or GPT then interprets a result calculated from that established definition.
Supabase’s API security guide describes how a schema such as api separates exposed objects from internal tables and helper functions in schemas the Data API does not expose. That separation makes the accessible surface easier to identify and audit. It also gives the semantic boundary a concrete database counterpart. The interface the agent uses can offer modeled results without letting it query the production tables behind them.
What MCP server should connect AI agents to Supabase with row-level access controls?
The appropriate MCP server exposes only the governed metric surface, keeps the production credential outside the agent, and provides an auditable interface. Protocol support alone is not enough to choose one. For analytical work, the selection criteria are explicit scope, governed metric definitions, an auditable interface, and no production credential at the agent layer.
Model Context Protocol is an open standard first released by Anthropic in late 2024. It standardizes how models call external tools and access resources, data sources, and APIs. In this access pattern, the agent asks a trusted MCP server for a result, and the server uses the credential without handing it over. MCP supplies the interface, while the governed semantic layer supplies the metric definition. Connecting it to uncertified tables still leaves the agent able to return confident wrong answers.
The 2026-07-28 MCP specification removes protocol-level sessions and the Mcp-Session-Id header from the Streamable HTTP transport. Its stateless protocol core lets tools make many short-lived calls without keeping connections open at the protocol level. That simplifies deployment across metadata, semantic definitions, query engines, and workflow systems. It does not replace identity, governance, or audit controls. Stateless transport governs the connection.
How the archived @modelcontextprotocol/server-postgres package was built still matters. Datadog Security Labs shows how sending multiple SQL statements together allows a stacked-query bypass of its read-only guard. The package was archived and deprecated in 2025, yet was pulled approximately 105,000 times in a single week in September 2026. A read-only label is not an enforced boundary. The database role beneath the interface must enforce the read-only restriction on its own.
The audit trail requirement that most implementations skip
A scoped credential and governed definitions establish what an agent is allowed to read. Audit establishes what it actually read. Every agent query should record the database, statement hash, duration, and outcome, without values or SQL text. Leaving those contents out keeps the audit log from becoming a second copy of the protected data. The resulting record supports scrutiny of the access path without reproducing its payload.
Agent defaults also need to be checked before the agent gets production access. Anthropic’s tools documentation states that all eight built-in tools are enabled by default when the agent toolset is included in Claude Managed Agents. Anthropic’s permission policies page distinguishes the agent toolset’s always_allow default from MCP toolsets’ always_ask default. The secure deployment guide describes unrestricted outbound internet as the default and recommends limited networking for production. These defaults require deliberate overrides rather than an assumption that every call receives human approval.
Audit provides the feedback loop for governing the access path over time. Recording duration and outcome shows how the system was used as well as what its permissions allowed, while statement hashes show which requests were made without keeping SQL text. Permission changes should also pass through a PR or equivalent review so that the exposed surface remains visible and version-controlled.
A governed layer without an audit trail is a promise with no receipt.
Putting the layers together: the access pattern that serves named metrics safely
The architecture begins with the constraints closest to the data. A dedicated read-only Postgres role receives explicit grants limited to the required schemas, with read-only session settings and a statement timeout. RLS on every exposed table specifies what the role may see rather than using unrestricted predicates such as true or 1=1. Where JWT role checks are needed, they use app_metadata, never user_metadata. A dedicated API schema separates exposed objects from internal tables, while pre-request checks enforce rate limits and quotas.
The governed semantic layer sits above those restrictions. Humans define the metrics in code before agents read them, and pre-calculated datasets provide the results. Because the same definitions serve the CEO dashboard and the agent, their numbers can reconcile without separate calculations. With pre-calculation, the agent also has no need to build a new query plan for each metric definition.
The MCP server then exposes that modeled surface as tools and resources. The agent requests a named metric, while the server holds the credential and returns the result without exposing the connection string. Stateless transport removes protocol-level sessions and keeps the permission boundaries in the layers below. Each layer enforces a constraint that the layer above cannot widen.
Every tool call leaves the required audit record, and permission changes still need to be reviewed. A human-governed definition, a restricted database identity, and an interface that exposes only the intended dataset bound the metric context. The agent reads metrics it did not define, through a path it cannot widen, against data it cannot touch directly. That is the governed access pattern.


