To connect Cursor’s agent to MySQL or any other database, install DBCode from Cursor’s Extensions view and save your connection in it. DBCode registers its MCP server with Cursor automatically, so there is no .cursor/mcp.json to edit and no password in an env block: the agent gets the connections you’ve saved, under the permissions you set on each one.
It works the same way for MySQL, Postgres, SQL Server, MongoDB, and the rest of 100+ databases.
The usual way vs this way
Most guides for Cursor and a database go like this: pick an MCP server package for your database, add it to ~/.cursor/mcp.json, put the host, user, and password in its env block, refresh Cursor’s MCP settings, and repeat for each database you use.
With DBCode, the connection is something you already set up to browse the database. The agent reuses it.
1. Install DBCode in Cursor
Open the Extensions view in Cursor and search for DBCode. DBCode publishes every release to Open VSX, which is where Cursor installs extensions from. Or start from the install page.
2. Add your connection
Click the DBCode icon in the activity bar and add a connection: host, port, user, password, database. Test it, save it. You can browse tables and run queries yourself from here, which is a good way to check the connection before the agent uses it.
3. Find DBCode in Cursor’s MCP list
Open Cursor’s MCP settings or the tools picker. DBCode is listed with its tools. Nothing to add, nothing to refresh.
4. Ask the agent
Use a chat that allows MCP tools:
“Read the tables in the shop database on my MySQL connection, then find customers who ordered more than three times last month.”
The agent lists your connections, reads the schema, 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.
If you have several connections, naming the one you mean (“on my MySQL Staging connection”) saves the agent a guess.
Keep the agent read-only
By default the agent gets the same access you have on a connection. To narrow it, open the connection in DBCode and set AI access:
- Read-only: the agent can run
SELECTand read the schema. Every write is denied. - Collaborator: the agent reads freely and asks you before any insert, update, or delete.
DROPandTRUNCATEstay off. - Blocked: the connection is listed, but every tool call against it is rejected.
The stricter of the connection’s own role and the AI role wins, so an AI role can only take access away. Assigning an AI role is a Pro feature. The connection’s own Read Only mode and roles are free, and so is the MCP server. More in how to let an AI agent query production safely.
Things worth knowing
- Each Cursor window connects on its own. The agent in one window sees the same saved connections as another, plus that window’s workspace connections.
- Claude Code in Cursor’s terminal can share the same connections: run DBCode: Install CLI, then
claude mcp add dbcode -- dbcode mcp --app Cursor. See how to give Claude Code access to your database. - Mask sensitive columns before the agent reads them with AI data masking (Pro).
DBCode in Cursor · Full MCP documentation
FAQ
Do I need to edit .cursor/mcp.json to connect a database?
Not with DBCode. It registers its MCP server with Cursor when the extension loads, so it shows up in Cursor's MCP settings and tools picker without a config entry.
How do I connect Cursor to MySQL with MCP?
Install DBCode from Cursor's Extensions view, add your MySQL connection in DBCode, and ask the agent about your data in a chat that allows MCP tools. Cursor finds the DBCode server on its own.
How do I stop Cursor's agent from changing data?
Set the connection's AI access to Read-only in DBCode's connection editor. The agent can still run SELECT and read the schema, and every write is denied before it reaches the database. You can also turn on the connection's Read Only mode, which applies to everyone.
Where does my database password go?
It stays in DBCode's connection settings. Nothing is written to an MCP config file, so there is no password in an env block to leak.
Can Claude Code running in Cursor's terminal use the same connections?
Yes. Install the DBCode CLI from the command palette and run claude mcp add dbcode -- dbcode mcp --app Cursor. It reads the connections you saved in Cursor.