DEV Community

Mads Hansen
Mads Hansen

Posted on

Schema context is the missing layer in MCP database agents

An AI agent cannot write a reliable database query from table names alone.

It needs context:

  • what each table means
  • which rows are active
  • which timestamps define freshness
  • which joins are approved
  • which columns should not be used for reporting
  • where tenant scope lives
  • what a safe example query looks like

Raw schema is not enough.

A column named status might mean subscription state, invoice state, support state, or deployment state. A table named events might be telemetry, billing events, audit events, or analytics.

If the MCP server hands the model a raw catalog and says “good luck,” the model will guess.

Better pattern:

  1. expose curated table descriptions
  2. document approved join paths
  3. include safe query examples
  4. separate schema discovery from query execution
  5. track context freshness/version
  6. make stale context visible before the answer

Longer version: Schema context for MCP database agents

The model does not just need access to the database. It needs the map.

Top comments (0)