Connect VS Code (GitHub Copilot) to Your SQL Database with MCP
· AI2SQL
Short answer: in VS Code, run MCP: Add Server from the Command Palette, choose HTTP, paste https://builder.ai2sql.io/api/chatgpt-mcp, and sign in with your AI2SQL account when VS Code asks. GitHub Copilot’s agent can then read your real schema and run read-only SQL on your PostgreSQL, MySQL or SQL Server database. There is no API key or database password in your config.
AI2SQL is a hosted MCP server for SQL databases. You connect a database once in AI2SQL, and any MCP client you sign in from gets the same governed access: schema reads, read-only queries, and a log of every call.
Why give Copilot your schema
Without the schema, Copilot guesses table and column names. With it, Copilot can:
- write queries and migrations against tables that actually exist,
- answer data questions while you code (“how many orders have a null
customer_id?”), - check whether a column is nullable or indexed before suggesting code that depends on it.
Set it up in VS Code
Before you start, connect your database in AI2SQL (Connections → Add database). PostgreSQL, MySQL and SQL Server work for live schema and queries.
Option 1: install link
Open AI agents → VS Code in the AI2SQL dashboard and click Add to VS Code. VS Code opens and asks you to confirm the server.
Option 2: Command Palette
- Open the Command Palette (
Cmd+Shift+P/Ctrl+Shift+P) and run MCP: Add Server. - Choose HTTP.
- Paste the server URL:
https://builder.ai2sql.io/api/chatgpt-mcp - Name it
ai2sqland pick where VS Code should save it.
Option 3: edit mcp.json
For a workspace, add .vscode/mcp.json:
{
"servers": {
"ai2sql": {
"type": "http",
"url": "https://builder.ai2sql.io/api/chatgpt-mcp"
}
}
}
VS Code’s MCP menus move between releases. If a label differs from the steps above, search the Command Palette for “MCP”.
Sign in
The first time Copilot starts the server, VS Code asks to authenticate with builder.ai2sql.io. Allow it, sign in to AI2SQL in the browser tab that opens, and press Allow on the consent screen. VS Code stores the token; you will not see it in your files.
Use it from Copilot Chat
Open Copilot Chat in Agent mode and check that the ai2sql tools are enabled in the tools picker. Then ask:
What tables are in my database, and how are orders linked to customers?
Copilot calls list_connections and describe_schema, then answers from your real schema. For data questions it writes a SELECT and runs it with run_query.
The tools Copilot gets
| Tool | What it does |
|---|---|
list_connections | Lists the databases you connected in AI2SQL |
describe_schema | Returns tables, columns and types for one connection |
run_query | Runs one read-only SELECT / WITH, up to 1,000 rows |
generate_sql | Writes SQL from a plain-English request |
fix_sql, explain_sql, optimize_sql, convert_sql | Repair, explain, speed up or translate a query between dialects |
What Copilot cannot do
- Write data. INSERT, UPDATE, DELETE and DDL are rejected before they reach the database. See read-only database access for AI.
- See your password. It holds an OAuth token you can revoke; database credentials stay encrypted on the AI2SQL server.
- Act unlogged. Every call shows up in Agent activity, including blocked write attempts.
Troubleshooting
- The tools do not appear. Make sure Copilot Chat is in Agent mode and the server is started (Command Palette → MCP: List Servers).
- “Run queries on your database” is refused. Running SQL on your own database needs Pro or Team. Schema reads work on every plan.
- No databases listed. Add one under Connections in the AI2SQL dashboard first.
Other editors and agents
The same server works from Cursor, Devin Desktop (formerly Windsurf), Gemini CLI, Claude, n8n and your own agent.
Frequently asked questions
Can GitHub Copilot in VS Code query my database?
Yes. VS Code supports remote MCP servers, and AI2SQL is one. Add https://builder.ai2sql.io/api/chatgpt-mcp as an HTTP server, sign in with your AI2SQL account, and Copilot's agent can list your connections, read the schema and run read-only SELECT queries on PostgreSQL, MySQL or SQL Server.
Do I need to paste an API key or my database password into VS Code?
No. VS Code signs in to AI2SQL with OAuth in your browser. Your database credentials stay encrypted on the AI2SQL server and never appear in mcp.json or your repository.
Can Copilot change or delete data through AI2SQL?
No. run_query accepts one SELECT or WITH statement. INSERT, UPDATE, DELETE and DDL are blocked by the SQL guard before anything reaches your database, and each call returns at most 1,000 rows.
What is free and what needs a paid plan?
Signing in, listing connections, reading schemas and a few SQL writing requests a day are free. Running queries against your own database needs the Pro or Team plan, which start with a 7-day trial.
Where do I see what Copilot ran?
Every call is logged in Agent activity in the AI2SQL dashboard with the SQL, the database, the result and the latency, including blocked write attempts.