MCP SQL Server: Connect Any AI Agent to Your SQL Database

An MCP SQL server is a Model Context Protocol connector that lets an AI agent — Claude, Cursor, ChatGPT, or any MCP-compatible client — read and query a SQL database directly. Instead of copying schemas into a prompt or pasting query results back and forth, the agent talks to your database through one standard protocol and gets structured, live answers.

This guide explains what an MCP SQL server is, how it works, what “read-only by default” really means, and how to connect one to your Postgres, MySQL, or SQL Server database in a few minutes.

What an MCP SQL server actually does

The Model Context Protocol (MCP) is an open standard from Anthropic that gives AI models a universal way to reach external tools and data. An MCP server is the piece that exposes one specific data source. An MCP SQL server exposes a SQL database: it advertises the tables and columns the agent is allowed to see, accepts a query request, runs it, and returns rows in a structure the model can reason over.

In practice that means you can ask your agent things like “which customers churned last month and what did they spend before leaving?” and it will inspect the schema, write the SQL, run it against your real database, and answer — without you writing a line of SQL or leaving your chat window.

Read-only by default — why it matters

The biggest risk with connecting an AI to a production database is that it might change or destroy data. A well-designed MCP SQL server is read-only by default: the agent can SELECT and answer questions, but it cannot DROP, DELETE, UPDATE, or overwrite anything. AI2SQL enforces this at the gateway with a SQL guard that rejects any write or DDL statement before it ever reaches your database.

This is what makes it safe to point an agent at real data. For more on the trade-offs, see is it safe to connect AI to a database and our note on why “read-only” is often not actually read-only in naive setups.

Setting up an MCP SQL server with AI2SQL

You don’t have to build and host an MCP server yourself. AI2SQL runs a governed MCP gateway — you connect your database once, get an API key, and drop this config into your MCP client:

{
  "mcpServers": {
    "ai2sql": {
      "url": "https://builder.ai2sql.io/api/mcp",
      "headers": {
        "x-ai2sql-key": "sk_live_your_key",
        "x-ai2sql-connection": "conn_your_database"
      }
    }
  }
}

The gateway handles authentication, schema introspection, the read-only SQL guard, and query execution. Your agent sends natural-language intent; AI2SQL turns it into safe, dialect-aware SQL and returns the rows.

Client-specific walkthroughs:

Supported databases

The same MCP SQL server works across engines, so the agent writes correct dialect-specific SQL for whichever database you connect:

MCP SQL server vs. a self-hosted one

You can run an open-source MCP SQL server yourself — for example one of the server-sqlite or mssql-mcp-server projects on GitHub. That gives you full control but means you own the hosting, the credential handling, and the read-only enforcement. A governed gateway like AI2SQL trades a little control for connection management, per-connection API keys, audit logging, and a SQL guard you don’t have to write. See AI2SQL gateway vs. a Postgres MCP server for the full comparison.

Try it

Connect a database and get your MCP SQL server config in a couple of minutes — read-only by default, no credit card to start.

TRY IT — FREE, NO SIGNUP
Try one: