How to Configure Claude Code CockroachDB Read Only Access
You set up claude code cockroachdb read only access by pairing an MCP server with a restricted database role. First, create a user in CockroachDB that only has permission to read tables. Next, pass that user's connection string to the Model Context Protocol server in Claude Code. Many teams start by giving the agent a shared developer account to save time. That choice lets the AI tool alter rows, drop tables, or read private records by mistake. How claude code cockroachdb read only access work
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 set up claude code cockroachdb read only access by pairing an MCP server with a restricted database role. First, create a user in CockroachDB that only has permission to read tables. Next, pass that user's connection string to the Model Context Protocol server in Claude Code. Many teams start by giving the agent a shared developer account to save time. That choice lets the AI tool alter rows, drop tables, or read private records by mistake.
How claude code cockroachdb read only access works
Claude Code talks to outside systems and databases through Model Context Protocol servers. The vendor docs list database queries as a main use case for MCP servers. Since CockroachDB speaks the PostgreSQL wire protocol, standard database MCP servers work well here. The official docs show a PostgreSQL setup using the DBHub MCP server and a connection string. The docs advise using a read-only database user in that string so queries cannot change data.
Claude Code can also reach your database by running shell commands through its Bash tool. In Manual mode, the Bash tool asks for human approval before it runs most commands. Only a built-in list of safe local commands runs without a prompt. Database clients are not on that automatic list, so the user must approve each shell call. Still, using a dedicated MCP server with a read-only role is the cleaner path.
Inside CockroachDB, you build this setup by making a role that only holds select rights. You grant that role permission to read specific schemas and tables in your cluster. Then you assign the role to a new login user meant just for the coding agent. When Claude Code starts the MCP server, it logs in with those read-only credentials. CockroachDB checks every query from the agent and blocks any attempt to write or delete data.
What native read-only roles solve and what they miss
A read-only role in CockroachDB stops accidental writes, updates, and table drops right away. Even if a prompt tricks the agent into sending a delete command, the database rejects it. This setup protects data integrity when an engineer asks Claude Code to inspect a live schema. It also limits blast radius compared to sharing a full admin account with the local tool.
Still, database roles only decide who can log in and which tables they can read. They do not inspect what individual queries do in flight or what data comes back. A read-only user can still pull whole customer tables full of sensitive fields. When Claude Code runs a select query, raw emails, phone numbers, and card numbers return in plain text. Those values flow straight into the model context and out to the external AI provider.
Auditor Read-Only Access + Claude Code Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles also leave local secrets exposed on the engineer's laptop. The connection string for the MCP server sits in a local file on disk. Anyone or any script on that machine can read the password and use it directly. Also, when ten developers share one read-only agent user, database logs show one generic name. You cannot tell which person or which prompt ran an expensive query that slowed the cluster.
Why query-level controls matter for AI agents
AI coding agents generate queries fast and often explore tables without tight row limits. A valid select statement on a massive table can lock up memory and hurt production traffic. Database roles alone cannot pause a single risky select query for a quick human check. They also cannot rewrite matched fields in results to hide national IDs or card numbers.
To run AI tools against real data safely, teams need controls that work per query. Tying every agent action to a real human identity fixes the shared account problem in audit logs. Masking sensitive columns in flight keeps private customer records out of model prompts. Adding approval steps for broad reads stops runaway queries before they hit the cluster.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.
Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.
Frequently asked questions
How does Claude Code connect to a CockroachDB cluster?
Claude Code reaches databases through Model Context Protocol servers like DBHub or through its Bash tool. You give the MCP server a standard connection string that points to your CockroachDB host.
Does a read-only CockroachDB user stop data leaks to the AI model?
No, a read-only user only blocks data changes like inserts, updates, and deletes. The agent can still read sensitive columns like emails, phone numbers, and card numbers in query results.
Can Claude Code run database commands through the terminal without asking?
In Manual mode, the Bash tool requires user approval for commands outside a tiny built-in list. Database CLI tools need approval unless a user changes their mode or allowlist settings.
Related guides
In this post