How to Configure Claude Code SQL Server Credentials
You set up claude code sql server credentials by creating a read-only database user. Then you pass that user login string to your Model Context Protocol server. Teams often start by reusing a shared admin account to test database queries fast. Still, broad permissions let an AI coding agent alter tables or read sensitive rows. A safe setup scopes the database identity before the agent runs its first query. How to set up claude code sql server credentials Claude Code reaches outside systems an
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 credentials by creating a read-only database user. Then you pass that user login string to your Model Context Protocol server. Teams often start by reusing a shared admin account to test database queries fast. Still, broad permissions let an AI coding agent alter tables or read sensitive rows. A safe setup scopes the database identity before the agent runs its first query.
How to set up claude code sql server credentials
Claude Code reaches outside 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 approval before running most commands. Only a small set of safe read commands run without a prompt. When you link a database MCP server, the agent uses your login string. Vendor docs tell you to put a read-only user in that string. That way, the queries that Claude Code runs cannot change your data.
On the database side, SQL Server splits login accounts into two main patterns. A database user represents the identity of a login inside one specific database. If a person needs many databases on one instance, admins create a master login. They map a SQL user to that login in the master database. If the agent only needs one database, you can use a contained database user. A contained user has a password and does not tie to the master database. An admin must turn on contained databases on the server and database first. SQL Server supports thirteen types of database users in total.
Choosing fixed roles for read-only database users
Once you create the database user, you must assign its read permissions. SQL Server offers fixed database roles with preset permissions that you cannot alter. All database roles, including the public role, hold basic permission to connect. Adding a user to the fixed data reader role grants read rights everywhere. Members of that role can read all data from all user tables and views.
By contrast, the fixed data writer role lets users add, change, or delete data. The database owner role can run all maintenance tasks and even drop the database. Never give data writer or owner roles to an AI coding agent. You can also combine roles to block writes or reads at the database level. The deny data writer role stops a user from adding, changing, or deleting rows. The deny data reader role blocks all reads from user tables, views, and metadata.
Claude Code Security + Ephemeral Credentials: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where native database roles fall short in flight
Setting up a read-only SQL user solves the first problem of database access. It decides who can log in and stops the agent from dropping tables. Yet native roles do not check what individual SQL statements do in flight. A user in the fixed data reader role sees every user table and view.
If a table holds customer emails, phone numbers, or card numbers, the query returns them. The database sends those raw fields straight into the agent context window. Also, a static login string sits on the developer laptop in plain text. Anyone who copies that file can log in from their own tool. Native SQL roles also treat every select query the same way. They cannot pause a huge table scan or rewrite national IDs in query results.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server, inline in the TDS wire protocol. On every batch an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Before a batch hits the server, hoop.dev guardrails refuse disallowed actions with a native TDS error or hold risky statements for approval. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns in memory, and every decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
How does Claude Code run queries against SQL Server?
Claude Code connects to databases through a Model Context Protocol server or its Bash tool. You give the MCP server a database login string so the agent can send queries.
Should I use a master login or a contained user for the agent?
Use a contained database user if the agent only needs one or a few databases. This keeps the password scoped to that database instead of the whole server instance.
Does the fixed data reader role hide sensitive columns from Claude Code?
No, members of the fixed data reader role can read all user tables and views. It does not block or mask emails, card numbers, or phone numbers in results.
Related guides
In this post