TutorialAug 7, 2026 · 8 min read

MCP database schema discovery permissions: let AI inspect structure without reading rows

An AI assistant needs database structure to form useful questions. It does not need permission to read every row merely to learn that an approved view contains customer_id, renewal_date, and plan.

Many teams combine schema discovery and data access under one broad database role. That makes setup easy, but it also makes metadata refresh a route to business data—and exposes sensitive structure the workflow never needed.

Treat schema discovery as its own contract

Define exactly which metadata the model can receive: approved databases, schemas, views, columns, data types, relationships, enum values, metric definitions, freshness, and descriptions. Everything else should be absent or explicitly denied.

Metadata is not harmless. Table and column names can reveal acquisition plans, security controls, customer categories, health data, payroll processes, or incident investigations. Comments, defaults, stored procedure bodies, samples, and statistics may expose values or internal logic.

Separate discovery identity from query identity

Use distinct operations and, where practical, distinct database or service identities:

  • Discovery: lists only approved objects and safe metadata.
  • Query: reads only approved views or operations under user and tenant scope.

The discovery path should not accept arbitrary SQL. The query path should not gain catalog visibility simply because a model asks for it. Separate audit events make it clear whether the assistant learned structure or accessed data.

See why natural-language SQL needs governed schema context.

Prefer an allowlisted metadata projection

Do not hand the model a raw dump of the system catalog. Build a filtered projection containing only objects approved for the workflow. It can be produced by a trusted service, reviewed metadata registry, or tightly scoped catalog queries.

A practical object record includes a stable object ID, display name, purpose, approved columns and types, join relationships, owner, classification, version, and last refresh time. Descriptions should be written for the workflow, not copied blindly from internal comments.

Expose approved views before base tables

Views can encode business definitions, remove sensitive fields, normalize names, and limit joins. They reduce the amount of raw schema the model must understand.

For example, a renewal workflow may discover one approved_renewals view with account, owner, plan, due date, and status. It should not discover the CRM ingestion tables, billing tokens, personal notes, or administrative schemas behind that view.

Use approved views for AI database agents to design that surface.

Decide what not to expose

Review these metadata classes explicitly:

  • unapproved schemas, temporary tables, and administrative objects;
  • column comments containing examples or sensitive explanations;
  • default values that embed identifiers, emails, or secrets;
  • function and procedure definitions;
  • index names and constraint text that reveal internal architecture;
  • database statistics, histograms, and sampled values;
  • foreign keys leading from approved views to restricted objects.

Omission is safer than asking the model to ignore metadata after it has entered context.

Version and refresh the schema context

Every discovery result needs a version or digest, source, observed time, and expiry rule. Schema context becomes operational state once tools depend on it.

Refresh on approved migrations or at a controlled interval. If a requested object is missing or the version is stale, the tool should refresh safely or return a structured error. It should not guess a renamed column from conversational memory.

Keep sample values out of discovery

Schema tools often include sample rows to make fields easier to understand. That collapses the separation between metadata and data access.

Use synthetic examples, enumerations approved for disclosure, or business definitions from a governed registry. If real values are required, fetch them through the query path with identity, purpose, tenant scope, row limits, redaction, and a separate audit record.

Test the boundary with negative cases

  1. Request an unapproved schema or system catalog.
  2. Ask for comments, defaults, function bodies, statistics, or sample rows.
  3. Follow a relationship from an approved view to a restricted base table.
  4. Use a guessed object name that exists but is not allowlisted.
  5. Change or remove a column and test stale-context behavior.
  6. Attempt to pass SQL through the discovery operation.
  7. Verify that another tenant or environment cannot change the metadata surface.

The correct result may be an empty list, explicit denial, or structured stale-context error. It should never be a broader catalog dump “for helpfulness.”

Make discovery observable

Log authenticated identity, tenant and environment, metadata contract version, requested object class, allowed result count, denied objects, refresh cause, latency, and trace ID. Avoid logging the full restricted catalog in denial messages.

Monitor sudden increases in discovered objects, repeated guesses of restricted names, stale-version errors, and discovery calls followed by unusually broad queries.

A practical implementation sequence

  1. Choose one narrow business workflow.
  2. Identify the minimum approved views and safe fields.
  3. Create a versioned metadata projection for those objects.
  4. Expose discovery and query as separate operations.
  5. Attach identity, tenant, environment, and purpose outside model text.
  6. Run the negative tests before enabling production data access.
  7. Refresh the projection through the migration process and review changes.

Where Conexor fits

Conexor provides MCP infrastructure for connecting AI clients to databases and APIs through governed tools. Separating schema discovery from row access helps teams keep structure, identity, permissions, and audit evidence explicit while still giving assistants enough context to work.

Explore the Conexor security model

For the next layer, see schema contracts for MCP database tools.

Relay

Quick questions

Relay

Quick questions

Ask me