To give GitHub Copilot agent mode access to your database, install DBCode in VS Code and save your connection. DBCode registers its tools with VS Code automatically, so there’s no .vscode/mcp.json to write: open Copilot Chat in agent mode and DBCode is already in the tools picker, ready to read your schema and run queries.
It works the same for Postgres, MySQL, SQL Server, MongoDB, and the rest of 100+ databases.
1. Install DBCode and add a connection
Install DBCode from the VS Code Marketplace, or start from the install page. Click the DBCode icon in the activity bar, add your connection, and test it.
2. Check Copilot can see it
Open Copilot Chat and switch to Agent mode. Click the tools icon at the bottom of the chat input. DBCode is listed as a server with its tools underneath.
You can also run MCP: List Servers from the command palette and look for DBCode.

3. Ask about your data
“What tables are in the sales_db database on my Postgres Dev connection? Then find accounts with no orders in the last 90 days.”
In agent mode, Copilot chains DBCode’s tools itself: it lists your connections, reads the schema of the database you named, then writes and runs the query against your real table and column names. The first time it calls a DBCode tool, you’re asked to sign in to DBCode if you aren’t already.
Two things save Copilot a guess:
- Name the connection and database when you have more than one.
- Set a default connection for the workspace. Copilot uses it when you don’t name one.
You can also drag a table or database from DBCode’s explorer into the chat to point Copilot at it.
4. Decide what Copilot may change
Reads and writes go through separate tools, so a question stays a question. What a write does next depends on the connection’s role.
Open the connection in DBCode and set AI access:
- Read-only: Copilot can run
SELECTand read the schema. Writes are denied. - Collaborator: Copilot asks before inserts, updates, and deletes. The confirmation and the SQL appear right in the chat.
DROPandTRUNCATEstay off. - Blocked: the connection is listed, but every call is rejected.
The stricter of the connection’s role and the AI role wins. Assigning an AI role is a Pro feature; the default, Same as user, is free, and so are the connection’s Read Only mode and roles.
Watch out for auto-approve
VS Code can remember tool approvals for the session, the workspace, or for good, and modes like Bypass Approvals or Autopilot skip prompts altogether. Any of those can quietly turn a Collaborator “ask” into a yes.
If a DBCode tool must always need a click, set it to false in chat.tools.eligibleForAutoApproval, and clear old approvals with Chat: Reset Tool Confirmations. DBCode’s own Deny permissions and the Blocked role are never bypassed by VS Code’s approval settings, so on production, prefer Read-only to Collaborator. More in how to let an AI agent query production safely.
Using Copilot CLI too
GitHub Copilot CLI runs outside the editor, so it gets DBCode through the CLI. Run DBCode: Install CLI, then in a Copilot CLI session run /mcp add with server name dbcode, type Local, command dbcode, arguments mcp. Same connections, same roles.
Copilot Tools docs · Full MCP documentation
FAQ
How do I add a database MCP server to Copilot in VS Code?
Install DBCode. It registers its MCP server with VS Code when it loads, so DBCode shows up in Copilot Chat's tools picker in agent mode without a .vscode/mcp.json entry. Run MCP: List Servers to confirm.
Does Copilot need my database connection string?
No. Copilot works through the connections saved in DBCode. The password stays in DBCode and nothing is written to an MCP config file.
Can I make Copilot ask before it changes data?
Yes. Set the connection's AI access to Collaborator and Copilot shows the SQL and asks for confirmation in the chat before any insert, update, or delete. Read-only denies writes outright.
Why did Copilot run a write without asking?
VS Code's saved tool approvals, and modes like Bypass Approvals or Autopilot, can skip Ask First prompts. Set the DBCode tool to false in chat.tools.eligibleForAutoApproval to always require a click, or use a Read-only AI role, which VS Code settings can't bypass.
Is it free?
The MCP server and Copilot's database tools are free, except copy data. Assigning an AI access role, data masking, and copying data are Pro.