Claude Code Microsoft SQL Server MCP
A claude code microsoft sql server mcp setup links your coding agent to your database. It uses the Model Context Protocol so the agent can run queries and read tables. Claude Code reaches outside tools and databases through Model Context Protocol servers. It can also run local shell commands through its built-in Bash tool. In manual mode, the Bash tool asks for approval before it runs most commands. Only a small built-in set of read-only commands runs without a prompt. When teams link a databas
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.
A claude code microsoft sql server mcp setup links your coding agent to your database. It uses the Model Context Protocol so the agent can run queries and read tables.
Claude Code reaches outside tools and databases through Model Context Protocol servers. It can also run local shell commands through its built-in Bash tool. In manual mode, the Bash tool asks for approval before it runs most commands. Only a small built-in set of read-only commands runs without a prompt. When teams link a database through an MCP server, they supply a connection string. The official docs advise using a read-only database user in that string. That step stops the agent from changing or deleting your data.
How a claude code microsoft sql server mcp setup works
In this setup, the MCP server sits between the agent and SQL Server. The agent sends a tool request when it needs schema details or row data. The MCP server translates that request into a SQL query and runs it. Then the server sends the query results back to the agent context window.
On the SQL Server side, the connection string logs in as a specific user. A database user is the identity of a login inside a database. When a person or tool needs many databases, admins create a login in master. When a tool needs one or a few databases, admins have another choice. They can set up a contained database user with its own password. That contained user stays inside the target database and does not need a master login. An admin must enable contained databases on the server and the database first. SQL Server supports thirteen types of database users for different access needs.
Security tradeoffs of static roles and credentials
Official agent docs tell teams to use a read-only user in the connection string. In SQL Server, admins often assign fixed database roles to control what a user does. Fixed database roles have set rules that admins cannot change. Every role, including the public role, includes basic permission to connect. A user in the datareader role can read all data from all user tables. That role also reads all user views across the database. Admins can also assign a deny datareader role to block all table and view reads. A user in the datawriter role can add, change, or delete table data. A deny datawriter role blocks all writes, updates, and deletes in user tables. At the top level, the owner role can run all maintenance tasks and drop databases.
Claude Code Security + Microsoft Entra ID (Azure AD): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Giving the agent a datareader user blocks accidental writes and table drops. Still, static roles and local connection strings leave big gaps during an active session. First, the datareader role can read every user table and view in that database. If a table holds emails, phone numbers, card numbers, or national IDs, the query reads them. Those raw values flow straight into the model prompt and remain in agent logs. Second, a connection string stored on a laptop gives standing access to the database. Anyone who finds that key can use it outside the coding agent. Third, database role assignments do not inspect individual queries before they run. The database cannot pause a risky query to ask a human reviewer for approval. Teams need query-level controls and data masking to fill these security gaps. Data masking rewrites matched fields like emails and card numbers in query results.
Practical steps before you link an agent to SQL Server
Start by checking the MCP server code before you connect it to your database. The official Claude Code docs warn users to trust each server before connecting. Next, create a dedicated SQL Server user just for the coding agent. Do not reuse an admin login or an app service account. Put that user in the read-only role and add the deny datawriter role. Finally, add a policy layer that logs queries and rewrites sensitive fields in results.
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 query a SQL Server database?
Claude Code connects to databases through an MCP server configured with a connection string. It can also run command-line database tools through its local Bash tool with user approval.
What SQL Server role should an AI coding agent use?
Assign the fixed datareader role and the deny datawriter role to the agent user. This setup lets the agent read user tables while blocking all data changes.
Does a read-only SQL Server role hide sensitive columns from the agent?
No, the fixed datareader role lets the user read all data in all user tables. To hide emails, phone numbers, or card numbers, you need data masking in front of the database.
Related guides
In this post