Blog
guide

How to Query Your Database With AI Using MCP (No SQL Required)

Musthaq Ahamad
Musthaq Ahamad

You can now query your database with AI in plain English, from inside Claude or Cursor, and get the answer back without writing a single line of SQL. The piece that makes this work is a small open standard called MCP, the Model Context Protocol.

Anthropic released MCP on November 25, 2024. A year later, the community had built thousands of MCP servers, and the official registry held close to two thousand entries, up 407% in three months. OpenAI, Google, and Microsoft all adopted it in 2025. The standard that lets AI talk to your database is no longer niche.

This guide explains what it means to query a database with AI, how MCP makes the connection, what you need to set it up, and how to do it without putting your data at risk. For the protocol itself, read our companion guide on what MCP is.

What "querying your database with AI" actually means

You type a question. Something reads your schema, writes the SQL, runs it, and hands back rows or a chart. That something is an AI data analyst, and MCP is how it plugs into the AI tools you already use.

The translation layer is text-to-SQL: a large language model turns "how many trials converted last month" into a real query. The model only writes good SQL when it knows your tables, columns, and how they join. Schema context is the whole game, which is why we cover it in how text-to-SQL works.

MCP is the wire between the AI tool and that schema-aware query engine. Without it, every tool needs its own custom database integration. With it, one server speaks to all of them.

The round trip: question to answer

Here is the full path a question takes when you query your database over MCP. The AI tool is the host. Sequel is the MCP server connected to your database.

Flowchart: a plain-English question flows from the user to an AI tool, to the Sequel MCP server, to the database read-only, and back as an answer and chart

Five things happen in order. The table below maps each step to what the MCP server is doing under the hood.

StepWhat you seeWhat happens behind it
1. AskYou type a plain-English questionThe AI host receives your prompt
2. DiscoverA short pauseThe host lists the server's tools and reads your schema as context
3. Generate"Running a query..."The model writes SQL from the question and schema
4. ExecuteRows or a chart appearThe server runs the SELECT against your database, read-only
5. ExplainA written answerThe model reads the rows and answers in plain language

The discovery step is the one people miss. The model cannot write a correct query for a schema it has never seen. The MCP server exposes your schema so the model knows orders joins customers on customer_id, not by guessing.

Why MCP, and not a custom integration

Before MCP, connecting an AI tool to a database meant building a bespoke integration for that exact pairing. Five tools and five data sources meant up to twenty-five integrations. Anthropic calls this the M×N problem.

MCP collapses it to M plus N. Each tool implements MCP once. Each data source exposes an MCP server once. They all interoperate. The official analogy is "a USB-C port for AI applications": one connector, many devices.

For you, that means the same database connection follows you between tools. Connect once in Sequel, then query from Claude today and Cursor tomorrow. No rebuild.

Diagram comparing database integrations without MCP (many tool-to-database connections) versus with MCP (each tool and database connects once through MCP)

What you need to query a database with AI

Three pieces, and you likely have the first already.

  1. An MCP-capable AI tool. The host that runs the conversation.
  2. A database MCP server. The bridge to your data. Sequel's MCP server is built for this and handles schema context and read-only safety for you.
  3. A read-only database connection. So the AI can read but never write.

Most popular AI tools now act as MCP hosts. Here is where the common ones stand.

AI toolActs as MCP hostSequel setup guide
Claude DesktopYesConnect PostgreSQL to Claude Desktop
Claude CodeYesConnect PostgreSQL to Claude Code
CursorYesAdd the Sequel MCP server in settings
ChatGPTYesConnect PostgreSQL to ChatGPT
OpenAI CodexYesConnect PostgreSQL to Codex

You do not build any of this. With Sequel you connect your database in the dashboard, then add the Sequel MCP server to your tool with a config snippet. For the protocol mechanics behind the connection, see MCP for databases.

How to set it up, step by step

The flow is the same regardless of database or tool.

  1. Connect your database to Sequel. Add your connection in the dashboard. Use a read-only user. Our guide on read-only users in Postgres shows how to create one.
  2. Add the Sequel MCP server to your AI tool. Paste the config snippet, or use a one-click install where supported.
  3. Ask a question. Type "what was revenue by plan last month" and watch the round trip run.

That is the whole setup. The connect guides walk through each database and tool pairing with screenshots.

What you can ask once it is connected

The point of querying with AI is that the people who used to wait on the data team can answer their own routine questions. A few examples by team:

TeamA question they can now ask directly
Finance"What was net revenue by plan, month over month?"
Marketing"Which campaigns drove signups that converted to paid?"
Customer success"Which accounts dropped usage in the last 30 days?"
Product"What is the funnel from signup to first query?"

Each of these is a question you have once, not a dashboard you check daily. That is exactly where asking beats building a report. We cover the dividing line in AI data analyst vs BI tools.

A worked example

Say a finance lead types: "what was net revenue by plan last month?" The MCP server hands the model your schema, and the model writes something like this.

SELECT plan,
       SUM(amount) AS net_revenue
FROM invoices
WHERE status = 'paid'
  AND invoiced_at >= date_trunc('month', current_date - interval '1 month')
  AND invoiced_at <  date_trunc('month', current_date)
GROUP BY plan
ORDER BY net_revenue DESC;

The server runs it read-only, returns the rows, and the AI tool charts them. The finance lead never wrote SQL. They also see the query, so they can confirm it filtered to paid invoices and the right month before trusting the number. That visibility is the difference between a tool you can trust and a black box.

How accurate is the SQL?

Good, not perfect, and you should know the gap. On the BIRD benchmark, which grades text-to-SQL against real databases, the best models reach about 82% execution accuracy. Human data engineers score roughly 93%. As of December 2025, that leaves an 11-point gap.

So treat the generated query as a draft. The strongest internal systems agree. Uber, after shipping its own text-to-SQL tool, noted that hallucinated tables and columns "remain an area that we are constantly working on". Read the SQL, or have someone who can. We break down the numbers in how accurate text-to-SQL is.

The practitioners on r/SQL are blunt about it. One top comment put it simply: "You should never run AI generated queries blind." A tool that shows you the SQL it wrote lets you follow that advice.

Keeping it safe

Giving an AI access to your database sounds risky. It is manageable with a few habits.

  • Connect read-only. A read-only role runs SELECT and nothing else. It cannot DELETE, UPDATE, or DROP. Sequel runs read-only by default.
  • Scope the access. Limit the connection to the schema the AI should see, not the whole cluster.
  • Keep a human in the loop. Review queries that matter before acting on the results.
  • Watch for prompt injection. Untrusted data can carry hidden instructions. This is a real attack class, not a hypothetical.

These are not optional niceties. We go deep on the threats and the controls in MCP security and governance, including why over-privileged database users are the single most common mistake.

Where this is heading

The distance between "I have a question" and "here is the answer" keeps shrinking, and MCP is the standard closing it. Connect your database once, and every AI tool you use can read it, safely, in plain English. Want to try it on your own data? Get started free or see how Sequel's MCP server works.

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

Can I query my database with AI without knowing SQL?

Yes. You ask a question in plain English from a tool like Claude or Cursor, and an MCP server reads your schema, writes the SQL, runs it read-only, and returns the answer. Knowing a little SQL helps you sanity-check the result, but it is not required.

What is MCP and why does it matter for databases?

MCP, the Model Context Protocol, is an open standard from Anthropic that lets AI tools connect to external systems through one shared interface. For databases, it means any MCP-capable AI tool can read your schema and run queries without a custom integration built for each tool.

Is it safe to connect my production database to an AI tool?

It is safe when you connect through a read-only user, scope access to the right schema, and keep a human in the loop. Sequel connects read-only by default, so the AI can run SELECT queries but cannot change or delete data. Avoid connecting an AI agent directly to production with write access.

Which AI tools can query a database over MCP?

Any tool that acts as an MCP host. That includes Claude Desktop, Claude Code, Cursor, ChatGPT, and OpenAI Codex. Sequel's MCP server works across all of them, so the same database connection follows you between tools.

Do I need to write code to set this up?

No. With Sequel you connect your database in the dashboard, then add the Sequel MCP server to your AI tool with a config snippet or a one-click install. There is no integration code to maintain.

How accurate is the SQL the AI writes?

Good, not perfect. On the BIRD benchmark, the best models reach about 82% execution accuracy versus roughly 93% for humans, as of December 2025. Treat the generated query as a draft you can read and verify, not a black box.

Can the AI modify or delete my data?

Not when you connect with a read-only database user, which is the recommended setup. A read-only role can run SELECT statements but cannot INSERT, UPDATE, DELETE, or DROP. Sequel runs read-only by default.

What databases can I query this way?

Sequel supports PostgreSQL, MySQL, ClickHouse, BigQuery, and more, and can join across them in a single question. Check that your specific database or warehouse is supported before you commit.

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.