How to Configure OpenAI Agents SDK SQL Server MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up an openai agents sdk sql server mcp server workflow, link your agent to the server process and assign a read-only database user. You pass the server command to the agent runtime and store the database credentials in the host. Teams often start by reusing a shared admin account to test queries fast. That broad account lets a confused model alter tables, drop data, or read sensitive rows across the whole database. How an openai agents sdk sql server mcp server setup works The agent fr

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 an openai agents sdk sql server mcp server workflow, link your agent to the server process and assign a read-only database user. You pass the server command to the agent runtime and store the database credentials in the host. Teams often start by reusing a shared admin account to test queries fast. That broad account lets a confused model alter tables, drop data, or read sensitive rows across the whole database.

How an openai agents sdk sql server mcp server setup works

The agent framework talks to external tools through the Model Context Protocol. In this setup, the agent runtime starts or connects to a local or remote server process. That server exposes database actions as structured tools that the model can call during a run. When a user asks a question, the model picks a tool and builds a SQL query.

The tool process then logs in to the database engine to run that query. In SQL Server, a database user is the identity of a login when it connects to a database. If the agent needs many databases on one instance, teams create a login in the master database first. If the agent only needs one database, an admin can enable contained databases on the server and database. Then the team can use a contained database user with its own password instead of a master login.

After creating the user, you must limit what tables and views the tool can touch. SQL Server includes fixed database roles whose assigned permissions cannot be changed. Adding the agent user to the data reader role lets it read all data from all user tables and views. You can also add the deny data writer role so the user cannot add, modify, or delete data. Avoid the database owner role, because it allows full maintenance and can even drop the database.

What native database roles solve and what they miss

Native logins and fixed roles decide which process can log in to the database. They also set coarse boundaries on whether that user can read or write tables. Putting the tool user in a read-only role stops the agent from deleting rows or dropping tables. This is a strong first step for any automated workflow that runs model-generated SQL.

Still, fixed roles apply to the whole database at connection time, not to each query in flight. A user in the fixed reader role can still read every user table and view in that database. If a table holds emails, phone numbers, card numbers, or national IDs, a query returns them in plain text. Those values then flow straight into the model context and appear in agent answers.

Kubernetes API Server Access + OpenAI API Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native roles also cannot pause a single risky statement for human review before it runs. If an agent needs write permissions for one task, the fixed writer role lets it change any user table. The database engine checks who logged in at the start of the session. It does not inspect what each agent prompt or tool call is trying to do.

Practical steps to tighten agent database access

Start by creating a dedicated database user just for the agent tool server. Never share human admin credentials or broad app accounts with an automated model workflow. If the agent only reads from a few tables, grant select rights on specific views instead of the whole database. Use the deny data writer role to block unwanted changes at the database level.

Next, keep raw database passwords out of agent prompts and code files. Store connection secrets in the host where the tool server runs, and rotate them often. Watch your database logs to see which queries the agent runs and how many rows it pulls. When agents touch production data, pair native roles with statement-level checks and field masking for emails or card numbers.

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 is an open-source proxy that sits next to SQL Server as a sidecar for your SQL Server. It inspects TDS batches and parameterized queries in real time.

With hoop.dev guardrails and hoop.dev data masking, banned statements are refused with your message. Matched sensitive fields in supported result columns are masked in memory, and each decision is logged per listener. Check out the code on GitHub.

Frequently asked questions

Should I give the agent a login in master or a contained user?

Use a contained database user if the agent only queries one database and contained databases are enabled. Use a SQL user tied to a login in master when the agent must query many databases on the instance.

Does the fixed data reader role hide sensitive columns from the agent?

No, members of the fixed data reader role can read all data from all user tables and views. To hide emails, phone numbers, or card numbers, you need restricted views or a layer that rewrites matched fields in results.

Why is the database owner role dangerous for an AI agent?

The database owner role can run all setup and maintenance tasks and can even drop the database. An agent with this role could destroy data if a prompt goes wrong or a user tricks the model.

The query runs. The emails stay hidden.