Designing an Immutable Metric Surface AI Agents Can Exhaust Without Risking Supabase State
Pre-calculated metrics in a read-only store keep agents off production.

Governed data access for AI agents on Supabase via MCP should expose pre-calculated metrics through a separate, read-only analytical surface. Immutable Parquet datasets, read-only DuckDB queries, and pre-action authorization keep agent exploration outside production state. Access controls set what agents may request, while architectural separation keeps their analytical workload off the database that serves the application.
Why letting agents query Supabase production directly is an authorization problem, not just a performance one
A database credential does not establish permission for every action an agent attempts. The authorization decision belongs before the tool call. Row-level security governs access to rows, but it does not replace a declarative policy governing whether an agent may invoke a tool for a particular operation.
Before the Tool Call: Deterministic Pre-Action Authorization for Autonomous AI Agents, the paper presenting Open Agent Passport, distinguishes this boundary from the safeguards teams commonly rely on. Model alignment is probabilistic and applied during training, while post-hoc evaluation examines actions retrospectively. Neither enforces declarative policy at each tool call or produces a verifiable authorization audit record. The OAP paper also reports that more than a quarter of engineering teams have abandoned framework-provided authorization for custom hardcoded logic.
The exposure is not confined to experimental deployments. The same paper cites enumeration of hundreds of production MCP servers exposed without authentication or encryption. The State of AI Agent Security 2026 found that the number of agents at enterprises roughly doubled between December 2025 and April 2026, with 48% running without enough security coverage. As fleets grow, trusting an agent to follow instructions makes the authorization boundary depend on how the agent behaves.
What Supabase production Postgres was not designed to absorb
Even an agent with permission can overload the wrong database. Supabase production Postgres serves an OLTP workload, which favors high-concurrency, short transactions. Analytical requests do different work, including aggregations, window functions, and full-table scans. When both run on the same instance, they compete for the same connection pool and compute budget. This is a workload mismatch.
Connection pool exhaustion is the most direct failure path. An agent can issue parallel queries and retry when responses slow, adding pressure to the resource that application transactions also need. Analytical load then appears in both the Supabase bill and end-user p95 latency. A query can be valid, permitted, and still expensive enough to degrade transactional traffic. Query hygiene helps, but it does not separate those competing demands.
Row-level security does not remove this resource coupling. Its policies are checked against live production data, so a request still uses the production database even if row access is denied. Misconfiguration can still lead to authorization failures, and prompt-injected requests still need controls at the tool boundary. Adding MCP server instances cannot fix either problem inside Postgres. More protocol capacity can instead produce more parallel connections to the same saturated pool, making separation necessary at the data layer.
How do AI agents query Supabase metrics without direct database access?
An out-of-band analytical store contains pre-modeled, pre-calculated datasets. Agents query that copy. Supabase remains responsible for transactional work, while the analytical layer absorbs exploration. The distinction is physical and operational.
A read-only production connection still reaches live production state and consumes production resources. An immutable analytical surface is a governed copy that cannot be production state by construction. Within the analytical engine, read_only=True rejects write-path SQL, including DROP, UPDATE, and INSERT, before execution and makes the intended access restrictions visible in infrastructure code. The separate store removes analytical lock contention from production and gives DuckDB stable statistics to plan against.
Tenant isolation belongs in the same design. Per-tenant Parquet files sit under isolated prefixes, and each query uses an in-memory DuckDB connection against the appropriate tenant prefix. The request returns its result and discards the connection. No request state persists between queries, and the analytical layer can be replaced or removed without touching production.
The agent remains untrusted throughout this path. Before a query reaches DuckDB, a SQL safety gate blocks write-path statements, enforces LIMIT and sampling, and applies a timeout budget. Agents can explore the published surface repeatedly, but individual requests remain bounded. Exhaustive exploration does not require unrestricted execution.
Why pre-calculated metrics are the right unit, not on-demand queries
Two engineers can query the same production table and produce different revenue figures. Both queries may execute correctly. The discrepancy can remain invisible until an investor asks for audited numbers, because the disagreement lies in the definitions. Moving raw tables into a separate store protects production, but it does not resolve this business problem.
ARR, churn, CAC, and gross margin each receive a governed definition, calculated from one source and published to the analytical surface. An agent then consumes the defined measure instead of inventing an aggregation from raw records. Without that constraint, it can produce a result that is internally consistent yet wrong by the business’s own definition. Faster execution would only deliver that discrepancy sooner.
The foundation is one authoritative source of measures, filters, and dimensions. Different metrics can be valid for different uses, as long as their definitions and the steps used to calculate them are clear. Governance preserves those distinctions rather than allowing each consumer to reconstruct them independently.
The same foundation should serve people and agents. Publishing metrics to dashboards, Slack, and email puts the defined measures where teams already work without requiring someone to request them. When agents consume that governed surface too, their analysis begins from the same definitions the team uses to make decisions.
MCP as the governed access protocol for the analytical surface
MCP supplies the interface to the separate analytical surface. The open standard was originally created by Anthropic and is now governed by the Agentic AI Foundation under the Linux Foundation. Its three primitives fit this analytical design directly. Tools run queries, Resources expose governed datasets and schemas, and Prompts codify repeatable analytical workflows. Together, they make the surface discoverable without requiring agents to infer its structure from production tables.
The July 28, 2026 MCP specification revision made the protocol stateless at the protocol layer. A remote MCP server that previously needed sticky sessions, a shared session store, and deep packet inspection at the gateway can now run behind a plain round-robin load balancer. For a server exposing governed Parquet data through DuckDB, this removes session affinity and shared protocol-context storage from the scaling path. The access layer scales like a REST API. Unlike adding servers in front of production Postgres, this adds capacity to a workload already separated from application transactions.
Protocol statelessness is not a security policy, however. The MCP server remains responsible for pre-action authorization and for keeping requests within the governed surface. Choosing a server should depend on whether it can enforce that boundary as well as connect to Supabase. Immutable datasets, read-only execution, tenant isolation, and pre-action guardrails protect different parts of the request path. Together, they keep production safety from depending on a single access-control setting.
Supabase observability as the prerequisite, not the afterthought
Separation must be observable on the Supabase side. An architecture diagram cannot prove that analytical traffic stays out of production, and a policy for agents cannot show whether another route still reaches it. Production instrumentation supplies that proof. It also makes the consequences of unexpected analytical traffic visible before they become indistinguishable from ordinary application growth.
pg_stat_statements, enabled by default on most managed Postgres deployments, records query mean time, total time, and call count. Those records provide a practical basis for detecting analytical query patterns in production traffic. Supabase’s Metrics API exposes Postgres performance and health metrics in Prometheus exposition format, including the signals needed to watch connection pressure and cache behavior. When active connections rise above 80% of max_connections, they are in the danger zone. A noticeable fall in cache hit ratio can indicate that analytical-style full scans are landing on production.
auto_explain logs the execution plan for queries that exceed a configured threshold. To align diagnosis with application requirements, the threshold should sit at the SLO boundary, so alerts arrive with the plan needed to identify expensive analytical work. These tools answer complementary questions about query patterns, resource pressure, and execution behavior. They make the separation auditable.
The staleness objection and how to answer it honestly
A separate analytical copy is not current by definition. Materialized views require scheduled refreshes, and published snapshots reflect the source at a particular time. Faster refreshes consume more compute, while slower refreshes increase lag. A founder who expects an agent to report the present state therefore has a legitimate objection. Production isolation does not erase that tradeoff.
For startup operating metrics, the relevant cadence is the decision cadence. Daily or hourly Parquet snapshots are almost always sufficient for ARR, churn, CAC, and gross margin because these measures generally do not change meaningfully between refreshes at the pace founders use them. Freshness must be a visible contract, through versioned snapshots or idempotent batches with a clear timestamp. Agents and humans then see the same vintage label, identifying an older calculation as such.
Fresh timestamps and correct definitions are separate properties. Live production queries can fetch newer raw records without making a governed metric more accurate. An agent that reconstructs revenue incorrectly has not improved the answer merely by using recent data. The analytical surface preserves the definition while making its temporal limit explicit.
A second objection concerns the security work at the MCP boundary. The OAP paper reports that synchronous pre-action authorization reduced adversarial success to zero under controlled conditions, while model alignment alone left most attacks successful. Those controlled results support enforcing policy before execution at the MCP server, even when its underlying datasets are immutable.
What this architecture looks like for a Supabase team without a dedicated data function
A small Supabase team can implement this design without operating a separate warehouse or changing the production database schema. The practical stack consists of pre-modeled metrics published to governed Parquet files, DuckDB opened read-only, and a single stateless MCP server. It does not require a dedicated data function. The work centers on defining the metrics, publishing the analytical copy, and governing access to it.
The absence of a separate warehouse does not eliminate publication work. Metrics still need calculation, snapshots need timestamps, and tenant-specific data needs isolated prefixes. The design needs no separate ETL pipeline, but the surface agents use still needs to be prepared with care. Its simplicity comes from the narrow scope. It exposes defined metrics rather than offering agents a general-purpose route into application state.
After the July 2026 protocol revision, that access layer can scale on demand without session-management overhead. A small team can thus keep agent requests separate from transactional work without having to work like a large team. Production observability remains part of the design, because the team still needs to verify that the boundary holds.
The durable benefit extends beyond agent safety. When sales, finance, and product consume the same governed surface and agree on the revenue figure, the executive team can focus its arguments on decisions. Agents join that shared calculation path without gaining a path to production tables. Their freedom to explore rests on the architecture’s exclusion of access to production tables.


