Routing Agent Queries Through a Governed Metrics Tier Before They Reach Supabase
Agents should query pre-modeled metrics through MCP, not raw Postgres.

AI agents should query Supabase through an MCP server that exposes a pre-modeled, governed metrics tier. That tier must serve pre-calculated datasets, enforce the requesting user’s permissions before each action, and record the authorization decision. This architectural boundary makes agent access safe and business metrics repeatable.
Why direct agent access to production Postgres is an authorization problem, not just a performance one
Security guidance uses the framing of an “over-eager intern with administrator credentials” to make the risk concrete. The intern might work too quickly, and enthusiasm combined with broad permissions is dangerous when each action can reach production data. An agent with a database credential can execute whatever that credential permits, while the connection string itself supplies no per-action policy or record of whose authority justified the request.
Uchi Uchibeke’s Open Agent Passport (OAP) research identifies this as a pre-action authorization problem. The decision to execute a tool call rests either with the model or with ad hoc application-layer validation, neither of which constitutes the security-grade authorization layer the paper describes. Model alignment shapes how a model behaves across a range of requests. It does not guarantee that an individual call is authorized. The paper also reports that 492 MCP servers were exposed in production without authentication or encryption, which shows that even basic access controls may be missing.
For Supabase teams, this authorization gap also creates operational exposure. Direct connections are bounded by compute tier, so agents issuing many queries can put pressure on the same pool that supports production workloads. A faster query or a different way to connect may ease that pressure without changing what the agent is allowed to retrieve. The architectural boundary must determine which action is permitted, for which identity, before production data becomes reachable through that action.
Why model alignment and post-hoc logging cannot substitute for a pre-action enforcement layer
A model’s judgment cannot serve as its own permission system. Alignment is probabilistic and established through training, whereas authorization must evaluate a specific action against a specific policy at execution time. A model may usually respect an instruction to avoid sensitive data and still make an unauthorized request. The enforcement layer must still work when that judgment fails. Otherwise, the supposed boundary is another instruction the model can misinterpret or be persuaded to ignore.
Uchibeke’s research tested this distinction in an adversarial setting. When the policy was permissive, social engineering worked against the model in roughly three-quarters of adversarial sessions. With a restrictive pre-action policy in place, attackers had a zero success rate across hundreds of attempts. Those results establish security outcomes within the test’s scope.
By the time a query appears in an audit log, it has already executed and may have returned fields the agent was never meant to see. A generic query log also does not establish which user the agent represented or which policy authorized access. Identity and scope must be established before exposing a working credential. That same pre-action boundary can enforce quality gates and operational contracts, making it governance infrastructure.
What a governed metrics tier actually is and what it must do at the architectural level
A governed metrics tier is an analytical layer that sits between agent tool calls and the production database, with pre-modeled data and policy enforced. It computes metrics ahead of time and stores the results in datasets that agents can query without touching operational tables. Its interface presents approved business measures rather than raw ingredients from which the agent must assemble an answer. A policy page beside an unrestricted SQL tool does not create this boundary.
The tier requires pre-calculated datasets, identity-aware enforcement, and a verifiable audit record for every request. These components serve different purposes. The datasets fix the calculation, while the policy evaluates access using the identity on whose behalf the agent acts, rather than treating a shared service credential as sufficient authority. The audit record binds the identity, policy, and decision into a cryptographically signed record. The OAP specification provides this authorization record at a measured median of 53 ms per decision, illustrating that pre-action enforcement can be an explicit part of the request path.
The interface must also block any escape route to raw tables. If an agent can choose between an approved metric and an unrestricted query tool, it can bypass the semantic definition even when the preferred workflow is documented. Exposing only pre-modeled datasets removes that choice. Semantic context then explains the approved values. This constrains metric retrieval, although it does not guarantee that every sentence the model writes about a result will be correct.
Postgres materialized views are the native expression of this pattern for Supabase teams. They pre-compute aggregates and serve stored results instead of repeatedly calculating them from operational tables. They are not a substitute for permissions or auditing. Rather, they supply the pre-calculation component around which the governed access boundary is built.
How MCP wires the governed tier into agent workflows without creating a thin proxy
MCP is the transport an agent uses to find and use the governed tier. The protocol alone does not establish authorization. An MCP server exposing free-form SQL against production remains a route to production, even if its interface is convenient and its implementation is stateless. Governance depends on what the server exposes, which identity it evaluates, and whether it enforces policy before an action executes.
MCP’s resources, tools, and prompts have distinct roles in that design. Resources give the agent governed datasets and schema context, so it gets approved metrics without access to raw tables. Tools execute scoped actions against the governed analytical copy. Prompts provide reusable analytical workflow templates that make repeated queries consistent at the workflow level. These roles complement one another, but a workflow template cannot replace enforcement on the tool it invokes.
Atlan’s MCP server demonstrates identity-aware access to governed metadata and context. It checks the requesting identity against defined access policy and returns the assets and metadata that identity is entitled to see, including owner, certification status, and sensitivity classification. Its documented scope is important. That implementation is not established here as a generic end-to-end row- or column-level broker for Supabase data.
A centralized gateway can place identity, policy enforcement, and logging in one layer while routing agent requests to governed services. This reduces the surface area for bypass and simplifies auditing. Each request still needs an authorization decision, even when the gateway retains no session state. Statelessness is a scaling property. The OAP research’s finding that most cataloged agent security incidents are authorization failures reinforces why this boundary belongs outside the model.
Why agents invent metric logic when no semantic layer is provided — and what that costs
Raw database schemas do not say how to calculate business metrics. An agent asked for ARR, active users, or LTV/CAC must construct its own interpretation if the data interface provides tables but no enforced metric definitions. Its SQL can run successfully and still answer the wrong business question, producing metric drift. Sales, finance, and an agent can each derive a different value from the same underlying records because they apply different definitions.
If an agent’s ARR differs from the CEO dashboard or the board deck, the organization must reconcile the calculations before it can use the result confidently. A plausible explanation from the model does not resolve that disagreement. The uncertainty concerns the number itself. Trust in both the agent and the dashboard weakens when neither visibly shares the other’s definition.
A governed data dictionary prevents this divergence only when its definitions are part of the exposed data contract. When documentation is kept separate, the agent can read the text its own way or ignore it as it writes a query. Pre-modeled datasets instead embody the definition in the result the agent can retrieve. Claude and a dashboard can then answer from identical definitions, rather than independently reconstructing the same business concept.
For B2B SaaS teams, the initial scope is tractable. The core set comprises ARR, churn, CAC, LTV, and gross margin, which are precisely the measures that need to reconcile across executive dashboards, board materials, and AI-generated reports. Pre-calculation removes the need for an agent to write SQL that derives those metrics. The underlying definition still needs to be correct. It makes that definition shared and reviewable instead of allowing each consumer to invent another version.
How do Supabase teams let agents query metrics without direct database access?
Supabase teams can use Postgres materialized views to pre-compute metrics, then route agent requests to a governed analytical copy through MCP. This separates repeated analytical reads from operational queries and addresses pressure on the tier-bounded production connection pool. Placement still determines the degree of isolation. Pre-computing an aggregate reduces repeated calculation, while keeping agent reads on the analytical copy prevents those reads from becoming another source of direct production connections. The architecture needs both the approved dataset and the governed route to it.
Supabase’s row-level security must still work along that route. A governed tier is not permission to broaden access simply because the dataset is aggregated or copied. The MCP server must enforce the requesting identity’s access at row and column level. A shared credential that can reach the whole dataset does not provide that user-level boundary. The serving layer must keep the restrictions that apply to each result, even after successful authentication.
For teams selecting an MCP server, the decisive criteria are therefore identity propagation, pre-action policy enforcement, scoped access to pre-modeled datasets, and a verifiable authorization record. A server that only forwards a credential and SQL fails that architectural test. Atlan’s metadata implementation shows how identity-aware policy checks can work, but its scope does not show that it enforces Supabase row-level security. Teams choosing a product must separate the controls it has shown to work from those the full deployment still needs.
Supabase’s OpenTelemetry integration and Postgres metrics API supply observability primitives for the surrounding infrastructure. Connection count, query latency, and checks for slow queries can help show when agent traffic reaches production. These measurements support operations but do not replace the authorization record. A stateless governed access layer can scale horizontally without increasing production connections when its requests remain on the analytical copy, preserving the separation the design was intended to establish.
The governance window is short — why today’s patterns become load-bearing infrastructure
An agent’s first data connection often becomes its permanent access path. A pilot needs data quickly, a broad credential removes the immediate obstacle, and the successful connection reduces the pressure to revisit its scope. Subsequent agents can inherit that shortcut. As their number grows, the credential becomes embedded in query patterns and workflows that are harder to change independently. The low-cost governance window is therefore the initial architecture stage.
In a governed metrics tier, new metrics are added as pre-modeled datasets, while new agents use the same policy and audit boundary. The shared infrastructure grows with the workload. The work of defining each metric and deciding who may see it remains in a common layer.
Retrofitting the boundary after months of production queries requires more than replacing a connection string. Teams must audit the query patterns already in use, narrow the scope of credentials that may have reached fields they should not have, and rebuild trust in numbers produced without shared definitions. Each additional agent increases the scope of that reconstruction. For founders and early-stage teams, a managed or partner-delivered governed layer offers a way to establish production-ready infrastructure without the ramp-up time of a dedicated data hire. The durable decision is to make governed metrics the access path from the outset, before raw production access becomes a dependency.


