Openhands SQL Server MCP

Published
Length
3 min read

Luis Felipe Dias

All posts

An openhands sql server mcp setup links autonomous coding agents to relational databases. It lets AI agents inspect schemas and run queries through a standard protocol. Engineering teams use this setup to speed up debugging and data tasks. Still, giving an autonomous agent direct database credentials creates real security risks. Teams must pair database roles with query controls and data masking. How an openhands sql server mcp workflow operates OpenHands runs as an autonomous agent that wri

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.

An openhands sql server mcp setup links autonomous coding agents to relational databases. It lets AI agents inspect schemas and run queries through a standard protocol.

Engineering teams use this setup to speed up debugging and data tasks. Still, giving an autonomous agent direct database credentials creates real security risks. Teams must pair database roles with query controls and data masking.

How an openhands sql server mcp workflow operates

OpenHands runs as an autonomous agent that writes code and runs commands. The Model Context Protocol gives the agent a standard way to call tools. In this setup, the MCP server acts as a bridge to SQL Server.

The agent sends a structured request when it needs database context. The MCP server translates that request into a database query and runs it. Then the server sends the query results back to the agent workspace.

A database user is the identity of a login inside a database. For access to many databases on an instance, teams use a master login. For one or a few databases, a contained database user is an option. An admin must first enable contained databases on the server and database. SQL Server supports 13 types of database users for different access needs.

Security tradeoffs of static roles and credentials

Teams often start by placing a static connection string in the agent config. They rely on built-in database roles to limit what the agent can do. SQL Server provides fixed database roles with permissions that cannot be changed.

Members of the datareader role can read all data from all user tables. They can also read all user views across that database. Members of the datawriter role can add, delete, or change table data. By contrast, the owner role can run all maintenance tasks and drop databases.

Kubernetes API Server Access + SQL Query Filtering: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Admins can also apply deny roles to restrict a database user further. The denydatareader role blocks reading data or metadata from user tables and views. The denydatawriter role blocks adding, changing, or deleting any table data.

Yet static roles leave big gaps during an active agent session. A read-only role still lets an agent read every user table at once. If a table holds emails, phone numbers, card numbers, or national IDs, the query returns them. Data masking solves this by rewriting matched fields in query results.

Why query-level controls matter for AI agents

Static credentials also stay valid until an engineer rotates them by hand. If a log file leaks the password, anyone can use that database login. All roles, including the public role, have basic permission to connect.

AI agents can also write bad queries that lock up production tables. Database roles check table permissions, but they do not review query logic first. Teams need a control layer between the MCP server and the database.

This layer checks each query before it reaches the database engine. It can block destructive commands or pause a query for human approval. It also logs every statement with the identity of the user or agent. Finally, it rewrites sensitive fields like emails and card numbers in the output.

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 OpenHands talk to SQL Server through MCP?

OpenHands sends tool calls to a local or remote MCP server process. That server connects to SQL Server, runs the query, and returns the rows.

Is the SQL Server datareader role safe enough for an AI agent?

No, because that role can read all data from all user tables. Without data masking, query results will still include emails, phone numbers, and card numbers.

Should we use a master login or a contained database user?

Use a master login if the agent needs access to many databases. Use a contained user if it only needs one or a few databases.

The query runs. The emails stay hidden.