How to Configure Claude Code CockroachDB MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a claude code cockroachdb mcp server by connecting an MCP tool. You pass a database string that uses a read-only user to block data changes. Teams often start by reusing a developer account from their local machine. That quick choice gives the AI agent broad rights to change or drop tables. A safer path starts with strict database roles and clear local rules. How a claude code cockroachdb mcp server works Claude Code reaches outside tools and databases through the Model Context Pro

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 a claude code cockroachdb mcp server by connecting an MCP tool. You pass a database string that uses a read-only user to block data changes. Teams often start by reusing a developer account from their local machine. That quick choice gives the AI agent broad rights to change or drop tables. A safer path starts with strict database roles and clear local rules.

How a claude code cockroachdb mcp server works

Claude Code reaches outside tools and databases through the Model Context Protocol. The vendor docs note that MCP servers link the agent to your data sources. They list querying databases as a main use case for these tools. The official PostgreSQL example uses the DBHub MCP server with a database string. Because CockroachDB speaks the PostgreSQL wire protocol, this same flow applies here.

First, you create a dedicated user inside your CockroachDB cluster. The Claude Code docs tell you to use a read-only database user. This step ensures the queries the agent runs cannot modify your data. Next, you register the MCP server in your local agent settings. You supply the database string so the server can log in to CockroachDB. The docs also warn you to check that you trust each MCP server. Once linked, the agent sends SQL queries through the MCP server to inspect schemas.

Claude Code can also run shell commands through its built-in Bash tool. In Manual mode, the Bash tool asks for your approval before running commands. Only a small set of safe read-only commands run without a prompt. Keeping database traffic inside a dedicated MCP tool avoids raw shell database calls.

What native database roles solve and what they leave open

A read-only CockroachDB role stops the agent from running write or delete statements. It also limits which schemas and tables the MCP server can read. This native setup solves the basic problem of accidental data loss during coding. It sets a clear boundary at the start of every database session.

Still, database roles only decide who can log in and which tables open. They do not inspect what individual queries do while a session is active. A read-only user with table rights can still pull thousands of customer rows. If those rows hold emails, phone numbers, or card numbers, the agent gets them. The database sends that raw text straight into the model context window.

Claude Code Security + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Local MCP setups also place static database strings on each developer laptop. If an engineer leaves or a key leaks, you must rotate secrets everywhere. Native roles also lack a unified log that ties prompts to exact SQL statements. To close these gaps, teams need controls that act on each query in flight. Field masking can rewrite emails, card numbers, and national IDs in query results. Statement rules and human approvals can pause risky queries before they run.

Best practices for agent database sessions

Start by creating a separate CockroachDB role just for your AI coding agent. Grant select rights only on the non-sensitive tables the task requires. Never reuse an admin role or a personal developer login in an MCP string. Keep Manual mode active in Claude Code so shell actions require your sign-off. Review the MCP server source code to confirm you trust it before use. Finally, pair read-only roles with query-level masking when tables contain personal 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 talk to a CockroachDB cluster?

Claude Code connects to databases through Model Context Protocol servers or its Bash tool. You register a compatible MCP server and give it a CockroachDB database string.

Why should I use a read-only user for the MCP server?

The official Claude Code docs advise using a read-only user in the database string. This prevents the queries the agent runs from changing or deleting your data.

Does a read-only CockroachDB role hide sensitive fields from the AI?

No, a read-only role still returns full rows from any permitted table. You need field masking in flight to rewrite emails, phone numbers, or card numbers.

The query runs. The emails stay hidden.