How to Configure Claude Code SQL Server Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code sql server least privilege by creating a read-only database user. Then you pass that restricted user to the AI agent through its database tool. Teams often start by reusing a broad developer login for quick testing. If that login has owner rights, the agent can change or drop production tables. A tight role setup prevents accidental data changes while the agent writes code. How claude code sql server least privilege works in practice Claude Code reaches external systems

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 least privilege by creating a read-only database user. Then you pass that restricted user to the AI agent through its database tool. Teams often start by reusing a broad developer login for quick testing. If that login has owner rights, the agent can change or drop production tables. A tight role setup prevents accidental data changes while the agent writes code.

How claude code sql server least privilege works in practice

Claude Code reaches external systems and databases through the Model Context Protocol, or MCP. It can also run 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 built-in list of safe read commands runs without a prompt. When you use an MCP server to query databases, you provide a connection string. Vendor docs advise putting a read-only database user inside that connection string. This stops the queries that the agent runs from changing your data.

On the database side, SQL Server manages access through logins and database users. A login in the master database lets a person reach many databases on an instance. A database user is the identity of that login inside one specific database. You can also set up a contained database user with its own password. This user stays inside one database and does not need a master login. An admin must first turn on contained databases on the server and database.

Choosing the right SQL Server roles for AI agents

Once you create the database user, you assign permissions through roles. SQL Server includes fixed database roles with preset permissions that you cannot change. Every role, including the public role, has basic permission to connect. The fixed reader role lets members read all data from all user tables and views. The fixed writer role lets members add, delete, or change data in user tables. The fixed owner role allows all setup tasks and can even drop the database.

For an AI coding agent, you should never assign the owner or writer roles. Adding the agent user to the deny writer role blocks all data changes. If the agent only needs a few tables, the fixed reader role is too wide. Because it reads all user tables, it can expose sensitive records to the model. Instead, grant select rights on specific views or tables only. You can also add the deny reader role to block table reads by default.

Least Privilege Principle + Claude Code Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they leave open

Native database roles decide who can log in and which tables they can read. They block write commands at the database engine when a user lacks write rights. This setup stops an agent from dropping tables or deleting rows by mistake.

Still, static roles do not check what individual queries do in flight. A read-only user can still pull thousands of customer emails or phone numbers. Those raw card numbers and national IDs then enter the AI model context. The local MCP setup also stores a plain database password on the developer machine. Anyone with access to that local file can use the login directly. Finally, database roles cannot ask a human to approve a heavy query before it runs. To close these gaps, teams need runtime controls that inspect queries and rewrite sensitive fields.

Add runtime guardrails beside SQL Server

Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.

Frequently asked questions

How does Claude Code reach a SQL Server database?

The agent reaches databases through an MCP server or by running shell commands. You give the MCP server a connection string that holds your database user credentials.

Should I give the AI agent the fixed reader role in SQL Server?

Only use the fixed reader role if the database holds no sensitive fields. That role lets the user read every user table and view in the database. For tighter control, grant read rights only on the specific tables the agent needs.

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

A standard SQL login lives in the master database and works across the server instance. A contained database user has a password stored inside one specific database. Contained users work well when an agent only needs access to a single database.

The query runs. The emails stay hidden.