Skip to main content
The CockroachDB MCP Server is a Model Context Protocol (MCP) server that lets your AI coding tools and AI agents explore live schemas, run queries, and write data on a CockroachDB cluster. The server runs as a local subprocess or a shared HTTP service and exposes a set of typed tools that agents invoke on your behalf. Once connected, you can interact with your cluster using natural language prompts to perform operations such as listing tables, executing statements, and inserting rows. This page explains how the CockroachDB MCP Server works, and what functionality it enables. To learn how to set it up, refer to . For the full list of configuration options, refer to the . For CockroachDB Cloud deployments, refer to .

Requirements

  • An existing with a whose are suitable for the operations that you want your AI agents to perform.
  • Installing with go install or building from source requires Go 1.26 or later. Alternatively, you can install with pre-built binaries (for Linux and Windows), and a Docker image is also available.

How it works

The server registers a set of typed MCP tools that AI agents invoke on your behalf. These tools trigger SQL queries against the connected cluster using a . The server supports two transports:
  • stdio (default): Your AI tool launches the server as a local subprocess and communicates with it over standard input/output. Each user runs their own server instance, authenticated to the cluster with their own SQL credentials. This is the simplest deployment and the recommended starting point.
  • HTTP: The server runs as a long-lived process that multiple MCP clients connect to over HTTPS with a bearer token. This is best for shared or remote deployments.

Security

The server is configured with secure defaults and requires explicit opt-in to relax them.
  • Read-only by default. Unless you explicitly enable write tools with the environment variable, only read tools are registered, and every SQL session is additionally forced read-only with default_transaction_read_only=true. For per-operation control, grant the connecting SQL role only the privileges you want: for example, SELECT, INSERT, and UPDATE but not DELETE to allow writes without deletes.
  • SQL grants are the permission boundary. Security ultimately comes from what the connecting SQL user is allowed to do in CockroachDB (via ), not from which environment variables you set on the MCP server. The server configuration controls which tools are registered, but even with write tools enabled, the SQL user can only do what its grants allow. Least-privilege grants are also the containment for prompt injection: the server cannot distinguish a tool call you intended from one induced by malicious content that the agent has read.
  • Password authentication is rejected by default. In stdio mode the server runs as a subprocess of the AI agent host, which can read passwords from the process environment or ~/.pgpass. Certificate-based authentication is recommended; password-based authentication requires an explicit opt-in.
  • TLS by default, in both directions. Connections to the cluster require sslmode of require or stronger, and HTTP mode refuses to start without a TLS certificate and key. Running without TLS—for local development or behind a TLS-terminating reverse proxy—requires explicit opt-in.
  • Background quality of service. By default, queries run at default_transaction_quality_of_service=background, so agent traffic does not contend with latency-sensitive foreground workloads.

Tools

For the full tool specifications including parameters, refer to the . The server registers the following read-only tools by default: The following write tools are registered only when =true is set:

Example usage

Use natural language prompts to read from and write to the cluster. You likely do not have to invoke the preceding tools explicitly. Most AI tools should be able to decide which functions to call based on natural language prompts provided by the user. Prompts can be simple, for example:
They can also be complex and conversational, for example:

See also