AI Engineering · Case Study

Row-Level RBAC for Agentic Data Access via MCP

An LLM agent can call tools across a search index, a relational store, and external APIs. The access model asks two separate questions: which tools should this user even see, and — independently — which rows or documents can any given tool call actually return.

← All AI engineering work
Layer 1 · Tool gating
Which tools exist for this user

Resolved once, upstream, from the user's role: someone without a given grant never sees the related tool offered at all — not a rejected call, an absent option. Decided before any request reaches a data source.

Layer 2 · Row / document gating
Which rows a tool call can return

Independent of layer 1: every query to a data source carries the caller's access tags and filters by them at query time — so a tool that's available still can't surface a record outside the caller's grant.

Source
How access is enforced
Row-level
Search index
Every query carries the caller's access tags and applies them as a filter, so gating never affects relevance ranking — a restricted document simply isn't in the candidate set, not down-ranked
Enforced
Relational store
Before a generated query runs, the tables it touches are checked against an allow-list resolved from the caller's tags; anything outside that list — or any query that can't be confidently parsed — is refused rather than partially executed
Enforced
External APIs
These sources have no stored corpus to filter row-by-row — access control is entirely layer 1: if a user's role doesn't include the source, the tool for it is never offered
Tool-gated only

Enforcement depth is matched to what each source actually needs — not every source gets the same treatment, and the table says so honestly.

▸ Design notes
  • The two layers are owned by different services on purpose: the service that authenticates users resolves roles into access tags and a tool list; the service that talks to data sources trusts those tags and never re-derives a role itself — a clean split between who someone is and what a query is allowed to return
  • Access tags are free-text strings, not a fixed enum — adding a new access tier is a new tag value, not a schema or code change to the filtering logic itself
  • Visibility is additive: a record is visible if the caller holds any one of its tags, and nothing defaults to visible unless it's explicitly untagged or tagged public
  • The trust boundary is written down, not assumed: the filtering layer documents that it relies on the upstream layer having set tags correctly — an honest architecture names where a guarantee actually lives instead of implying it's stronger than it is
Next practice One Toolchain, Local and CI Identical →