Short answer: connect Claude to SQL Server through an MCP server that only runs
read-only SQL, using a login that is only in db_datareader. With AI2SQL you add the
database once, add the connector https://builder.ai2sql.io/api/claude-mcp to Claude (or the editor URL to Cursor),
and sign in. The same steps work for Azure SQL and Amazon RDS for SQL Server.
Step 1: a read-only SQL Server login
Enforce read-only in SQL Server itself, so a write fails even if every other layer missed it:
-- SQL Server / RDS
CREATE LOGIN claude_ro WITH PASSWORD = 'a-long-random-Passw0rd!';
USE AppDb;
CREATE USER claude_ro FOR LOGIN claude_ro;
ALTER ROLE db_datareader ADD MEMBER claude_ro;
-- Azure SQL Database (contained user, run in the database)
CREATE USER claude_ro WITH PASSWORD = 'a-long-random-Passw0rd!';
ALTER ROLE db_datareader ADD MEMBER claude_ro;
To hide sensitive tables, skip db_datareader and grant SELECT on specific
schemas instead, for example GRANT SELECT ON SCHEMA::sales TO claude_ro;.
Step 2: add the database to AI2SQL
Sign in at builder.ai2sql.io, open Connections, pick
SQL Server and enter the host, port (usually 1433), database and the
claude_ro login. If the server only listens on localhost or inside a private network, use
the desktop connector instead.
Step 3: add the connector
claude.ai or Claude Desktop
- Open Customize → Connectors.
- Add AI2SQL from the directory, or choose Add custom connector and paste the URL below.
- Press Connect, sign in to AI2SQL and press Allow.
https://builder.ai2sql.io/api/claude-mcp Claude Code
claude mcp add --transport http ai2sql https://builder.ai2sql.io/api/claude-mcp Then run /mcp, pick ai2sql and choose Authenticate.
Cursor
{
"mcpServers": {
"ai2sql": {
"url": "https://builder.ai2sql.io/api/chatgpt-mcp"
}
}
} Add it to ~/.cursor/mcp.json, then click Needs login next to ai2sql in Settings → MCP. More in Cursor MCP SQL server.
Step 4: ask a question
Try "Use AI2SQL to describe my SQL Server database and show the top 10 customers by revenue this
quarter." Claude reads the real schema with describe_schema, writes T-SQL and runs it
with run_query, up to 1,000 rows.
What keeps it safe
- Database level: the
claude_rologin can only read. - Gateway level: one
SELECTorWITHstatement per call; writes and DDL are rejected before they reach SQL Server. - Limits: results are capped at 1,000 rows.
- No shared secrets: Claude and Cursor hold a revocable OAuth token, never the SQL Server password.
- Audit: every call appears in Agent activity with the SQL, the database and the result.
AI2SQL or Microsoft's SQL MCP Server?
Microsoft's SQL MCP Server (part of Data API builder) is self-hosted and exposes the tables and views you configure as typed operations. It suits teams that want to run and govern their own server. AI2SQL is hosted: no server to run, natural-language questions over the whole readable schema, OAuth sign-in from Claude and Cursor, and an audit log. If you only need Claude to answer questions from SQL Server data, the hosted connector is the shorter path.