How to Configure Cursor SQL Server MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a cursor sql server mcp server by adding a database tool in your editor settings. Then you give that tool a read-only database login so the AI agent can run queries. Most teams start by sharing a local database string with their coding agent. If that string uses an admin role, the agent can change or drop tables by mistake. Scoping the database user before the agent runs its first query prevents bad writes. How a cursor sql server mcp server works The Model Context Protocol lets AI

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a cursor sql server mcp server by adding a database tool in your editor settings. Then you give that tool a read-only database login so the AI agent can run queries. Most teams start by sharing a local database string with their coding agent. If that string uses an admin role, the agent can change or drop tables by mistake. Scoping the database user before the agent runs its first query prevents bad writes.

How a cursor sql server mcp server works

The Model Context Protocol lets AI coding editors reach external tools, databases, and APIs. When you ask the editor a question about your schema, it calls the database tool. The tool opens a session to SQL Server using the login details you gave it.

In SQL Server, a login lets a user reach the server instance. A database user is the identity of that login inside one database. For access to many databases on an instance, teams often create a login in master. For access to one or a few databases, a contained database user is an option. An admin must enable contained databases on the server and the database first.

Once the user exists, you assign a fixed database role. The db_datareader role lets the user read all data from all user tables and views. You can also add the db_denydatawriter role to stop the user from changing data. The db_denydatawriter role blocks adding, changing, or deleting rows in any user table. Avoid the db_owner role, which allows all maintenance actions and can drop the database. Note that you cannot change the permissions built into fixed database roles.

Why native database roles are not enough for AI agents

Setting up a read-only SQL user solves the problem of accidental table edits. The coding agent can inspect schemas and read rows without risking a data wipe. Still, native database roles only check who logs in and which tables they can read.

A user in the db_datareader role can still read every row in every user table by default. That includes sensitive fields like emails, phone numbers, card numbers, and national IDs. When the agent runs a broad query, those fields flow back into the editor prompt. Also, static connection strings often sit in plain text files on developer laptops. Anyone who copies that file gets the same database access as the coding agent.

Native roles also do not inspect individual queries while they run in flight. An agent can run a huge join that locks up CPU on a shared database. You also lack a clear log that ties each SQL statement to the human developer. Teams need a way to check queries, mask matched fields in results, and remove local keys.

Kubernetes API Server Access + Cursor / AI IDE Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Steps to harden your database setup for coding agents

Start by creating a dedicated SQL user just for your AI coding tool. Do not reuse the account your backend app uses to run in production. Add the new user to db_datareader and db_denydatawriter so it can only read rows.

If your agent only needs a few tables, skip the db_datareader role. Grant select rights only on the specific views or tables the agent needs for coding. If there is a sensitive table it must avoid, use custom grants or db_denydatareader. Remember that db_denydatareader blocks reading data from all user tables and views in that database.

Next, review how your team stores the database string on local machines. Do not commit tool settings files with real passwords into your git repo. Point the agent at a test or staging database with fake data whenever you can. When the agent must query real systems, add controls that rewrite sensitive fields in results.

Govern SQL Server queries and responses in flight

Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.

Frequently asked questions

Can I use the db_owner role for a local Cursor MCP setup?

Only use db_owner on a disposable local container with fake data. In SQL Server, db_owner can run all maintenance tasks and even drop the database. For shared or staging databases, always use a restricted read-only user instead.

Does db_datareader hide sensitive columns like emails or card numbers?

No, members of db_datareader can read all data from all user tables and views. To keep emails, phone numbers, or card numbers out of prompts, you must restrict columns or rewrite matched fields in results.

What is the difference between a standard login and a contained user in SQL Server?

A standard SQL user links to a server login stored in the master database. A contained database user has its own password inside a single database and does not need a login in master.

The query runs. The emails stay hidden.