> ## Documentation Index
> Fetch the complete documentation index at: https://www.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CockroachDB MCP Server

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The CockroachDB MCP Server is a [Model Context Protocol (MCP)](https://modelcontextprotocol.io) 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 <InternalLink path="select-clause">`SELECT`</InternalLink> 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 <InternalLink path="install-cockroachdb-mcp-server">Install, Configure, and Connect to the CockroachDB MCP Server</InternalLink>. For the full list of configuration options, refer to the <InternalLink path="cockroachdb-mcp-server-reference">CockroachDB MCP Server Reference</InternalLink>.

For CockroachDB Cloud deployments, refer to <InternalLink version="cockroachcloud" path="connect-to-the-cockroachdb-cloud-mcp-server">Connect to the CockroachDB Cloud MCP Server</InternalLink>.

## Requirements

* An existing <InternalLink path="install-cockroachdb">CockroachDB cluster</InternalLink> with a <InternalLink path="create-user">SQL user</InternalLink> whose <InternalLink path="grant">privileges</InternalLink> 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](https://go.dev/dl/). 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](#tools) that AI agents invoke on your behalf. These tools trigger SQL queries against the connected cluster using a <InternalLink path="create-user">CockroachDB SQL user</InternalLink>.

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 <InternalLink path="cockroachdb-mcp-server-reference#crdb-mcp-enable-write-queries">`CRDB_MCP_ENABLE_WRITE_QUERIES`</InternalLink> 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 <InternalLink path="grant">`GRANT`</InternalLink>), 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 <InternalLink path="cockroachdb-mcp-server-reference">CockroachDB MCP Server Reference</InternalLink>.

The server registers the following read-only tools by default:

| Tool                                                                                                             | Description                                                                                                 |
| ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| <InternalLink path="cockroachdb-mcp-server-reference#list_databases">`list_databases`</InternalLink>             | List all databases in the cluster.                                                                          |
| <InternalLink path="cockroachdb-mcp-server-reference#list_tables">`list_tables`</InternalLink>                   | List all tables in a database.                                                                              |
| <InternalLink path="cockroachdb-mcp-server-reference#get_table_schema">`get_table_schema`</InternalLink>         | Get the schema for a table, including columns and indexes.                                                  |
| <InternalLink path="cockroachdb-mcp-server-reference#get_cluster">`get_cluster`</InternalLink>                   | Return cluster identity and version metadata.                                                               |
| <InternalLink path="cockroachdb-mcp-server-reference#list_sql_users">`list_sql_users`</InternalLink>             | List SQL users defined in the cluster.                                                                      |
| <InternalLink path="cockroachdb-mcp-server-reference#list_cluster_nodes">`list_cluster_nodes`</InternalLink>     | List cluster nodes with address, liveness, and locality.                                                    |
| <InternalLink path="cockroachdb-mcp-server-reference#show_running_queries">`show_running_queries`</InternalLink> | List in-flight SQL statements on the cluster.                                                               |
| <InternalLink path="cockroachdb-mcp-server-reference#select_query">`select_query`</InternalLink>                 | Execute a <InternalLink path="select-clause">`SELECT`</InternalLink> statement.                             |
| <InternalLink path="cockroachdb-mcp-server-reference#explain_query">`explain_query`</InternalLink>               | Return the <InternalLink path="explain">`EXPLAIN`</InternalLink> plan for a statement without executing it. |
| <InternalLink path="cockroachdb-mcp-server-reference#show_statement">`show_statement`</InternalLink>             | Execute a `SHOW` statement such as `SHOW SCHEMAS`, `SHOW INDEXES`, or `SHOW JOBS`.                          |

The following write tools are registered only when <InternalLink path="cockroachdb-mcp-server-reference#crdb-mcp-enable-write-queries">`CRDB_MCP_ENABLE_WRITE_QUERIES`</InternalLink>`=true` is set:

| Tool                                                                                                   | Description                                                                                              |
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| <InternalLink path="cockroachdb-mcp-server-reference#create_database">`create_database`</InternalLink> | Create a database.                                                                                       |
| <InternalLink path="cockroachdb-mcp-server-reference#create_table">`create_table`</InternalLink>       | Execute a <InternalLink path="create-table">`CREATE TABLE`</InternalLink> statement.                     |
| <InternalLink path="cockroachdb-mcp-server-reference#insert_rows">`insert_rows`</InternalLink>         | Execute an <InternalLink path="insert">`INSERT`</InternalLink> statement.                                |
| <InternalLink path="cockroachdb-mcp-server-reference#update_rows">`update_rows`</InternalLink>         | Execute an <InternalLink path="update">`UPDATE`</InternalLink> statement. A `WHERE` clause is mandatory. |
| <InternalLink path="cockroachdb-mcp-server-reference#delete_rows">`delete_rows`</InternalLink>         | Execute a <InternalLink path="delete">`DELETE`</InternalLink> statement. A `WHERE` clause is mandatory.  |

## 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:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
List all of the tables in the movr database.
```

They can also be complex and conversational, for example:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
I need to add a reviews table to the movr database so that riders can rate their rides.

For the schema, I'm thinking we need:
- Review ID (primary key)
- Rider reference (foreign key to movr.users)
- Ride reference (foreign key to movr.rides)
- A 1–5 star rating
- Optional text feedback
- Timestamp

Let's include a secondary index on the rating column.

Show me the CREATE TABLE statement so that we can talk it through before you actually create the table.
```

## See also

* <InternalLink path="install-cockroachdb-mcp-server">Install, Configure, and Connect to the CockroachDB MCP Server</InternalLink>
* <InternalLink path="cockroachdb-mcp-server-reference">CockroachDB MCP Server Reference</InternalLink>
* <InternalLink version="cockroachcloud" path="connect-to-the-cockroachdb-cloud-mcp-server">Connect to the CockroachDB Cloud MCP Server</InternalLink>
* <InternalLink path="cockroachdb-and-ai">CockroachDB and AI</InternalLink>
* <InternalLink path="agent-skills">Agent Skills for CockroachDB</InternalLink>
* <InternalLink path="docs-mcp-integration">Docs MCP Server</InternalLink>
