Credential Isolation and Query Mediation When AI Agents Need Supabase Data
Govern agent access to Supabase before connecting, isolating credentials and mediating every query.

AI agents should access Supabase data through a governed MCP server or scoped API. Credential isolation and query mediation must be configured before the first connection, with a named agent identity, task-scoped access, and deterministic checks on every request. The safe architecture exposes modeled metrics while keeping production credentials and authorization decisions outside the agent’s control.
Why the sequencing of credential setup relative to agent connection is the actual security decision
A developer provisions a working credential, connects the agent, and leaves permission cleanup for later. The agent starts running before that cleanup happens. From that point, it inherits the full access surface of the credential it received. The initial grant is already an operational security decision.
Speed makes that decision difficult to reverse safely. An agent can issue thousands of queries in the time a human analyst writes one, so a gap in policy can be triggered far faster than a human-scale error. Malicious intent is not required. An ordinary task pursued through an over-permissioned tool can reach data the task never justified, before anyone revisits the credential.
The order of operations therefore creates the problem despite sufficient security features. A team that connects first has delegated authority before defining its limits. Credential scoping and query controls must set those limits before the agent has any way to reach the data.
What credential isolation actually requires before any agent connection exists
Credential isolation gives the agent its own named workload identity with independently scoped, independently revocable access. That identity is a configured principal for the workload. It must remain distinct from the initiating human. The access record also needs to identify who or what started the run, whether an employee, application, or scheduled job, so policy can evaluate the authority delegated to the agent.
Scope then follows the task, environment, and maximum permitted action. An agent given a read-only analytical task needs a grant limited to that task, even if the person who launched it has broader authority. OAuth and short-lived tokens provide the implementation path. Expiration requires a fresh grant, while independent revocation allows the agent’s access to end without disrupting the human credential from which its authority was derived.
A connection grant alone is too coarse. Permission to invoke a query tool must also constrain which tables it can query, whether it can write, and how large a result it can return. Otherwise, the tool’s parameters reopen the access surface that the identity was meant to narrow. A long-lived static key also keeps a standing grant in place and lacks the expiration and request-specific authorization that task-scoped access needs.
Credential isolation also extends to what leaves the retrieval path. A permitted query can return a table containing API keys, just as a file-reading tool can reach a configuration file containing secrets. Retrieval permission does not settle disclosure permission. The governed layer must scan outbound content for credential patterns before what was retrieved reaches the model.
Why Supabase's production database is structurally the wrong target for agent queries
Supabase’s row-level security is built around auth.uid() and per-user policies. That fits the application’s access model. An agent or BI service account scanning across rows has a different requirement, which forces a choice between granting a role that bypasses RLS and writing analytics-shaped policies into production authentication. The former creates a separate security-review obligation, while the latter mixes analytical access with the application’s user model.
Production queries also introduce a resource conflict that credential scoping cannot resolve. Analytical aggregations hold connections longer than transactional queries, creating a risk of connection-pool exhaustion. The pooler limits that protect the application work against the agent’s analytical workload.
Supabase recommends read replicas to address query contention. A replica genuinely resolves that performance conflict, but it runs the same compute as the primary and bills separately, roughly doubling database spend. It does not resolve the meaning of the data. The agent still has to work with an OLTP-shaped schema in place of modeled, pre-calculated metrics, even when its queries no longer compete with the application.
That distinction affects accuracy as well as containment. Against production, a perfectly scoped credential still exposes live, mutable data from which the agent constructs SQL for each question. Two agents can translate the same business question into different queries and produce different answers. Isolating the workload therefore requires more than moving its connection away from the primary database.
How can AI agents query Supabase data without direct database access?
A governed query layer places deterministic policy and retrieval between the agent and Supabase data. The agent submits a request. The layer evaluates that request before content enters the model context, limiting effective access to what both the requester and the agent are permitted to do. Neither identity’s broader permissions should override the other’s narrower scope.
At query time, the layer applies tenant, environment, and data-classification filters. It separates read paths from write paths and minimizes returned fields and records. Model output remains a proposal for an action. Whether that proposal is honored depends on policy enforced outside the model, rather than on the agent remembering restrictions from its prompt.
For MCP integrations, token handling must preserve the same separation. The server validates that an incoming token was issued for that MCP server as its intended resource. It must not pass the client’s MCP access token through to downstream APIs. Downstream calls instead use a separately scoped token, so permission to call the server does not become an unrestricted credential for the systems behind it.
When governed datasets hold agreed metric definitions, two agents asking the same question use the same calculation instead of each building SQL against production tables. Definitions belong in infrastructure. “Active user” and “churn” can then have shared meanings across agents.
The selection criteria for an MCP server follow from those requirements. A suitable server enforces row- and column-level policy on each request, respects both identities, exposes governed metrics, and records access for audit. Connectivity alone is insufficient. MCP gives access to tools, while the governed data layer holds the policy and context that decide what those tools may return.
What MCP's current specification requires and what it still leaves to the implementer
The July 28, 2026 specification revision made MCP stateless at the protocol layer. Protocol version, client identity, and capabilities travel in a _meta field with each request. Each request can then go to any server instance behind a round-robin load balancer. That removes a horizontal scaling barrier while leaving authorization obligations in place.
Remote deployments run stateless over Streamable HTTP. The separate SSE transport is legacy, while SSE remains available within Streamable HTTP for request-scoped streaming. Stdio remains the current local transport. These transport choices determine how requests and responses move, but they do not define which Supabase rows a particular agent may read.
The same revision tightened authorization across six enhancement proposals. These cover issuer validation under RFC 9207, application_type declaration in DCR, credential-issuer binding, refresh token guidance, scope step-up clarification, and .well-known discovery clarification. Implementation still requires protected endpoints. Every endpoint should be wrapped in OAuth or JWT middleware, and each agent context sandboxed to prevent confused-deputy or prompt-injection attacks from escalating through tools.
The remaining access decision is specific to the workload. It asks what this agent, acting for this user on this task, may retrieve. Statelessness cannot answer that question, and a valid token does not supply row-level business policy. The governed layer must make the decision before MCP returns the result.
Rashidi’s 2026 systematization of 39 execution-security papers identifies a further gap. Policy-enforcement studies report high failure rates for real deny-lists, yet no isolation paper re-evaluates its own defense under that adversarial setting. Protocol controls and sandboxing still need correct policy to work. The study also treats TOCTOU, or time-of-check-to-time-of-use, races and MCP threats as separate literatures despite their shared validate-then-act state problem, so implementations need to account for both.
How permission enforcement degrades in practice and what deterministic enforcement requires
A well-written policy is insufficient if the agent must interpret and apply it. The rules have to be enforced outside the reasoning chain. Otherwise, the system asks the same model that generates an action to decide whether its action complies with the boundary intended to constrain it.
Michael and Roesner’s 2026 survey of 21 user-level agent permission systems finds that none fully address minimal user overhead, formalized policy specifications, and deterministic enforcement simultaneously. Commercial agents often make users choose between user-in-the-loop permissions that take a lot of work and LLM auto-reviewers that give users little insight or control. Users overwhelmed by prompts frequently over-grant permissions, making repeated confirmation an unreliable substitute for a defined policy.
Database-layer enforcement removes the need to rely on every path through the application to apply the same filter correctly. Row-level security attaches the rule directly to the table. For a role subject to that policy, a developer cannot accidentally omit the tenant filter, and an ORM change cannot silently remove it. This establishes why governed access for analytics needs an enforced data boundary that preserves Supabase’s production RLS.
GAAP, by Stanley et al., UCLA, 2026, demonstrates deterministic enforcement through Information Flow Control. Its execution environment tracks how an agent accesses and uses private user data across steps within a task and across separate tasks. It blocks data disclosure attacks without having to trust the agent or rely on an attack-free user prompt.
Application filtering may catch many invalid requests, but one gap can let data into the agent’s reasoning chain. The consequences extend beyond the initial response. An agent can act on that data through APIs and cascade across dozens of tool calls before a human notices. Deterministic retrieval and disclosure controls bound that risk at the points where data enters and leaves the agent’s workflow.
The full sequence: how credential isolation and query mediation work together before the first connection
The implementation sequence begins with an inventory of the agent’s intended access. The team identifies every source the agent will touch, the rows, columns, and records it may see, and the authority under which it acts. This precedes credential issuance. Without that inventory, a task-scoped grant has no defined task boundary to encode.
The next step is policy definition against a governed metadata layer. Row- and column-level rules set the scope, and deterministic enforcement applies those rules to every request, including those after the initial connection. Only then does credential issuance begin. The named workload receives a short-lived, task-scoped credential, preferably using OAuth or JWT-backed tokens instead of static API keys, with expiration and re-issuance replacing manual rotation.
Governed exposure follows through an MCP server or scoped API that enforces the policy on every request. It returns modeled, pre-calculated metrics rather than raw OLTP rows and logs access with both the agent identity and the initiating user identity. Audit preserves the delegation relationship. The record must distinguish the workload that retrieved data from the person or system whose authority started the run.
Output scanning completes the path before a response reaches model context. It checks for credential patterns, PII, and sensitive field values, including data the query legitimately retrieved but the agent should not relay. The final test is independent revocation. Ending the agent’s access should require changing only its credential.


