Claude on your database: how to limit what the agent can do
5 min read · Updated November 14, 2026
Claude Code and Claude Desktop use MCP servers to talk to databases. They do what the configured credential allows, no more, no less. The limit has to live outside the model.
How Claude connects to the database
In Claude Code, MCP servers can be added from the command line or declared in a project .mcp.json file. In Claude Desktop, they live in the app's config file. In both cases a PostgreSQL server usually receives the connection string with user and password.
That means the agent's limit is exactly the credential's limit. Prompt instructions such as "never delete data" help the model behave, but they are not a permission: a model can misread the request or look for another path when it meets a restriction.
Why "ask for confirmation first" is not enough
- Confirmation happens inside the chat, where any text, including data read from the database, can influence the model.
- The person confirming is the person who asked, with no second opinion.
- Nothing binds the confirmation to the exact command that will run.
- The credential still allows everything, confirmed or not.
Good practices, with or without a tool
- Use a database user only for agents, without DROP, TRUNCATE, or role management.
- Prefer a replica or staging. Production only with an approval control in place.
- Set statement_timeout so a heavy query cannot lock the database.
- Never put the connection string in a versioned file.
- Review what the agent ran: if the database does not record who asked, you do not have an audit.
Setting up Claude with GatekeeperID Agents
With Agents, Claude only receives the Connector's internal address and the personal token of whoever is using it:
{
"mcpServers": {
"gatekeeper-agents": {
"type": "http",
"url": "https://agents.yourcompany.internal/mcp",
"headers": { "Authorization": "Bearer <your-personal-token>" }
}
}
}The token carries the person's role. If they are an analyst, Claude queries. If the request goes past the limit, Claude is told approval is needed and can open the request with a justification. Typing "approved" in the chat releases nothing: approval happens in the panel, by another person, and is valid for that call once.
Use Claude on the database with a limit per person
See the blocked request, the approval, and the audit in a 20-minute demo.
Book a 20-minute demoQuestions about this guide
Does it work with Claude Code and Claude Desktop?
Yes. Both speak MCP. The Agents panel generates the ready-made JSON for Claude when the token is created.
Does Claude see the database password?
No. The password stays in the Connector, inside the company network. Claude only gets the personal token, which can be revoked at any time.
What if Claude tries another command to reach the same result?
The decision follows the SQL's effect, not the tool's name. Destructive commands, risky changes, and unknown commands go to approval wherever they come from.
More guides
How to connect Cursor to PostgreSQL safely
The usual way to connect Cursor to PostgreSQL puts the database password on a laptop. See the risks, what to do with PostgreSQL alone, and how to give each person a limit without handing out the password.
Human approval for AI agents: how to require approval before DELETE and DROP
Real human-in-the-loop is not the agent asking in the chat. See the six properties of an approval that protects the database and how to apply them to AI agents on PostgreSQL.
LGPD and AI agents on your database: what changes and how to control it
When an AI agent queries personal data in your PostgreSQL, Brazil's LGPD still applies. See the principles that matter most, the practical risks, and the controls that produce evidence.
