A Postgres-Native Isolation Stack for AI Agents Querying Business Metrics on Supabase
Database policies, modeled metrics, and Parquet keep agents off live data.

Governed data access for AI agents on Supabase via MCP requires three layers, which are database-enforced row policies, pre-modeled business metrics, and an MCP server exposing read-only datasets. Exporting those datasets to Parquet and querying them through DuckDB removes live Postgres from the agent’s query path. This stack separates access control, metric accuracy, and workload isolation instead of expecting one interface to provide all three.
Why AI agents querying production Postgres directly is now a production problem, not a theoretical one
Cloud Security Alliance and Token Security research found that most organizations had already experienced at least one cybersecurity incident caused by an AI agent. Data exposure was the most common outcome. These findings concern agent deployments broadly, rather than Supabase alone, but they expose the weakness of giving an agent unrestricted access to business data. An agent can disclose sensitive information while doing exactly what its credentials permit. The failure is an authorization boundary that never existed.
Direct, ungoverned database access makes that failure consequential because readable data becomes available regardless of the purpose of the request. Permission is not the same as purpose. Most organizations cannot limit what an agent uses data for or stop it once it misbehaves, so they have no way to contain it. For a production Postgres system, the immediate question is therefore not whether the agent can generate valid SQL. It is whether the system can prevent a valid query from retrieving data the task should never expose.
Why the access-control problem lives at the data layer, not the application layer
Uchi Uchibeke’s Before the Tool Call: Deterministic Pre-Action Authorization for Autonomous AI Agents describes the gap between what agents can do and what they should do as an authorization problem. Model alignment changes how a model behaves across a range of responses. It does not guarantee an individual decision. The paper’s live adversarial testbed found that social engineering succeeded under a permissive policy, while a restrictive declarative policy held at a zero success rate across comparable attempts.
Application validation and broad role assignments cannot substitute for that per-action boundary. A role may authorize access without constraining the purpose, rows, or operation appropriate to a particular request. Product-level permissions that stay the same also struggle when access needs change with the context, while asking users to approve every decision leads them to grant too much access.
For Supabase data, the durable boundary is where queries execute. A database policy evaluates access whether the request arrives through REST, an Edge Function, an MCP tool call, or a direct connection, subject to the credentials and bypass privileges involved. Application checks can complement that boundary but cannot replace it with instructions to the model. The enforcement must live in the database itself.
What Supabase's Row Level Security actually enforces and where it fails without deliberate setup
Supabase’s Row Level Security moves row authorization into PostgreSQL. Once RLS is enabled, access is denied until an explicit policy grants it. That guarantee requires deliberate setup and appropriate credentials. RLS is not the Postgres default, and AI-generated CREATE TABLE statements have historically omitted both enablement and policies. Adding a table can therefore expose more data without adding rules for who can access it.
The first failure is confusing USING with WITH CHECK. USING governs which existing rows an operation can access, while WITH CHECK governs the permitted state of written rows. Visibility alone is not a complete write policy. An agent’s ability to read a row should not be treated as sufficient specification of the changes it may make.
The second failure is assuming a policy’s related tables are already protected. Policies that depend on joins require deliberate access rules for the referenced tables as well, across query paths. The third failure bypasses the whole arrangement. The service_role key bypasses RLS, so placing it in an agent’s environment defeats the intended row-level boundary.
Indexed policies add minimal overhead, while unindexed subquery policies on large tables can add hundreds of milliseconds. Agents compound that delay through repeated, sequential metric queries. Writing (select auth.uid()) rather than bare auth.uid() lets Postgres cache the result once per statement.
What MCP server should connect AI agents to governed Supabase data?
The appropriate MCP server exposes pre-approved datasets and fields, enforces access policy before execution, and records each interaction. Its resource should be a governed metric surface. MCP is the right interface for that separation. It distinguishes the AI client, the connector logic in the server, and the resource being accessed, allowing the server to constrain what the agent can request.
But the protocol does not clean data, define metrics, or set up row policies on its own. Trend Micro’s research found hundreds of MCP servers running without client authentication or traffic encryption. Authentication, scoped access, and auditability must therefore be criteria for the server.
Execution timing adds another requirement. Mohammadreza Rashidi’s execution-security systematization treats MCP threats and time-of-check-to-time-of-use races as related validate-then-act problems. A permission check can fail to cover the action if the conditions it checked change before the action runs. The server consequently needs pre-action enforcement over an already governed resource, with database policy protecting live data regardless of the access path.
How pre-modeled datasets prevent metric drift and why agents querying raw tables produce unreliable numbers
Pre-modeling exists to prevent metric drift and simplify SQL generation. An agent querying raw tables must infer business meaning from the available schema. Two agents can make different, plausible choices. One may use SUM(revenue) to work out Q2 revenue, while another uses SUM(amount_captured). Without a canonical definition, valid SQL can produce incompatible answers to the same business question.
That divergence may remain hidden until an investor, audit, or board pack forces comparison. By then, dashboards and agent outputs can disagree. The practical discipline is a written definition for each KPI, with one formula, one source, and one owner. For early-stage B2B SaaS teams, ARR, monthly churn, CAC, LTV, and gross margin deserve this treatment first because they inform board-level decisions and each permits multiple plausible calculation paths.
For a Supabase-native team, SQL views or materialized views provide a place to encode those definitions. Access to them must follow the underlying row policies, because a modeled object is not safe just because it has been modeled. Security and semantics are separate requirements. Materialized views also pre-calculate expensive aggregations and provide a stable schema when underlying tables are refactored. This gives human analysts and agents a common calculation without requiring each consumer to reconstruct the metric from transactional data.
The read-only query surface: Parquet, DuckDB, and keeping agents off live tables entirely
RLS limits which production rows a credential can access, but it does not remove production from the query path. A read-only copy provides that additional boundary. Governed metrics can be exported as Parquet datasets and queried through DuckDB without a running database server. The agent then receives analytical context without a connection to production Postgres. Its queries cannot become slow analytical requests against live transactional tables.
DuckDB’s columnar query engine fits aggregations, filters across metric dimensions, and time-series summaries. Those are the workloads business-metric agents repeatedly generate. Production data still has to be modeled and exported, but individual agent queries no longer add load to live tables.
An agent cannot retrieve a metric that has not been modeled and included in the governed dataset. Definitions must exist before access is granted. This moves disputes about calculation into the modeling process rather than leaving them to query-time interpretation. Because access goes through the governed surface, activity can be recorded where data is exported and queried without adding instrumentation to production Postgres for each agent request.
Assembling the full isolation stack: how RLS, the MCP server, and the governed data layer connect

The stack begins with deny-by-default RLS on live Postgres and explicit grants for the roles that need access. The agent never receives the service_role key. Above that boundary, modeled datasets define the approved metrics, while Parquet exports provide the physically separate read surface. The MCP server exposes only approved metrics and fields from that surface.
The query path starts when an agent submits a metric request to the MCP server. Before execution, the server evaluates the request against its declared access policy. An authorized request goes to the governed dataset, where DuckDB queries the exported data. The server returns the result and records the interaction with enough metadata to reconstruct what was accessed and why. The pre-action authorization paper shows how to strengthen this record with cryptographically signed audit records.
This path should start read-only, with any later write actions introduced behind explicit change approvals. The layers can be deployed independently. A team can establish RLS before modeling metrics, then add the MCP interface when agents enter the workflow. That sequence preserves earlier work, although complete physical isolation arrives only when agent requests use the separate query surface outside live Postgres.
What observability the stack needs to stay safe as agent query volume grows
An isolation stack can lose its guarantees as policies and schemas change and agents gain more capabilities. Deployment is not the end of governance. Supabase provides basic database metrics, including active connections, query count, and storage usage, while query-level visibility, slow-query identification, and real-time alerts require additional instrumentation. In this architecture, that visibility must cover the governed query surface as well as production Postgres.
The key signals are access paths, credential scope, dataset freshness, and query load. Tool-call records should distinguish requests reaching the governed layer from those triggering fallback paths. Credential monitoring should show when credentials have gained access beyond their original scope. Refresh monitoring must show whether materialized views are up to date, because changes to upstream columns, tables, or calculations can leave a metric surface looking stable even when its data is stale or wrong.
Per-call MCP logs provide the foundation, but a clear record of which agent accessed what data and when must be stored so it cannot be altered afterward. Supabase reports that 12 companies grew from zero to more than a million users on the platform in under a year. Growth of that kind makes connection exhaustion and analytical load operational risks as well as security concerns. Monitoring the governed surface helps expose those pressures before fallback access turns them into production problems.
How early-stage Supabase teams can run this stack without a dedicated data engineer
Seed-stage teams often already have the necessary data in Postgres, Stripe, and a CRM. Modeling metrics, auditing RLS, maintaining views, governing an MCP server, and preserving compliance logs all compete with product engineering. Treating these tasks as incidental work is how temporary agent credentials and ad-hoc queries become the lasting architecture.
For a team in that position, the starting point is explicit. Turn on RLS for every table from day one and set up deny-by-default policies before giving an agent a credential. Keep the service_role key within server-side infrastructure and outside the agent’s credential context. Before giving access to business metrics, write down each KPI’s formula, source, and owner. These steps establish the access and semantic boundaries before automation multiplies requests.
A partner with the right skills can take responsibility for the governed data layer when its upkeep is more than the team can handle. That responsibility should include compliance logging, view maintenance, RLS policy auditing, and MCP server governance alongside delivery of an initial connector. The operational work grows with agent usage. Offloading it can preserve engineering time for the product while keeping the architecture coherent.
Sources
- AI Agent Security Incidents Hit 65% of Firms in 2026
- The Balkanization of Execution-Security Research for AI Coding Agents: Isolation, Access Control, and Time-of-Check-to-Time-of-Use Vulnerabilities
- Before the Tool Call: Deterministic Pre-Action Authorization for Autonomous AI Agents
- How Agents Ask for Permission: User Permissions for AI Agents, from Interfaces to Enforcement


