How to Configure Claude Code SQL Server Permissions
You set up claude code sql server permissions by making a read-only database user. Then you pass that user to a Model Context Protocol server or command tool. Many teams start by reusing an admin account from a local file. That shortcut gives the AI agent the power to change or delete live tables. A broad role turns a small prompt mistake into a major data loss event. Good database rules stop the agent from running bad writes or dropping tables. How claude code sql server permissions work in p
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 claude code sql server permissions by making a read-only database user. Then you pass that user to a Model Context Protocol server or command tool. Many teams start by reusing an admin account from a local file. That shortcut gives the AI agent the power to change or delete live tables. A broad role turns a small prompt mistake into a major data loss event. Good database rules stop the agent from running bad writes or dropping tables.
How claude code sql server permissions work in practice
Claude Code talks to outside systems in two main ways. First, it uses Model Context Protocol servers to reach tools, databases, and APIs. Vendor docs advise using a read-only user in the database string. This stops the queries the agent runs from changing any data. Second, the agent runs shell commands through its built-in Bash tool. In Manual mode, the Bash tool asks for human approval before running most commands. Only a small set of safe read commands run without a prompt.
On the database side, SQL Server splits identity between logins and database users. A login lives in the master database and works across many databases. A database user is the identity of that login inside one specific database. Admins can also make a contained database user with its own password. This user stays inside one database and does not need a master login. First, the admin must turn on contained databases on the server and database. SQL Server supports thirteen different types of database users for different needs.
Choosing the right SQL Server roles for AI agents
After you make the database user, you assign it a fixed database role. You cannot change the base rules inside SQL Server fixed database roles. Every role, including the public role, holds the basic permission to connect. The data reader role lets the user read all data from user tables. It also lets the user read all views in that database. You can pair it with the deny data writer role for extra safety. That deny role blocks the user from adding, changing, or deleting table data.
Never give an AI agent the database owner role or data writer role. The data writer role allows adding, deleting, or changing rows in any user table. The database owner role can run all setup tasks and even drop the database. If a table holds secret records, use the deny data reader role too. Members of that role cannot read data or metadata from user tables and views.
Claude Code Security + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native SQL Server roles do a great job of blocking direct table writes. When the agent connects with a read-only role, update and delete statements fail. This setup solves the problem of accidental table drops or altered rows. It sets a clear boundary around which database the agent can enter.
Still, native roles only check who logs in at the start of a session. They do not inspect what individual queries do while they run in flight. A read-only user can still read every column in every user table and view by default. That means the agent can pull emails, phone numbers, card numbers, or national IDs. A role also cannot stop an expensive query from locking up server memory. Also, the developer still holds the raw database password on their machine. Native roles alone cannot mask fields in results or require approval per query.
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
Should I use a standard login or a contained user for Claude Code?
Use a contained database user if the agent only needs one or two databases. It keeps the user and password inside the target database without a master login. Use a login in master only when the agent must query many databases.
Does the SQL Server data reader role hide sensitive columns from the agent?
No, the fixed data reader role allows reading all user tables and views. It does not rewrite or mask emails, phone numbers, or card numbers in results. You need extra controls if you want to mask sensitive fields in query outputs.
Can Claude Code run database commands without an MCP server?
Yes, Claude Code can run database CLI tools through its built-in Bash tool. In Manual mode, the Bash tool requires your approval before running those commands. You should still enforce read-only SQL Server permissions on the database account it uses.
Related guides
In this post