Blog
guide

MCP for Databases: How AI Tools Connect to Your Data

Musthaq Ahamad
Musthaq Ahamad

When you ask Claude "how many orders shipped late last week," Claude does not know your database exists. It has never seen your orders table. Something has to hand it your schema, take the SQL it writes, run that SQL safely, and return the rows. That something is a database MCP server.

This is the piece that turns a general AI tool into one that can answer questions about your specific data. This guide explains what a database MCP server is, the exact lifecycle of a query, and what separates a server you can trust in production from one you cannot. For the protocol itself, start with what MCP is.

What a database MCP server is

A database MCP server sits between an AI tool and your database. It speaks the Model Context Protocol to the AI tool and SQL to your database. To the AI host, it is just another MCP server. To your database, it is just another client running queries.

Its job is two things: give the model enough context to write a correct query, and run that query without putting your data at risk. Sequel's MCP server does both, and works across Claude, Cursor, and ChatGPT from a single connection.

The lifecycle of one query

Here is what happens, in order, when you ask a question. The sequence below traces a plain-English prompt from the AI tool to your database and back.

Sequence diagram of a database query over MCP: the AI host lists tools, the Sequel server introspects the schema, the model writes SQL, the server runs it read-only, and rows return as an answer

Each stage maps to a concrete action. This table is the same flow, described step by step.

StageWhat the server does
DiscoveryTells the host which tools and resources it offers
Schema introspectionReads system catalogs for tables, columns, types, and keys
Context deliveryExposes that schema to the model as a resource
GenerationThe host's model writes SQL from your question and the schema
ExecutionRuns the query against your database, read-only
ResponseReturns rows, which the model turns into an answer

The pgEdge Postgres MCP server documents this same pattern: discovery, then schema introspection from catalogs like pg_class and pg_attribute, then tool execution, then response. It is the standard shape of a database MCP server.

Schema as a resource, queries as a tool

A database MCP server exposes your database through two of MCP's three primitives.

  • The schema is a resource. Read-only context. The model reads your tables, columns, types, primary keys, and foreign keys so it knows how data connects.
  • Query execution is a tool. The model calls it with a SQL statement. A safe server restricts this to SELECT.

The official docs give this exact example: an MCP server for a database "can expose tools for querying the database, a resource that contains the schema of the database, and a prompt that includes few-shot examples." That is the blueprint every database server follows.

Why schema context is the whole game

The model only writes good SQL when it understands your data model. This is the step people underestimate, and it is where most naive setups fail.

Pinterest, which has "hundreds of thousands" of tables in its warehouse, found that the hard part was "identifying the correct tables," not writing the query once the tables were known. Finding the right three tables among hundreds of thousands is the real problem.

Schema alone is not always enough, either. As one data engineer put it on r/dataengineering, "knowing what columns and data types are in tables does not include business context." A column named status means nothing without knowing what its values represent. The best database MCP servers add that context. We unpack how in how text-to-SQL works.

Read-only by design

A database MCP server should never be able to change your data. The control is simple: connect through a read-only database user.

A read-only role can run SELECT statements but cannot INSERT, UPDATE, DELETE, or DROP. Even if the model generates a destructive query, and even if untrusted input tries to trick it, the database itself refuses. Our guide on read-only users in Postgres shows how to create one in a few lines.

Sequel runs read-only by default. This is not a setting you have to remember to enable. It is the baseline, because connecting an AI agent to a production database with write access is the mistake that causes incidents. We cover why in MCP security and governance.

Which databases work over MCP

A database MCP server can expose a transactional database or a warehouse using the same pattern. Sequel supports the common ones, each with a setup guide.

DatabaseTypeSetup guide
PostgreSQLTransactionalConnect PostgreSQL to Claude Code
MySQLTransactionalConnect MySQL to Claude Code
ClickHouseAnalyticalConnect ClickHouse to Claude Code
BigQueryWarehouseConnect BigQuery to Claude Code

Because the server normalizes everything to MCP, you can ask one question that joins data across these sources. The model sees a unified schema, not four disconnected ones.

Build your own, or use a managed server

You can build a database MCP server. The SDKs and open-source reference servers make a basic one approachable. The question is what happens past the demo.

ConcernDIY serverManaged server (Sequel)
Basic schema introspectionYou build itBuilt in
Table selection at scaleHard, you tune itHandled
Read-only enforcementYou configure itDefault
Cross-database joinsYou wire each sourceBuilt in
Audit loggingYou add itBuilt in
Works across AI toolsYou test eachOne connection

A weekend project gets you a server that queries one database from one tool. Production-grade schema context, table selection across a large warehouse, and audit logging are the work. That is the gap a managed AI data analyst fills.

A note on accuracy

The query the model writes is a draft, not gospel. On the BIRD benchmark, the best models reach about 82% execution accuracy against real databases, versus roughly 93% for humans, as of December 2025. A good database MCP server shows you the SQL it ran so you can check it. We cover the numbers in how accurate text-to-SQL is.

The takeaway

A database MCP server is the bridge that gives an AI tool your schema and runs its queries safely. Get the schema context and the read-only enforcement right, and any AI tool can answer questions about your data. Want the bridge without building it? Get started free or read how to query your database with AI using MCP.

Try Sequel

Meet your always-on data analyst.

An AI data analyst that connects to all your data and answers questions with reports and visualizations. Free for up to 3 seats - no credit card required.

Get started free

Frequently asked questions

What is a database MCP server?

A database MCP server is a program that exposes your database to AI tools through the Model Context Protocol. It shares your schema as read-only context and offers query execution as a tool the model can call. Sequel is a database MCP server that handles schema understanding and read-only safety for you.

How does an AI tool get my database schema?

The MCP server introspects your database, reading system catalogs for tables, columns, types, keys, and constraints. It then exposes that schema as an MCP resource. The AI model reads the schema as context before writing any SQL, so it knows how your tables relate.

Which databases work with MCP?

Most major databases and warehouses can be exposed over MCP. Sequel supports PostgreSQL, MySQL, ClickHouse, and BigQuery, among others, and can join across them in a single question. Check that your specific database is supported before you set it up.

Is a database MCP server read-only?

A well-built one is, or it connects through a read-only database user. That means the AI can run SELECT queries but cannot INSERT, UPDATE, DELETE, or DROP. Sequel runs read-only by default, which is the safest way to connect production data.

Can I build my own database MCP server?

Yes. Open-source reference servers exist for databases like Postgres, and the SDKs make it possible. The hard parts are schema context at scale, table selection across large warehouses, read-only enforcement, and auditing. A managed server like Sequel handles those for you.

Does MCP work with data warehouses like BigQuery?

Yes. A database MCP server can expose a warehouse the same way it exposes a transactional database, by introspecting the schema and offering read-only query tools. Sequel connects to BigQuery and can join warehouse data with other sources in one question.

How is a database MCP server different from a text-to-SQL tool?

Text-to-SQL is the part that turns a question into a query. A database MCP server is the connection layer that gives the model your schema and runs the query, exposed over a standard any AI tool can use. The MCP server uses text-to-SQL inside it.

Written by

Musthaq Ahamad
Musthaq Ahamad

Co-founder and CEO of Sequel. Previously built developer tools and data infrastructure. Passionate about making data accessible for everyone.