How to Configure Claude Code CockroachDB Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code cockroachdb credentials by giving a read-only connection string to a Model Context Protocol server. You can also let the agent run database tools through its local Bash tool. Many engineering teams start by pasting their personal admin database strings into local files. When database roles are too broad, a bad query can alter or delete production rows. How claude code cockroachdb credentials work in practice Claude Code talks to outside databases and APIs through Model

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 credentials by giving a read-only connection string to a Model Context Protocol server. You can also let the agent run database tools through its local Bash tool. Many engineering teams start by pasting their personal admin database strings into local files. When database roles are too broad, a bad query can alter or delete production rows.

How claude code cockroachdb credentials work in practice

Claude Code talks to outside databases and APIs through Model Context Protocol servers. These MCP servers act as local bridges between the coding agent and your data. Because CockroachDB speaks the PostgreSQL wire protocol, standard PostgreSQL MCP servers work well here. Official vendor docs show the DBHub MCP server as a common way to query databases. You give the MCP server a database connection string so it can run queries.

The vendor docs advise using a read-only database user inside that connection string. This step ensures the queries the agent runs cannot change or delete your data. Before you add any MCP server, you must verify that you trust the server code. You also need to create a dedicated role inside your CockroachDB cluster first. Grant this role select permissions only on the specific tables the agent needs to read.

Claude Code can also reach your database by running commands through its Bash tool. In Manual mode, the Bash tool asks for human approval before running most shell commands. Only a small built-in list of safe read-only file and git commands skips this prompt. Database command line tools do not skip the prompt, so you must check each command. Even with manual prompts, storing static keys on developer laptops creates a real security risk.

What native database roles solve and what stays exposed

A read-only CockroachDB user stops the agent from running write, update, or drop statements. Manual Bash approval gives developers a chance to stop bad shell commands before they run. Together, these native controls decide which database user logs in and which tables it reads. They form a solid first step for teams testing AI coding agents on test data.

Claude Code Security + Ephemeral Credentials: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database roles only check who logs in at the start of a session. They do not inspect what individual queries do while the connection is active. A read-only user can still pull thousands of customer emails, phone numbers, or card numbers. Once the database sends those rows back, the raw values enter the model context window. If a developer stores the connection string on disk, any local process can read it. Teams also lack a central log that ties each SQL query to a specific person. Native roles cannot rewrite sensitive fields in results or expire keys after one task.

Steps to tighten local agent database setups

Start by removing shared admin connection strings from developer laptops and project config files. Create a separate CockroachDB role that only has select access to safe tables. Never grant this role access to tables that hold raw passwords or secret tokens. Keep Claude Code in Manual mode so the Bash tool asks before running database scripts. Review every MCP server package before you connect it to your cluster. Rotate the database password often so old local config files cannot keep reading your data.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How does Claude Code connect to a CockroachDB cluster?

It connects through a Model Context Protocol server like DBHub or through its Bash tool. Both methods use a standard connection string to reach the cluster and run queries.

What database permissions should I give the coding agent?

Official docs recommend using a read-only database user in your MCP server connection string. This prevents the coding agent from changing rows or dropping tables when it runs queries.

Why is a read-only database role not enough for production data?

A read-only role still lets queries return raw emails, phone numbers, and card numbers. It also leaves static passwords on local machines and does not mask sensitive result fields.

The query runs. The emails stay hidden.