How to Configure OpenHands SQL Server MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up an openhands sql server mcp server, create a restricted database user first. Then link that account to the agent settings so the model can run queries. Many teams start by handing the agent a main admin login to move fast. That shortcut creates huge risks when an automated tool can edit or drop live tables. A safe setup uses strict database roles to limit what the agent can touch. How the openhands sql server mcp server architecture works In SQL Server, a database user is the identi

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 openhands sql server mcp server, create a restricted database user first. Then link that account to the agent settings so the model can run queries. Many teams start by handing the agent a main admin login to move fast. That shortcut creates huge risks when an automated tool can edit or drop live tables. A safe setup uses strict database roles to limit what the agent can touch.

How the openhands sql server mcp server architecture works

In SQL Server, a database user is the identity of a login inside a database. When an person or agent needs many databases, teams make a login in master. Then they map a SQL user to that login. If the agent only needs one database, a contained database user is a good choice. This user has a password and does not tie back to a login in master. An admin must turn on contained databases on the server and database first. Microsoft supports 13 types of database users for different needs.

Once the user exists, you must assign permissions through roles. Fixed database roles have preset rules that you cannot change. Every role, including the default public role, holds the basic permission to connect. If you assign the owner role, the agent can run any maintenance task. Worse, that owner role lets the agent drop the entire database. Instead, most teams use the fixed data reader role for AI coding tools. Members of this reader role can read all data from all user tables and views. If the agent must not change records, you can add the deny data writer role. That role stops the user from adding, changing, or deleting data in any table.

What native roles solve and what they leave open

Native SQL Server roles do a great job of controlling who can log in. They also draw hard lines between reading data and writing data at the table level. Pairing the data reader role with the deny data writer role blocks bad writes. The agent can inspect schemas and check rows without breaking your production tables. If you want to block all reads on a database, the deny data reader role helps. Members of that role cannot read data or metadata from user tables and views.

Still, native database roles have a big blind spot during live agent sessions. The fixed data reader role gives read access to every user table and view. You cannot edit the permissions of a fixed role to hide specific columns. Once the agent logs in, the database lets any valid read query run in flight. If a table holds emails, phone numbers, card numbers, or national IDs, the agent gets them. Native roles also do not pause a query to ask a human for approval. Plus, storing a database password in the agent settings leaves static keys on disk. Teams need a way to inspect queries and mask fields like card numbers in results.

Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Best practices for agent database permissions

Start by making a separate SQL user just for your AI agent. Never share a human engineer login with an automated tool. Keep the agent out of the owner role and the data writer role by default. If the agent only needs to read a few tables, skip the fixed reader role. Instead, grant select rights only on the exact views or tables required for the task. Use the deny data writer role as a safety net against accidental changes. Finally, review your server logs often to see which queries the agent runs.

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 runs beside the database as a sidecar for your SQL Server and checks TDS traffic without changing how clients log in.

With hoop.dev SQL Server controls, rules refuse banned statements before they run and can hold risky queries for human review. Matched sensitive values in supported result columns are masked before they reach the client. 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

What SQL Server role is safest for an OpenHands agent?

Start with a custom role that only reads specific views, or use the fixed data reader role paired with the deny data writer role to block all table changes.

Should I use a contained database user for the MCP server?

Yes, if the agent only needs one database, a contained user keeps the account isolated to that single database without needing a login in master.

Does the fixed data reader role hide sensitive columns like emails?

No, members of the fixed data reader role can read all data from all user tables and views, including emails, phone numbers, and card numbers.

The query runs. The emails stay hidden.