Row-Level Policy Inheritance as the Architectural Reason to Route AI Agents Through an MCP Analytics Server

Routing agents through an MCP server makes the database enforce tenant boundaries.

· 8 min read
Cover illustration for “Row-Level Policy Inheritance as the Architectural Reason to Route AI Agents Through an MCP Analytics Server”
MCP Data Layer · November 17, 2026 · 8 min read · 1,743 words

For governed AI access to Supabase, route agents through an MCP analytics server that holds a restricted Postgres role, inherits row-level security, and limits data exposure to governed metrics. The agent receives tools. Tenant boundaries and business definitions must be enforced without depending on what the agent remembers to do.

Why routing AI agents directly to Postgres is an authorization problem, not just a performance one

Production agents can write dozens of queries in a single session. At that volume, authorization depends on someone keeping tenant filters correct in every generated query. This connection pattern requires each statement to reconstruct a security condition correctly before the database will return an appropriately scoped result.

Application-layer authorization checks tenant context in code before issuing a query, but that check alone gives the database no rule to enforce. If the query omits the expected filter, the database can return rows that the agent was never meant to see. In a multi-tenant Supabase project, one unchecked query can expose PII or business data across organizational boundaries. The query can be valid SQL and still break the application's access model.

Prompt instructions do not close that gap. An instruction to “respect tenant boundaries” tells the agent how to behave, while a database policy determines what it can access. That distinction separates an advisory safeguard from an enforcement boundary. Performance and query cost remain operational concerns, but neither resolves authorization that depends on generated SQL including the right restriction every time.

What Postgres row-level security actually does at the engine level

Postgres row-level security uses a predicate inside the query engine to check rows before returning them. Once enabled on a table, RLS subjects ordinary roles' SELECT, INSERT, UPDATE, and DELETE operations to row security policies. Without a policy, no rows are visible or writable by default.

The filter runs inside the query executor. It therefore applies regardless of which client, agent, or tool issued the query. A generated statement does not need to repeat the policy's tenant filter for the database to enforce it. The boundary exists independently of the query's wording. That is the mechanical guarantee on which an agent-facing access layer can build.

Policies can derive scope from the connection's security context. A common direct Postgres pattern uses current_setting('app.tenant_id'), while Supabase Auth-integrated projects use auth.uid() or auth.jwt(). Role exceptions still define the guarantee's limits. Superusers and roles with BYPASSRLS bypass all RLS checks, and table owners usually bypass them too unless the table uses FORCE ROW LEVEL SECURITY. That setting subjects owners to RLS, but does not remove the superuser or BYPASSRLS exceptions.

How connecting as the wrong role silently nullifies every RLS policy you wrote

A table can have carefully written tenant policies and still expose unscoped data to a privileged connection. Supabase's service_role key bypasses RLS policies and belongs exclusively to administrative use. Using it for an agent does not merely broaden one policy. It removes the row-policy enforcement boundary from that access path.

General Analysis demonstrated this failure in 2025 using a Supabase project modeled on a multi-tenant customer-support SaaS. The project had RLS enabled as documented, but a cursor assistant operated through service_role. User-submitted messages contained crafted instructions that the assistant could interpret as commands, causing it to execute SQL unintentionally. No RLS check intervened. The policies existed, but the role used by the assistant was exempt from them.

The injected content steered what the assistant did, and its elevated role let it access the database without row checks. Stronger instructions would not bring back the missing enforcement boundary. The architectural failure preceded the malicious message.

The anon key presents a useful contrast because it operates within RLS policies and accesses only what those policies permit. That protection works only if RLS is enabled on every table the agent can access. With RLS disabled, anon can access all rows in that table. Neither a key's name nor the presence of policies elsewhere establishes a safe agent connection.

Why an MCP analytics server makes RLS inheritance the default, not a per-query obligation

An MCP analytics server closes this gap by fixing the database role and connection pattern outside the agent's control. In this design, the server holds one dedicated role for agent connections. It is not a table owner, a superuser, or a role with BYPASSRLS. The privileged route exploited in the demonstration is therefore absent from the agent connection pool. MCP supplies the access boundary, while Postgres supplies row enforcement.

The server also establishes tenant context before querying. It sets the session context used by the policies rather than asking the agent to insert tenant restrictions into each statement. With a fail-closed policy, the agent gets no rows when context is missing. The agent must not be able to override that context through its exposed tools. RLS inheritance is the name for this setup, with a fixed role, context set by the server, and scope enforced by the database.

Credential custody makes this different from a well-configured direct connection. A direct connection using an ordinary role can enforce RLS, but it still gives the agent a database access path. Here, the agent receives no database credentials. It calls the server's tools, and only the server connects to Postgres. The guarantee comes from that arrangement.

Amazon's North America Sort Center MCP architecture illustrates the broader centralization principle. Its server centralizes permission enforcement and uses configuration-driven dataset access, eliminating the need for per-dataset integration code. This gateway pattern frees each agent from having to keep access logic up to date as datasets change.

What RLS cannot cover, and how role privilege design fills the remaining gap

RLS determines which rows a role may read or write, but it does not protect schema operations. Its row policies do not cover DROP TABLE, ALTER TABLE, and TRUNCATE. A tenant filter cannot prevent those operations. The role must lack the authority to perform them, even when its row-level access is correctly constrained.

The design response is least privilege at the server's database role. Agent connections should never have authority to drop, alter, or truncate tables, and their DML privileges should be limited to the analytics use case. These restrictions complement RLS. The MCP server is the natural place to keep that restricted role in use for every agent request.

With the intended fail-closed policy, absent context returns no rows. Teams should monitor unexpectedly empty responses as a possible sign that context-setting has broken. Safe failure still needs diagnosis.

Supabase database branching supplies a separate change-management layer. Schema changes can be tested on a branch before production, where testing can expose a misconfigured policy or a missing FORCE ROW LEVEL SECURITY setting. Branching does not replace runtime access controls. Together, row policies, restricted privileges, and branch-based testing address data scope, schema protection, and changes to the controls themselves.

The second reason to route through MCP: governed metrics prevent agents from hallucinating business definitions

An agent can follow every row policy and still get the answer to a business question wrong. Definitions of ARR, churn, or CAC live in calculation logic. When natural language-to-SQL operates on raw tables, the agent must infer that logic from the schema. Different inferences can produce different answers to the same question using entirely authorized rows.

This is metric hallucination at the calculation layer. The agent need not invent a record to produce an unreliable result, because choosing the wrong calculation is enough.

A semantic layer addresses that problem by defining metrics as code once. Human users and agents then consume the same calculation. Improvado's MCP interface illustrates this pattern by exposing governed campaign and attribution data to AI clients.

An MCP analytics server can combine that semantic model with RLS inheritance. Postgres restricts the rows available to the connection, while the exposed metric uses the business's defined calculation. That second guarantee depends on tools that expose pre-modeled, pre-calculated datasets so that arbitrary raw SQL does not have to build the metrics. A server that merely exposes table schemas may preserve tenant isolation while leaving calculation drift untouched.

How do Supabase teams without a data engineer give agents governed access?

For a small Supabase team, these controls belong to the first agent deployment. Agent access should start with a dedicated agent role without BYPASSRLS, with minimum DML privileges and no ownership-based bypass. Every table the agent touches needs RLS, and its policies need a defined tenant context. The server must also keep custody of the credentials and give agents access to governed calculations.

Maintaining the foundation requires continuing attention to RLS advisories, privilege audits, and metric modeling. A schema change that introduces an accessible table without RLS can silently open a gap. Observability must exist to surface such omissions.

A partner-driven implementation is therefore a risk-mitigation option. Bad authorization patterns and missing RLS coverage can remain unnoticed for months while agents query production data. To trace a query triggered by an agent back to the workflow it came from, teams need distributed tracing across the full stack as well as Supabase observability. Teams still need to link what a workflow does to the data it accesses, even without a dedicated data engineer.

One governed data layer should serve human teammates and AI agents. The pattern does not inherently require a separate warehouse, an ETL pipeline, or changes to production table schemas. It does require explicit ownership of permissions and metric definitions.

Why the MCP analytics layer is an architectural commitment, not a configuration option

The architectural commitment is to place authorization and metric definitions outside the agent's discretion. A restricted database role ensures that row policies apply, and a governed semantic interface gives the agent calculations it does not have to invent. Neither follows automatically from deploying an MCP server. Both must be properties of the connection path that the agent actually uses.

Product maturity is a selection criterion. The category of MCP servers exposing governed semantic models is relatively new, and some data infrastructure servers instead expose warehouse table schemas directly. Teams should check whether a server closes both gaps or just one. A server can enforce RLS correctly and still leave the agent to guess what a business metric means.

For Supabase teams, the row-enforcement mechanism already exists in Postgres as a core-server feature requiring no additional licensing. The architectural work is to preserve it through role selection, context handling, and restricted tool access, then pair it with defined metrics. A founder need not understand every Postgres internal to evaluate that design.

Sources

  1. Serverless MCP server for AI agent data lake access on Amazon ECS Fargate
  2. Build a semantic layer for agentic AI with EDB Postgres AI and Amazon Bedrock AgentCore
  3. From silos to insights: Federated data access patterns for AI agents
  4. AI Agent Data Access: Governed Patterns and Setup [2026]
Filed underMCP Data Layer

More in MCP Data Layer