Est.

Why Postgres Role Grants Alone Cannot Scope a Claude or GPT Agent to Business Metrics on Supabase

Grants control who sees rows, but only a semantic layer defines metrics.

· 8 min read
Cover illustration for “Why Postgres Role Grants Alone Cannot Scope a Claude or GPT Agent to Business Metrics on Supabase”
MCP and Headless Analytics · November 21, 2026 · 8 min read · 1,852 words

Governed data access for language model agents on Supabase needs three layers, which are hardened Postgres roles, a trusted MCP enforcement boundary, and a governed semantic layer. Role grants and RLS constrain data access. For analytics without direct access to the production database, agents should read pre-calculated, governed datasets through a read-only MCP or API interface, with metric definitions set before the agent asks its question.

Why Postgres role grants are a data-plane control, not a business-meaning control

Postgres evaluates access through two sequential checks. Table and column GRANTs decide whether a role may perform an operation at all, and row-level security policies then filter which rows that permitted operation can reach. A successful query can therefore be correct from the database’s perspective because it returns exactly the rows the role is entitled to see.

That entitlement says nothing about what those rows mean. Revenue, churn, and active users require a defined formula, a defined grain, and a source of truth. A role can permit access to the inputs without establishing any of those definitions. Closing this category difference requires a mechanism outside the role system, even when that mechanism stores its definitions inside Postgres.

How the Supabase MCP server brings this gap into an agent's live query path

The Supabase MCP server gives an agent a live connection to a project, placing this distinction directly in its query path. The @supabase/mcp-server-supabase package was at version 0.14.0 on 14 October 2026, with its tools in eight groups. Its capabilities include execute_sql, apply_migration, deploy_edge_function, and full schema introspection, with Storage disabled by default. The connection is not merely a metric lookup. It exposes project capabilities whose reach depends on the authorizing identity.

That identity determines what data a tool call can return. Sensitive data, including auth.users, financial records, PII, and secrets, can remain reachable unless access controls exclude them. In the hosted server’s read-only mode, the read-only user can see every table without RLS. Read-only access is therefore not row-scoped access, and neither is equivalent to a governed analytics interface.

Teams often connect agents with the service role key, whose internal identity bypasses RLS when there is no end-user session token. An MCP connection does not itself establish the intended row boundary. Even with the right limits on the identity, the agent gets data it can access without canonical business definitions, so it must infer how to use that data at query time.

What actually goes wrong when an agent computes business metrics from raw tables

An agent with SELECT on the appropriate tables can return a credential-valid answer that is factually wrong. One agent might compute MRR from subscriptions, while another computes it from invoices. Both queries can be permitted and produce different numbers. Neither discrepancy is an access-control error, because the role system has no rule that says which calculation is MRR.

The EDB Postgres AI / Amazon Bedrock AgentCore reference architecture provides a concrete example. Its purchases.price field records the order total. An agent that multiplies that value by quantity returns a figure roughly 18× too high for the top customer. The arithmetic succeeds while the interpretation fails. Tighter limits on which rows the agent can see would still leave the mistaken multiplication in place.

The same uncertainty affects terms that are not column names, including “big spender,” cohort, and active user. Without explicit definitions, the agent infers their meaning on each prompt, with no guarantee of consistency across callers or runs. Cross-source questions add another unresolved dependency. A Postgres role cannot establish a governed join to Stripe, an ad platform, or a CRM merely by granting access to production tables.

Runtime SQL also introduces cost and exposure risks. A vague prompt for analytics can lead to a costly full-table scan or an accidental cross-join, and permissions alone put no limit on how much data comes back. A session can override a timeout supplied only as a default. Indirect prompt injection widens this exposure because a poisoned row value can steer an agent toward a multi-statement tool payload that exploits its existing credentials. These risks compound uncertainty about business meaning, but they are not its cause.

Why hardening the role still does not solve the semantic problem

A carefully hardened role is necessary and correct. The baseline includes a dedicated login with NOSUPERUSER and NOBYPASSRLS, column-level SELECT on needed columns, transaction-local timeouts, and audited SECURITY DEFINER functions. Revoking EXECUTE from PUBLIC on functions that write blocks another way to go beyond the intended read boundary. These controls deserve their place because they constrain what an agent can reach and do.

They do not define what an answer means. A role limited to the required columns still supplies no canonical MRR formula, grain for an active user, or join path to Stripe. It also gives no assurance that two agents that query at different times will use the same definitions.

A proxy can add statement inspection and block destructive commands or a missing WHERE clause, governing query shape while leaving the correctness of a revenue formula unchecked. A read replica also keeps analytical load apart from transactional load and removes write risk, but it gives the agent rows without metric definitions. The agent remains responsible for inferring joins and formulas. Role hardening and semantic governance are complementary layers because they govern different properties.

What out-of-band policy enforcement adds — and where its ceiling is

Out-of-band enforcement moves policy decisions outside the agent’s reasoning loop to a trusted tool boundary. Millstone, Akidau et al.’s August 2026 Redpanda Data paper formalizes this approach to policy enforcement, referring to it as OBPE. The boundary authorizes the typed operation and resource, narrows queries or shapes arguments before backend execution, and filters records and fields in the response. The agent does not enforce its own limits. Its policy can only narrow the data owner’s maximum grant, never widen it.

The OBPE paper reports a substantial reduction in failures across controlled trials against Jira and ServiceNow mocks. Under the OBPE bundle, the trace-failure rate fell from a majority of trials to 0.2%. The benchmark counted a failure when protected data entered agent context, an exact protected value appeared in an answer, or a forbidden backend effect took place. This evidence about access and exposure is limited to those trial conditions.

The remaining failures also delimit what enforcement proves. The paper describes answers that reconstructed protected values and a separate trial that used filtered row counts as an oracle. Shaping an execution is not proof of noninterference. More directly for analytics, a boundary can filter every returned row correctly while leaving the agent to invent an MRR calculation from the visible columns.

What a semantic layer actually does that role grants cannot

A semantic layer defines what a metric means, how it is calculated, and which definition is canonical. It stores those decisions outside the agent’s query-time reasoning. Metric formulas such as ARR, churn, CAC, and active users become machine-readable definitions. Every caller resolves against the same definition, while access controls can still restrict the population or fields that caller may see.

The EDB architecture makes this division concrete. Standard Postgres COMMENT statements hold the business meaning, and foreign keys provide the join graph. A “big spender” view with a COMMENT ON VIEW statement puts that definition in one place. In the earlier price example, defining purchases.price as an order total exposes the mistaken unit-price assumption at definition time, rather than after an inflated answer has been returned.

The architecture also preserves structural access control. Two Postgres roles asking the same question receive different answers because column-level GRANT and RLS are enforced at the semantic layer’s MCP endpoint. The prompt, tool catalog, and agent code stay the same.

Beyond formulas, the layer establishes cross-source coherence and provenance. Stripe, ad platforms, and a CRM can contribute to governed, pre-joined models. Each metric has a documented grain, calculation source, and changelog so that a disputed number can be traced to its definition.

Several tools expose semantic capabilities through MCP. The dbt Semantic Layer uses MetricFlow, and dbt MCP provides nine toolsets. Cube exposes 30 MCP tools and is warehouse-agnostic, while Honeydew also belongs to this category as of 2026. Bruin is a broader data platform with a semantic layer component and an MCP endpoint. Tool counts describe interface breadth.

How can agents query governed Supabase metrics without touching production tables?

Instead of asking an agent to construct a production query at runtime, the system calculates metrics ahead of time and materializes the results. Humans and agents then consume the same governed source. This takes the work of producing answers out of the transactional query path, with no need for a separate data warehouse.

The Supabase Metrics API exposes roughly 200 Postgres performance and health metrics in Prometheus exposition format. Connections, WAL, and I/O describe how the database runs. They do not define ARR, churn, or cohort retention, so infrastructure observability cannot substitute for the business model an analytical agent needs.

Governed Parquet datasets queryable through DuckDB give agents analytical context without a live SQL session against the transactional store. Pre-calculation also separates the workload of producing metrics from the moment someone waits for an answer. The production database is no longer the agent’s analytical execution target. Consequently, database-layer blast-radius and prompt-injection risks associated with that live connection do not apply to this path, although the agent interface still needs governance.

Exposing these datasets through a single MCP server lets dashboards, Slack reports, and agents consume the same certified metrics. That shared source avoids separate definitions drifting between the founder’s dashboard and an agent’s response. Certification requires an explicit ownership decision. Each metric needs one calculation source, one canonical definition, a changelog, and an owner, rather than inheriting its meaning from whichever table an agent chooses.

What Supabase teams should actually put in place, in order

The first layer is a dedicated login role with NOSUPERUSER, NOBYPASSRLS, and column-level SELECT only on required columns. Timeouts belong in SET LOCAL per transaction because role defaults are overridable. SECURITY DEFINER functions need auditing, with EXECUTE revoked from PUBLIC on functions that write. The service role key should never be handed to an agent, while per-project scoping and an app-level MCP server should be used where available.

The second layer is a trusted enforcement boundary. It should check and narrow queries before they run, filter the fields in responses, and hold high-impact operations until a human approves them. Its authority must stay outside the agent’s reasoning loop, and policy for the agent must only narrow the data owner’s grant.

The third layer defines the analytical contract itself. Metrics should be defined once as code, with a canonical formula, documented grain, provenance record, and changelog. Pre-calculated, materialized results can then be exposed through a read-only, token-efficient MCP or API interface.

A founder can make these decisions in sequence. Restricting access is the baseline, mediating tools controls runtime behavior, and governing definitions determines what the business answer means. None substitutes for the others. Teams connecting agents now need this distinction from the first MCP connection, because the semantic gap begins with the first permitted analytical query.

Sources

  1. Build a semantic layer for agentic AI with EDB Postgres AI and Amazon Bedrock AgentCore
  2. If Agents Were Angels, No Governance Would Be Necessary: Out-of-Band Policy Enforcement at a Trusted Tool Boundary

More in MCP and Headless Analytics