The Governance Stack That Absorbs Every Agent Query Before Supabase Sees It
Agents should query governed analytical copies, never production Postgres.

To let AI agents query Supabase data without direct database access, put a governance stack between the agents and the pre-calculated analytical datasets they reach through a single MCP endpoint. The stack must enforce identity and permissions, provide shared metric definitions, and record every tool call before execution. Production Supabase supplies the governed data, and agent queries resolve against the analytical copy.
Why agent queries reaching Supabase production is an architectural mistake, not just a risk
An agent receives a reasonable question about revenue and answers it by querying a production table. Yet the agent has just turned an analytical question into production database work, with access bounded by the connection’s privileges. That is the structural flaw in direct access. A more careful prompt does not change where the query executes or what its credentials permit.
For Supabase, this arrangement creates two compounding risks, namely connection-pool exhaustion and row-level security bypass potential. An over-privileged connection can undermine the protection expected from RLS, while permitted queries can still consume scarce connections. Read access is not operationally harmless access. If the production database is already strained, agent-generated work compounds its latency problems rather than creating a separate workload that can be governed independently.
Uchi Uchibeke’s March 2026 paper, Before the Tool Call: Deterministic Pre-Action Authorization for Autonomous AI Agents, describes the underlying problem as pre-action authorization. Model alignment shapes behavior, and retrospective evaluation looks at what happened, but neither enforces a declared policy before a call runs. The remedy therefore belongs in the execution path. It is a governance stack that absorbs every agent query before production Postgres sees it.
What the authorization gap looks like at the tool call boundary
The authorization gap sits where a structured tool call leaves the agent and reaches a data system. At that boundary, authorization may depend on the model’s judgment or ad hoc application validation. The distinction is precise and consequential for database access. RLS can constrain rows under the database connection’s permissions, but it does not by itself supply the full pre-action authorization and audit contract for an agent’s tool call.
The OAP paper presents Open Agent Passport as a specification and reference implementation that intercepts calls synchronously before execution. Its approach requires three conditions to hold together. The agent’s identity must be verified, the requested action must be evaluated against declared policy, and a tamper-proof record must be produced. The infrastructure must do this work without depending on how the model behaves.
Model alignment is probabilistic and operates through training, so it cannot guarantee the acceptability of an individual query. Post-hoc evaluation comes too late for prevention. By the time it examines a call, a connection slot has been consumed and a sensitive field may already have been read. Pre-action authorization makes the decision before the call runs and creates a cryptographically signed audit record.
Why MCP standardizing agent connectivity does not solve governance — it raises the stakes for it
MCP gives agents a common protocol through which to connect to data sources. It does not, by itself, enforce which agent may query which data under which constraints. Connectivity and authorization remain separate architectural responsibilities. The specification’s move to the Agentic AI Foundation under the Linux Foundation provides vendor-neutral governance for the protocol, while governance inside each implementation remains a separate responsibility.
That distinction also applies to scalable MCP deployments. Servers can be stateless at the protocol layer, with identity and capabilities supplied in a _meta parameter on each request. A load balancer can rate-limit traffic without parsing JSON, but a limit on how many requests pass through does not decide whether a given request is permitted. Routing is not authorization, and neither is throttling.
Consequently, expanding MCP access to production Postgres can expand connection demand and attack surface without adding safeguards. The access layer needs read-only enforcement, role-based or attribute-based access controls, and audit trails from the start. Those controls belong inside the governed interface. MCP is the means of reaching that interface, while the governance stack determines what requests can pass through it and where they can execute.
How can AI agents query Supabase data without direct database access?

The architecture has three enforcement rings, which are identity and routing, semantic abstraction, and tamper-proof audit. The outer ring controls entry and destination. The middle ring defines the data and business meaning available to the agent, while the inner ring records the authorization decision and interaction. Each can fail independently, so success in one does not compensate for a missing control in another.
At the outer ring, a centralized API gateway actively enforces permissions, logs access, and routes analytical requests exclusively to isolated read-replicas or analytical copies. The production primary is not an agent destination. CData’s governed MCP pattern illustrates a single access-controlled interface with OAuth/SAML identity passthrough and user-level enforcement at the connection. This interface does not depend on which agent framework or model provider is used.
Inside that boundary, semantic abstraction replaces raw live-table access with business-friendly data. Agents need table definitions, ownership, and freshness before reasoning about a result. Ambiguous column names are not adequate business context. When revenue is a declared, pre-calculated field, the agent does not have to choose a nearby column name and construct its own interpretation.
The audit ring uses infrastructure to record what happens, without relying on the agent to report what it did. The OAP reference implementation creates a cryptographically signed record for each tool call and reports a measured median authorization time of 53 ms. That measurement supports synchronous enforcement within the scope of the evaluated implementation. The same record can support security constraints, quality gates, operational contracts, and compliance controls.
Why pre-calculated datasets are the right unit of data to put behind the governance layer
Authorization alone does not make a dataset suitable for agents. Even a permitted query against live tables can yield metrics that disagree or use up production capacity. The data surface needs its own design. Pre-modeled, pre-calculated datasets separate business interpretation from the moment an agent asks a question, so the access layer governs declared results rather than arbitrary calculations against operational records.
Governed Parquet files queried through DuckDB provide that separation without production connection-pool pressure. The calculation happens ahead of the agent request, and the agent reads its result from the analytical copy. A query is an interpretation of underlying data. A pre-calculated metric is a declaration that all consumers can use consistently, provided they read the same governed dataset.
That declaration requires a strict data dictionary with one defined source for each metric. ARR comes from the billing system, churn follows a declared cohort definition, and active users derive from a named event. Definitions must precede the calculations they govern. If each agent chooses its own runtime aggregation for churn, agents can get different answers even when every query is technically valid and fully authorized.
The semantic layer fixes what a metric means, while identity and policy determine who may read it. Neither control performs the other’s job. Together, they provide a narrower, more trustworthy query surface than permission to invent SQL against live production tables.
What Supabase observability must cover before any agent layer is added
Production isolation needs an observable baseline to be demonstrable. Without query latency, connection counts, and RLS performance signals, a team cannot distinguish existing database strain from agent-driven anomalies. The minimum foundation has three tiers. Query-level visibility shows which statements are slow, why they are slow, and how often they run. Connection-level visibility shows active work and waiting clients, while system-level visibility covers CPU, memory, IO, disk, and replication lag.
RLS performance provides a concrete Supabase example. Postgres may evaluate auth.uid() as volatile and run it for every row, while wrapping it as a scalar subquery lets the planner evaluate it once. Without query-level visibility, the team may miss that cost until a table scan times out. Security policy and query behavior intersect here. Adding agent traffic to an already-strained database makes that interaction harder to ignore.
For teams preparing the database, the practical requirement is to measure active connections against max_connections, cache hit ratios, WAL volume, replication lag, and statement-level statistics from pg_stat_statements. Dashboards for slow queries and monitoring of connection headroom show where production is nearing its limits. Replication lag also exposes the condition of an analytical destination.
Expensive reporting workloads, including agent-generated reporting, should move to replicas, materialized views, or pre-calculated analytical datasets before connection pressure becomes an incident. The destination must preserve the intended separation from production. Once these signals are in place, the team can instrument the governance layer to detect requests that would otherwise have reached production and confirm that interception is working.
How the governance stack becomes the single source of truth for both humans and agents
Metric drift starts when those who use the same raw data read it in different ways. One engineer writes SUM(revenue) and another writes SUM(amount_captured), so Q2 revenue depends on which query ran. A directly connected agent adds another interpretation. More access does not resolve a disagreement about definitions.
When sales, finance, and product each keep their own version of ARR, the executive team must sort out the numbers before it can make decisions. An agent that writes its own ARR query adds to that dispute. A governed field changes the source of authority. ARR becomes one pre-calculated value from one declared source that every human and agent with permission can read.
For an early-stage team without a dedicated data function, this layer also performs work that would otherwise require a data engineer. It declares definitions, enforces their use at query time, and distributes results to inboxes, Slack, and dashboards. The team does not have to depend on someone remembering to open a report before a useful number becomes visible.
The choice of metrics must still follow the company’s stage. Before product-market fit, optimizing LTV, payback period, and burn multiple can encourage scaling something that does not yet work. The governed layer should surface the five metrics that are actionable now. In the agent workflow, this means retrieving pre-calculated revenue rather than inventing its calculation, and reporting the same number the CEO sees in Slack.
What teams building on Supabase should implement in what order

For implementation, the sequence is instrument first, model second, and expose third. Each stage needs results from the one before it. The first step is to install pg_stat_statements, establish connection monitoring, and build p50/p95 latency dashboards. That baseline lets the team assess production pressure and later confirm whether the governed access path is keeping agent requests away from the primary.
The second step is to declare the five KPIs the business actually runs on, including their definitions and sources in the Postgres schema. This is the data dictionary the semantic layer will enforce. Modeling begins only after those definitions are explicit. Otherwise, pre-calculation simply preserves competing interpretations in a different storage format.
The third step is to calculate those metrics and store them in governed datasets as Parquet files or materialized views, while keeping the analytical copy that agents query separate from production. Parquet datasets can then be queried cheaply through DuckDB. The fourth step is to expose that copy through one MCP endpoint that enforces identity, routes agents away from production, and logs every query. The endpoint is the interception boundary.
The fifth step is scheduled delivery to Slack, email, and dashboards, so humans use the same governed results as agents. Teams without an internal data function can use a managed layer for the modeling, governance, exposure, and delivery stages. That path provides senior data modeling without a six-figure hire. The selection criteria remain the same regardless of who builds it, including permission enforcement, isolated query execution, declared metrics, and infrastructure-generated audit records.
The architectural decision is whether agent requests terminate in a governed analytical layer or become work for production Postgres. That decision separates a controlled data interface from an agent with standing database privileges. The governance stack is not optional infrastructure. The agent layer becomes an asset with the governance stack and a liability without it.


