How to Configure Mastra SQL Server Approval

Published
Length
3 min read

Luis Felipe Dias

All posts

You configure mastra sql server approval by pausing agent workflows before database execution and restricting database user roles. First, your app stops the agent when it drafts a query, and then a human reviewer approves the run. Teams often connect agents using a single shared database login for speed. When that login holds broad permissions, one bad prompt can change or delete production tables. How mastra sql server approval works with native roles A database user is the identity of a log

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 configure mastra sql server approval by pausing agent workflows before database execution and restricting database user roles. First, your app stops the agent when it drafts a query, and then a human reviewer approves the run. Teams often connect agents using a single shared database login for speed. When that login holds broad permissions, one bad prompt can change or delete production tables.

How mastra sql server approval works with native roles

A database user is the identity of a login when it connects to a database. For access to many databases on an instance, a SQL user with a login in master is common. When an agent needs one or a few databases, a contained database user with a password works well. An admin must first enable contained databases on the server and the database. SQL Server supports thirteen types of database users for these setups.

After you create the user, you assign a fixed database role to limit what the agent can do. Members of the data reader role can read all data from all user tables and views. Members of the data writer role can add, delete, or change data in all user tables. If you assign the owner role, the agent can run all maintenance tasks and even drop the database. You cannot change the permissions assigned to fixed database roles.

Inside the agent framework, developers wrap database tools in a human review step. When the model wants to run a query, the workflow pauses and saves its state. A reviewer checks the pending action in the app interface and clicks approve or reject. Only after this approval does the tool send the statement to the database using the assigned user role.

What native setup solves and where it falls short

Combining workflow pauses with fixed database roles stops several basic risks. Using a deny data writer role ensures the agent cannot add, modify, or delete table rows. Using a deny data reader role stops the user from reading any user tables, views, or metadata. Every role, including the public role, still holds basic permission to connect to the database. These roles draw a hard boundary around the account at login time.

Approval Chains & Escalation + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database roles only decide who logs in, not what individual statements do in flight. A user in the data reader role can still read every table, including emails and card numbers. If an agent needs to update one table, the data writer role lets it change all user tables. Code-level approval steps also rely on developers to wrap every single database tool by hand. If a developer misses one tool path, the agent runs queries without a human check.

Why runtime query checks matter for agent workflows

Teams need a way to inspect each SQL statement right before the database runs it. Instead of trusting app code to pause every time, runtime controls check the actual query text. Read queries can run right away while masking rewrites matched fields like phone numbers or national IDs in results. Write or delete statements can trigger a review request based on the exact SQL command in flight. This separates login identity from per-query safety and keeps sensitive rows protected during 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

Can I edit the permissions of a fixed SQL Server role for my agent?

No, you cannot change the permissions assigned to fixed database roles in SQL Server. If the default reader or writer roles are too broad, you must create a custom role and grant table permissions.

Should an agent use a login in master or a contained database user?

Use a contained database user when the agent only needs one or a few databases. This keeps the user password tied to that specific database instead of the master database on the server.

Does the data reader role hide sensitive columns from AI agents?

No, members of the data reader role can read all data from all user tables and views. To protect sensitive fields like emails or card numbers, you need data masking or column-level controls.

The query runs. The emails stay hidden.