How to Configure Codex SQL Server MCP Server
You set up a codex sql server mcp server by linking an agent to SQL Server. You pair a scoped database user with the Model Context Protocol server process. Most engineering teams start by pasting a shared database string into their local agent settings. That fast path works at first, yet broad roles expose every table and allow edits. When an AI coding agent holds owner rights, one bad prompt can drop production tables. How a codex sql server mcp server works with database roles The Model Con
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 codex sql server mcp server by linking an agent to SQL Server. You pair a scoped database user with the Model Context Protocol server process. Most engineering teams start by pasting a shared database string into their local agent settings. That fast path works at first, yet broad roles expose every table and allow edits. When an AI coding agent holds owner rights, one bad prompt can drop production tables.
How a codex sql server mcp server works with database roles
The Model Context Protocol gives AI coding agents a standard way to query databases. The agent sends a tool request to the local MCP server process. That server reads a database string from its start settings and opens a SQL session. In SQL Server, a login in the master database maps to a database user. Database admins can also set up a contained database user with its own password. This contained user stays inside one database and does not need a master login. Admins must turn on the contained database setting on the server and database first. SQL Server supports thirteen different types of database users for various login needs.
Once the user exists, admins assign fixed database roles to control what queries can do. The standard read role lets the user read all data from every user table. It also lets the agent read every view inside that database. If a team picks the write role, the agent can add, change, or delete rows. The owner role is much worse because it allows full maintenance and dropping the database. Fixed database roles have locked permission sets that admins cannot change. Every role, including the default public role, grants the basic right to connect. To block writes, admins can combine the read role with the deny write role.
What native SQL roles solve and where gaps remain
Using a read-only database user stops an AI agent from changing or deleting table rows. It also prevents the agent from running maintenance tasks or dropping the database by mistake. This native role setup handles the basic question of who can log into SQL Server. Still, fixed database roles decide who logs in, not what individual statements do in flight.
A user in the standard read role can still read every user table and view. If a table holds customer emails, phone numbers, or card numbers, the query returns them. The MCP server passes those raw results straight back into the AI agent context window. Native roles also cannot inspect the text of a query before the database runs it. An agent can still run a massive join that locks up CPU and memory. Also, developers still keep static database passwords inside local config files on their laptops. When someone leaves the team, rotating those shared strings across every laptop takes hours. Admins can add a deny read role, yet that blocks all user tables and views. Teams need finer control over specific queries and sensitive columns like national IDs.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
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 master login or a contained user for an MCP server?
Use a contained database user when the agent only needs one or a few databases. Use a SQL user tied to a master login when it needs many databases.
Can I edit the fixed read role to hide one table from Codex?
No, SQL Server does not let admins change the permissions assigned to fixed database roles. The standard read role always grants read rights across all user tables and views.
How do I stop the MCP server user from changing data?
Place the database user in the fixed read role and add the deny write role. Never place an AI agent user inside the database owner role or data writer role.
Related guides
In this post