How to Configure Claude Code SQL Server MCP Server
To set up a claude code sql server mcp server, connect an MCP server to your database using a read-only user. You then register that server in your local agent settings so the model can run queries. Teams often start by pasting an existing connection string into the local tool setup. When that string uses a broad database role, the coding agent gains power to change or drop tables. A safer plan uses a restricted database user from the very first day. How a claude code sql server mcp server wor
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.
To set up a claude code sql server mcp server, connect an MCP server to your database using a read-only user. You then register that server in your local agent settings so the model can run queries. Teams often start by pasting an existing connection string into the local tool setup. When that string uses a broad database role, the coding agent gains power to change or drop tables. A safer plan uses a restricted database user from the very first day.
How a claude code sql server mcp server works
Claude Code reaches outside tools and databases through the Model Context Protocol. The vendor docs note that MCP servers let the agent query databases and use APIs. You supply a database connection string to the MCP server on your machine. The official docs urge teams to put a read-only database user in that connection string. This step prevents the queries that the agent runs from changing your stored data. The docs also warn you to check that you trust each MCP server before connecting.
On the database side, a database user is the identity of a login when it connects. If an account needs many databases on an instance, admins create a SQL user with a login in master. If the agent only needs one database, a contained database user with a password is an option. An admin must first turn on contained databases on the server and the database. In total, the database engine supports thirteen types of database users.
Setting up read-only roles in SQL Server
After you create the database user, you assign a role to control what the agent can read. SQL Server provides fixed database roles for common access patterns. You cannot change the permissions assigned to these fixed database roles. Every role, including the public role, holds the basic permission to connect.
Many teams assign the fixed reader role to their AI agent account. Members of this reader role can read all data from all user tables and views. If you want to block writes for sure, you can also add the deny writer role. That role stops the user from adding, changing, or deleting data. You must avoid the owner role for any coding agent. Members of the owner role can run all maintenance tasks and even drop the database.
Also, to MCP servers, Claude Code can run shell commands through its Bash tool. In Manual mode, the Bash tool asks for human approval before running most commands. It only skips approval for a built-in set of safe read-only commands.
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
A read-only role stops the agent from changing rows or dropping tables through the MCP server. That solves the risk of accidental writes during a coding session. Yet native database roles only check who logs in and which tables they can touch. They do not inspect what individual queries do in flight.
Because the fixed reader role reads all user tables and views, the agent can still pull sensitive columns. A single query can return emails, phone numbers, card numbers, or national IDs into the model prompt. Also, storing a static database password in a local file creates a secret management chore. Every developer machine holds a live key that stays valid until someone rotates it by hand. Finally, the database log only shows that the shared read-only user ran a query. It does not tie each query back to a specific engineer or prompt.
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 login in master or a contained database user for an MCP server?
Use a contained database user if the coding agent only needs one or a few databases. This setup keeps the user and password inside the target database instead of the master database. Remember that an admin must first enable contained databases on the server and database.
Does the fixed reader role hide sensitive columns from Claude Code?
No, members of the fixed reader role can read all data across all user tables and views. If a table holds emails, phone numbers, or card numbers, the query results will include them. You need column-level rules or dynamic data masking to rewrite matched fields in results.
Can Claude Code still reach my database without an MCP server?
Yes, the agent can run command-line database tools through its built-in Bash tool. In Manual mode, the Bash tool requires your approval before it runs those shell commands. You should check every command carefully before you let the agent run it.
Related guides
In this post