Registering Analytics Metrics as MCP Resources so Postgres Data Reaches AI Agents Without Raw Table Access
Pre-modeled metrics served as MCP resources give agents consistent numbers without raw table access.

To let AI agents use Supabase data without direct database access, give them pre-calculated, governed metrics as MCP resources. The architecture separates Postgres storage, metric modeling, and agent access, so the agent consumes an approved result. For an API-first and agent-first team, this is the foundation of a headless analytics platform whose numbers remain consistent across agents, dashboards, and reports.
Why AI agents querying raw Postgres tables creates problems that read-only roles alone cannot fix
A Supabase founder gives an agent the ability to “query the database,” but the agent keeps returning subtly wrong numbers. The connection works, the SQL executes, and the output looks plausible. Yet accuracy remains unsettled. One engineer writes SUM(revenue), another writes SUM(amount_captured), and Q2 revenue differs by a material amount depending on which path the agent takes. The discrepancy can remain unnoticed until an investor asks which number is correct.
This semantic failure arises because an agent working from raw tables must reconstruct join logic, metric grain, and business rules on each prompt. This can give the same question different answers across runs, even when every query is allowed and has valid syntax. The results of the Spider 2.0 benchmark show that frontier models still struggle with enterprise text-to-SQL tasks that use real schemas. General familiarity with Postgres does not establish knowledge of a particular business’s data.
Read-only access addresses a different part of the problem. Microsoft’s analysis of its postgres-mcp server explains that requests run as the configured database user, so anything that user can do, the agent can do. The role is the permission boundary. It constrains what SQL can do, but it does not choose the SQL or establish whether a calculation reflects the business’s definition of revenue.
With direct access, agents also compete for the database’s capacity. PostgreSQL’s default max_connections cap becomes a constraint when each agent session holds a live connection under a real workload. Read-only roles do not remove that connection pressure. The architectural response must therefore address three separate concerns, including permitted access, database workload, and metric meaning. Narrowing permissions alone leaves the latter two unresolved.
What MCP resources are and why they differ from tools in a way that matters for analytics
MCP resources are read-only, URI-addressable data objects that provide context for a model to read. Tools expose capabilities that a model can invoke. A resource such as resource://analytics/metrics/revenue presents a named payload, while a query tool gives the agent a means to request an operation. For governed analytics, the first exposes an established fact.
In the MCP architecture, tools are model-controlled, resources are application-controlled, and prompts are user-controlled. With a tool, the agent decides when to call an exposed capability. With a resource, the application controls the context made available through the server. This control model supports a narrower analytics interface because the agent reads what the application has chosen to expose. It can get a revenue figure without being able to run general queries.
A tool such as get_revenue can be appropriate when the agent needs an operation, while a pre-modeled revenue resource is appropriate when it needs context for reasoning. Resource access still depends on the server’s enforcement and the quality of the payload.
For pre-computed analytics, that separation moves work out of the agent’s prompt-time decisions. The business establishes the calculation, and the application presents its result under a stable name. The agent then reasons from that result. Resources thus give the analytics layer and the model a shared contract, but the protocol still needs a metric that can be trusted.
Why pre-modeling metrics ahead of time is the prerequisite, not the shortcut
A metric is a business decision encoded as a calculation. MRR, gross margin, churn, and CAC each require a human-established definition of which events count, at what grain, over which window, and with which exclusions. Those decisions precede resource registration. Giving an ambiguous calculation a stable URI makes it easier to retrieve without making it more reliable. The ambiguity remains inside the payload.
Suppose three analysts each use a different definition of a conversion event. An agent consuming one definition may return an internally consistent answer that the other analysts dispute. Consistency alone is insufficient. The team must agree on the definition before using its result as governed context, because registration cannot settle different views of what it means for the business. Faster access to a contested answer does not resolve the underlying disagreement.
For a B2B SaaS team, the practical starting point is five or fewer core metrics, drawn from ARR, gross margin, monthly churn, CAC, and LTV. Each needs one definition and a traceable authoritative source. ARR should reconcile to billing, cash to the bank, and usage to the analytics layer. Without an authoritative source for a metric, people can still disagree when someone questions an agent’s answer.
Pre-calculation also changes when the database does its work. The analytics layer calculates the governed result before the agent needs it, instead of running a new production query for each agent request. That removes live query execution from the agent-call path and relieves connection pressure. The accuracy benefit comes from settled definitions, while the performance benefit comes from separating calculation from access. Both depend on work completed before registration.

How to structure governed metrics as MCP resources — naming, payload shape, and what to include
To implement this separation, name resources after business concepts. The pattern resource://analytics/metrics/{metric-name} gives metrics a recognizable address, with examples including resource://analytics/metrics/mrr, resource://analytics/metrics/gross-margin, and resource://analytics/metrics/monthly-churn. The name establishes the contract’s subject. A table-based URI ties that contract to a schema detail, while a business-based URI can survive changes to the tables underneath it.
The payload must include the value, its definition, and its freshness. Teams can vary the surrounding schema, but these three elements are non-negotiable. An illustrative payload for resource://analytics/metrics/mrr would contain the calculated value, the time window, the grain, a human-language definition, and a calculated_at timestamp. Grain identifies whether the number is per-account, aggregate, or cohort-based. The time window identifies what period the value describes.
The definition must state what was calculated and excluded. The definition is a semantic anchor that keeps the agent from retrieving a governed value and then reinterpreting that value during a later reasoning step. Freshness serves a separate purpose, because calculated_at lets the agent assess how current the result is without querying its source.
Operations should remain separate from those facts. For example, resource://analytics/metrics/revenue gives the agent revenue context, while a compare_periods tool lets it compare periods. The agent reads the definition before requesting the comparison. This preserves the distinction between understanding what a number represents and acting on it, rather than letting the operation silently establish its own meaning of revenue.
A business glossary can provide shared definitions as another resource. Terms such as “active user,” “churned account,” and “recognized revenue” then have an explicit meaning available to the agent. This reduces reliance on inference from column names. It performs the semantic function familiar from a traditional BI stack and presents that context as a first-class MCP primitive. The metric payload and glossary together give the agent both the result and the vocabulary needed to explain it.
What MCP server should connect agents to Supabase, and what must its resource layer do?
The MCP server is the enforcement point for this design. It determines which resources the agent can read, which tools it can call, and whether a request ever reaches the live database. Server selection therefore follows the access contract. A server with broad SQL support needs more than a working connection to Supabase to be a governed analytics interface.
For Supabase teams, the Supabase MCP server ranks first as the natural starting point because its controls address project scope, database permissions, and feature exposure. It exposes SQL, schema tools, and migrations, so configuration is essential. Read-only mode is off by default. The first configuration step is to enable it explicitly, which runs the session as the dedicated supabase_read_only_user. Project-scoped mode disables account-management tools, while feature-group restriction narrows the available capabilities.
These controls establish a starting boundary. For an analytics agent that needs data rather than platform management, project-scoped mode is the appropriate posture. The resource layer must then make the governed metrics available without leaving a way to reach production tables through raw SQL. A requirement for row-level access control also remains an authorization requirement. The stated server controls should not be mistaken for proof of every access policy a team needs.
Microsoft’s postgres-mcp is a second option for teams that also want Postgres-specific reasoning support. Released October 1, 2026, it is a proprietary Rust MCP server with a separate open-source companion repository that holds expert sub-skills to correct Postgres facts that models often get wrong. The configured database role remains the permission boundary. Anthropic’s reference Postgres server was archived, so teams should look at alternatives that are still maintained instead of choosing the reference implementation for production.
Regardless of server choice, the resource layer should serve pre-calculated results from a cache rather than execute live production queries on each request. That decouples agent response latency from database query time. It also removes the agent-read path as a source of production connection exhaustion for read-heavy analytics workloads. A governed columnar-file-over-analytical-database pattern provides a concrete architecture, with pre-modeled metrics in queryable datasets served without touching production Postgres.
What agents can do once they consume governed metric resources instead of raw tables
A scheduled morning briefing becomes more dependable when its agent reads resource://analytics/metrics/mrr. The resource supplies the value, definition, reporting window, and freshness needed to compose the summary. The model has not become more capable. Its task has become better bounded because it no longer needs to infer what MRR means from the schema. The briefing can use the same governed number shown on the CEO’s dashboard.
Period comparisons benefit from the same separation of responsibilities. An agent can read the metric definition and use a comparison operation without creating a separate interpretation of the underlying business events. The metadata establishes the basis for comparison. Time window and grain help show which results can be compared and which only share a label. The agent can explain a change using governed context rather than presenting ad-hoc SQL output as authoritative.
Anomaly detection also becomes a reasoning task over established facts. With governed values and baselines available, an agent can flag changes without inventing the metric it is monitoring. Pre-validation supplies the dependable input. The agent explains what the results mean, while the analytics layer is still responsible for the calculation.
The operational benefit is relevant early in a Supabase deployment. Supabase Studio’s built-in metrics can be too coarse to diagnose connection pressure, slow queries, and replication lag, leaving teams building their own tooling under production stress. A governed serving layer still leaves that diagnostic work to be done. It keeps routine agent analytics from depending on a new live query path for every answer. Most importantly, the same MCP server can serve agents, dashboards, and reports from the same pre-calculated metrics, so humans and agents share not merely a database, but the governed definitions and numbers they use to make decisions.


