How to Configure Claude Code SQL Server Connect
You set up a claude code sql server connect workflow through an MCP server. You can also let the agent run database tools through its shell tool. Many teams start by giving the agent a shared login string on a laptop. That shortcut creates big risks when the database user has broad write roles. A bad query from an agent can change rows or drop a whole database. How a claude code sql server connect workflow works Claude Code reaches outside tools and databases through the Model Context Protoco
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 claude code sql server connect workflow through an MCP server. You can also let the agent run database tools through its shell tool. Many teams start by giving the agent a shared login string on a laptop. That shortcut creates big risks when the database user has broad write roles. A bad query from an agent can change rows or drop a whole database.
How a claude code sql server connect workflow works
Claude Code reaches outside tools and databases through the Model Context Protocol, or MCP. An MCP server gives the coding agent a bridge to your database and APIs. You give the MCP server a login string so it can run queries. Official docs advise you to use a read-only database user in that login string. That way, the queries the agent runs cannot change your stored data. The docs also warn you to check that you trust each MCP server first.
Claude Code can also reach a database by running commands in its Bash tool. In Manual mode, the Bash tool asks for your approval before it runs commands. Only a small built-in list of safe local commands can run without approval. Once you approve a database command, the database checks the user in the string.
In SQL Server, a database user is the identity of a login inside a database. When someone needs many databases on one server, teams make a login in master. Then they map a SQL user to that login inside each target database. When someone needs just one or a few databases, a contained user works well. A contained database user has its own password and no login inside master. An admin must first turn on contained databases on the server and database. SQL Server supports thirteen distinct types of database users for these setups.
Choosing SQL Server roles for AI coding agents
After you make the database user, you must assign it to a fixed role. You cannot change the built-in permissions that belong to fixed database roles. Every role, including the default public role, holds the basic permission to connect. Many teams make the mistake of using the database owner role for local setups. A member of the database owner role can run all setup and maintenance tasks. That role can even drop the whole database in SQL Server if a prompt misfires.
A safer choice is the fixed data reader role combined with deny rules. Members of the data reader role can read all data from all user tables. They can also read all user views inside that database. Meanwhile, the data writer role lets a user add, delete, or change table data. To lock down an agent, you can add the deny data writer role. A user in the deny data writer role cannot add, change, or delete rows. If you must hide tables, the deny data reader role blocks all table reads. An admin adds users to these fixed roles with standard role change statements.
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 decide who can log in and which tables they read. Giving an agent a read-only user stops it from deleting rows or dropping tables. Still, the fixed data reader role still lets the agent read every user table. If a table holds emails, phone numbers, card numbers, or national IDs, queries return them. The raw values go straight back into the model context during the session.
Also, a login string on a developer laptop keeps a static password on disk. Anyone or any script on that machine can reuse that string at any time. Native roles check the user at login, not what each query returns in flight. Teams still need a way to mask sensitive fields and review single statements.
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 run queries against SQL Server?
It connects through an MCP server that you configure with a database login string. It can also run command-line database tools through its Bash tool after your approval.
Which SQL Server role should I give an AI coding agent?
Use the fixed data reader role and add the deny data writer role. Avoid the database owner role because it can change data and drop the database.
Does a read-only SQL Server user stop sensitive data exposure?
No, the fixed data reader role can read all rows in all user tables by default. You need field masking to rewrite emails, phone numbers, or card numbers in results.
Related guides
In this post