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

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>;
};

This page lists the configuration options for the <InternalLink path="cockroachdb-mcp-server">MCP Server</InternalLink> that connects to self-hosted CockroachDB deployments. To set up the server, refer to <InternalLink path="install-cockroachdb-mcp-server">Install, Configure, and Connect to the CockroachDB MCP Server</InternalLink>.

## Configuration

All configuration is managed via environment variables. In stdio mode, set them in the `env` block of your MCP client configuration; in HTTP mode, export them in the server's environment.

### Authentication

Certificate-based authentication is recommended in stdio mode. The server runs as a subprocess of the AI agent host, which can read `CRDB_PWD`, a password embedded in `CRDB_DATABASE_URL`, `PGPASSWORD`, or `~/.pgpass` from the process's environment. To protect those credentials, password-based authentication is rejected by default; set [`CRDB_MCP_ALLOW_PASSWORD_AUTH`](#crdb-mcp-allow-password-auth)`=true` to opt in.

You can authenticate with individual variables (recommended) or with a full connection string. [`CRDB_DATABASE_URL`](#crdb-database-url) takes precedence when both are set.

| Variable                                        | Description                                                                                                                                                             | Required                                                                       | Default       |
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------- |
| <a id="crdb-host" />`CRDB_HOST`                 | Hostname. For a multi-node cluster, use a load balancer address; for development, any node's address.                                                                   | Yes                                                                            |               |
| <a id="crdb-port" />`CRDB_PORT`                 | Port.                                                                                                                                                                   | No                                                                             | `26257`       |
| <a id="crdb-username" />`CRDB_USERNAME`         | SQL user.                                                                                                                                                               | Yes                                                                            |               |
| <a id="crdb-pwd" />`CRDB_PWD`                   | Password. Requires [`CRDB_MCP_ALLOW_PASSWORD_AUTH`](#crdb-mcp-allow-password-auth)`=true`. Certificate-based authentication is recommended instead.                     | No                                                                             |               |
| <a id="crdb-ssl-mode" />`CRDB_SSL_MODE`         | `require`, `verify-ca`, or `verify-full`. TLS-optional modes (`disable`, `allow`, `prefer`) require [`CRDB_MCP_ALLOW_INSECURE_DB`](#crdb-mcp-allow-insecure-db)`=true`. | No                                                                             | `verify-full` |
| <a id="crdb-ssl-ca-path" />`CRDB_SSL_CA_PATH`   | CA certificate path.                                                                                                                                                    | When `CRDB_SSL_MODE` is `verify-ca` or `verify-full` (the default)             |               |
| <a id="crdb-ssl-certfile" />`CRDB_SSL_CERTFILE` | Client certificate path.                                                                                                                                                | When `CRDB_SSL_MODE` is `require`, `verify-ca`, or `verify-full` (the default) |               |
| <a id="crdb-ssl-keyfile" />`CRDB_SSL_KEYFILE`   | Client key path.                                                                                                                                                        | When `CRDB_SSL_MODE` is `require`, `verify-ca`, or `verify-full` (the default) |               |

Alternatively, use a full connection string:

| Variable                                        | Description                                                                                                                                                                                                                                      |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <a id="crdb-database-url" />`CRDB_DATABASE_URL` | A full libpq connection string (for example, `postgresql://user@host:26257/defaultdb?sslmode=verify-full&sslcert=...`). When set, the individual variables above are ignored. A `CRDB_DATABASE_URL` that omits `sslmode` is rejected at startup. |

### Query behavior

| Variable                                                                | Description                                                                                                                                                                                                                                                   | Required | Default      |
| ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------ |
| <a id="crdb-mcp-query-timeout" />`CRDB_MCP_QUERY_TIMEOUT`               | Per-query timeout, as a Go duration (for example, `30s`). The server cancels a query that exceeds it.                                                                                                                                                         | No       | `30s`        |
| <a id="crdb-mcp-max-rows-count" />`CRDB_MCP_MAX_ROWS_COUNT`             | Cap on the maximum `LIMIT` that list-style tools issue to CockroachDB.                                                                                                                                                                                        | No       | `10000`      |
| <a id="crdb-mcp-max-conns" />`CRDB_MCP_MAX_CONNS`                       | Upper bound on the connection pool size (up to 100).                                                                                                                                                                                                          | No       | `10`         |
| <a id="crdb-mcp-txn-qos" />`CRDB_MCP_TXN_QOS`                           | Default transaction quality of service: `background`, `regular`, or `critical`. Refer to the precedence notes below the table.                                                                                                                                | No       | `background` |
| <a id="crdb-mcp-enable-write-queries" />`CRDB_MCP_ENABLE_WRITE_QUERIES` | Enable the [write tools](#write-tools). For per-operation control, grant the connecting role only the SQL privileges you want, for example `SELECT`, `INSERT`, and `UPDATE` but not `DELETE` to allow writes without deletes.                                 | No       | `false`      |
| <a id="crdb-mcp-allow-password-auth" />`CRDB_MCP_ALLOW_PASSWORD_AUTH`   | Opt in to password-based authentication. The server refuses to start if a password is detected from any source ([`CRDB_PWD`](#crdb-pwd), a password in [`CRDB_DATABASE_URL`](#crdb-database-url), `PGPASSWORD`, or `~/.pgpass`) unless this is set to `true`. | No       | `false`      |
| <a id="crdb-mcp-allow-insecure-db" />`CRDB_MCP_ALLOW_INSECURE_DB`       | Opt in to the `sslmode` values that can run without TLS: `disable`, `allow`, `prefer`. Certificate variables are not required in these modes. Development only.                                                                                               | No       | `false`      |

MCP traffic runs at `default_transaction_quality_of_service=background` by default, so it does not contend with latency-sensitive foreground workloads. The value is chosen with the following precedence:

1. [`CRDB_MCP_TXN_QOS`](#crdb-mcp-txn-qos), if set (`background`, `regular`, or `critical`).
2. Otherwise, a `default_transaction_quality_of_service=...` query parameter in [`CRDB_DATABASE_URL`](#crdb-database-url), if present.
3. Otherwise, `background`.

### Transport

| Variable                                                              | Description                                                                                                                                                                                                                    | Required                                                                                                | Default |
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | ------- |
| <a id="crdb-mcp-transport" />`CRDB_MCP_TRANSPORT`                     | `stdio` or `http`.                                                                                                                                                                                                             | No                                                                                                      | `stdio` |
| <a id="crdb-mcp-http-listen-addr" />`CRDB_MCP_HTTP_LISTEN_ADDR`       | Listen address in HTTP mode, any `host:port`. Omit the host to bind all interfaces. Examples: `:8080`, `0.0.0.0:8443`, `127.0.0.1:9090`.                                                                                       | No                                                                                                      | `:8080` |
| <a id="crdb-mcp-bearer-token" />`CRDB_MCP_BEARER_TOKEN`               | Bearer token that clients must send in `Authorization: Bearer {token}`. Must be at least 16 characters.                                                                                                                        | Required for `http` mode, unless [`CRDB_MCP_ALLOW_NO_BEARER`](#crdb-mcp-allow-no-bearer)`=true`         |         |
| <a id="crdb-mcp-tls-cert" />`CRDB_MCP_TLS_CERT`                       | PEM-encoded server certificate path.                                                                                                                                                                                           | Required for `http` mode, unless [`CRDB_MCP_ALLOW_INSECURE_HTTP`](#crdb-mcp-allow-insecure-http)`=true` |         |
| <a id="crdb-mcp-tls-key" />`CRDB_MCP_TLS_KEY`                         | PEM-encoded private key path.                                                                                                                                                                                                  | Required for `http` mode, unless [`CRDB_MCP_ALLOW_INSECURE_HTTP`](#crdb-mcp-allow-insecure-http)`=true` |         |
| <a id="crdb-mcp-allow-insecure-http" />`CRDB_MCP_ALLOW_INSECURE_HTTP` | Opt in to cleartext HTTP (for reverse-proxy deployments).                                                                                                                                                                      | No                                                                                                      | `false` |
| <a id="crdb-mcp-allow-no-bearer" />`CRDB_MCP_ALLOW_NO_BEARER`         | Opt in to skipping bearer authentication (for upstream-auth deployments). A startup warning is logged. Mutually exclusive with [`CRDB_MCP_BEARER_TOKEN`](#crdb-mcp-bearer-token): the server refuses to start if both are set. | No                                                                                                      | `false` |

### Logging

| Variable                                          | Description                                                                        | Required | Default |
| ------------------------------------------------- | ---------------------------------------------------------------------------------- | -------- | ------- |
| <a id="crdb-mcp-log-level" />`CRDB_MCP_LOG_LEVEL` | `debug`, `info`, `warn`, or `error`.                                               | No       | `info`  |
| <a id="crdb-mcp-log-path" />`CRDB_MCP_LOG_PATH`   | Log file path, or `-` for stderr. No rotation; use logrotate or your orchestrator. | No       |         |

### Tracing (OpenTelemetry)

Tracing is opt-in. When neither of the following variables is set, no exporter is installed. When enabled, tool calls and their SQL statements are exported as spans, and server logs are exported as OpenTelemetry log records. Query text and errors are redacted before export, so literals and user data never leave the server.

| Variable                                                            | Description                                                                  | Required |
| ------------------------------------------------------------------- | ---------------------------------------------------------------------------- | -------- |
| <a id="otel-exporter-otlp-endpoint" />`OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP gRPC endpoint; the standard `OTEL_*` environment variables are honored. | No       |
| <a id="crdb-mcp-otel-file" />`CRDB_MCP_OTEL_FILE`                   | Write traces and logs as JSON lines to this file instead (takes precedence). | No       |

## Tools

The following sections list the tools that the MCP server makes available to agents.

You likely do not have to invoke these functions explicitly. Most AI tools should be able to decide which functions to call based on natural language prompts provided by the user.

### Read-only tools

The following tools are registered by default. They do not modify cluster data.

#### `list_databases`

List all databases in the cluster.

| Parameter | Description                                                                              | Type    | Required | Default |
| --------- | ---------------------------------------------------------------------------------------- | ------- | -------- | ------- |
| `limit`   | Maximum rows to return, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count). | integer | No       | `100`   |
| `offset`  | Rows to skip before returning results.                                                   | integer | No       | `0`     |

#### `list_tables`

List all tables in a database.

| Parameter  | Description                                                                              | Type    | Required | Default |
| ---------- | ---------------------------------------------------------------------------------------- | ------- | -------- | ------- |
| `database` | Database whose tables are listed.                                                        | string  | Yes      |         |
| `limit`    | Maximum rows to return, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count). | integer | No       | `100`   |
| `offset`   | Rows to skip before returning results.                                                   | integer | No       | `0`     |

#### `get_table_schema`

Get detailed schema information for a table, including columns and indexes. Returns the <InternalLink path="create-table">`CREATE TABLE`</InternalLink> statement.

| Parameter  | Description                    | Type   | Required | Default  |
| ---------- | ------------------------------ | ------ | -------- | -------- |
| `database` | Database containing the table. | string | Yes      |          |
| `table`    | Table name.                    | string | Yes      |          |
| `schema`   | Schema name.                   | string | No       | `public` |

#### `get_cluster`

Return cluster identity and version metadata: `cluster_id`, `cluster_name`, `binary_version`, `active_version`.

The identity fields (`cluster_id`, `cluster_name`, and `active_version`) require access to `crdb_internal` built-in functions, which are gated by default on CockroachDB v25.4 and later. When these fields cannot be accessed, they are returned as `null`, with the reason reported under an `unavailable` key. `binary_version` is always returned.

This tool takes no parameters.

#### `list_sql_users`

List SQL users defined in the cluster.

| Parameter | Description                                                                              | Type    | Required | Default |
| --------- | ---------------------------------------------------------------------------------------- | ------- | -------- | ------- |
| `limit`   | Maximum rows to return, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count). | integer | No       | `100`   |
| `offset`  | Rows to skip before returning results.                                                   | integer | No       | `0`     |

#### `list_cluster_nodes`

List cluster nodes with address, liveness, and locality. Requires `admin` or the `VIEWCLUSTERMETADATA` <InternalLink path="security-reference/authorization#supported-privileges">system privilege</InternalLink>.

This tool takes no parameters.

#### `show_running_queries`

List in-flight SQL statements on the cluster, ordered by start time descending. Viewing other users' statements requires `admin` or the `VIEWACTIVITY` or `VIEWACTIVITYREDACTED` <InternalLink path="security-reference/authorization#supported-privileges">system privilege</InternalLink>; otherwise, only the connecting user's own statements are returned.

| Parameter | Description                                                                              | Type    | Required | Default |
| --------- | ---------------------------------------------------------------------------------------- | ------- | -------- | ------- |
| `limit`   | Maximum rows to return, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count). | integer | No       | `100`   |
| `offset`  | Rows to skip before returning results.                                                   | integer | No       | `0`     |

#### `select_query`

Execute a single <InternalLink path="select-clause">`SELECT`</InternalLink> statement. Non-`SELECT` statements are rejected. A default `LIMIT` of `100` is appended when none is supplied, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count). An explicit `LIMIT` that exceeds [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count), or `LIMIT ALL`, is rejected.

| Parameter | Description                  | Type   | Required |
| --------- | ---------------------------- | ------ | -------- |
| `query`   | A single `SELECT` statement. | string | Yes      |

#### `explain_query`

Return the <InternalLink path="explain">`EXPLAIN`</InternalLink> plan for a single SQL statement without executing it. `EXPLAIN ANALYZE` (and `EXPLAIN ANALYZE (DEBUG)`) is rejected because it executes the statement. Display options (`VERBOSE`, `DISTSQL`, `TYPES`, `OPT`, and so on) pass through.

| Parameter | Description             | Type   | Required |
| --------- | ----------------------- | ------ | -------- |
| `query`   | A single SQL statement. | string | Yes      |

#### `show_statement`

Execute a single `SHOW` statement such as `SHOW SCHEMAS`, `SHOW INDEXES`, `SHOW REGIONS`, or `SHOW JOBS`. A default `LIMIT` is appended, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count).

| Parameter | Description                                                                              | Type    | Required | Default |
| --------- | ---------------------------------------------------------------------------------------- | ------- | -------- | ------- |
| `query`   | A single `SHOW` statement.                                                               | string  | Yes      |         |
| `limit`   | Maximum rows to return, capped at [`CRDB_MCP_MAX_ROWS_COUNT`](#crdb-mcp-max-rows-count). | integer | No       | `100`   |
| `offset`  | Rows to skip before returning results.                                                   | integer | No       | `0`     |

### Write tools

The following tools are registered only when [`CRDB_MCP_ENABLE_WRITE_QUERIES`](#crdb-mcp-enable-write-queries)`=true` is set. Any write tool that includes a `RETURNING` clause returns the affected rows instead of just the count.

#### `create_database`

Create a database.

| Parameter       | Description                                                           | Type    | Required | Default |
| --------------- | --------------------------------------------------------------------- | ------- | -------- | ------- |
| `name`          | Database name to create.                                              | string  | Yes      |         |
| `if_not_exists` | When `true`, the statement is a no-op if the database already exists. | boolean | No       | `false` |

#### `create_table`

Execute a single <InternalLink path="create-table">`CREATE TABLE`</InternalLink> statement.

| Parameter   | Description                                                                                                            | Type   | Required |
| ----------- | ---------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `statement` | A single `CREATE TABLE` statement. Qualify the table with a database when not using the connection's default database. | string | Yes      |

#### `insert_rows`

Execute a single <InternalLink path="insert">`INSERT`</InternalLink> statement. Returns the number of rows affected.

| Parameter   | Description                                                                                                                                                      | Type   | Required |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `statement` | A single `INSERT` statement. A `RETURNING` clause returns the inserted rows. Qualify the table with a database when not using the connection's default database. | string | Yes      |

#### `update_rows`

Execute a single <InternalLink path="update">`UPDATE`</InternalLink> statement. A `WHERE` clause is mandatory. Returns the number of rows affected.

| Parameter   | Description                                                                                                                                                                                    | Type   | Required |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `statement` | A single `UPDATE` statement. A `WHERE` clause is mandatory. A `RETURNING` clause returns the updated rows. Qualify the table with a database when not using the connection's default database. | string | Yes      |

#### `delete_rows`

Execute a single <InternalLink path="delete">`DELETE`</InternalLink> statement. A `WHERE` clause is mandatory. Returns the number of rows affected.

| Parameter   | Description                                                                                                                                                                                    | Type   | Required |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `statement` | A single `DELETE` statement. A `WHERE` clause is mandatory. A `RETURNING` clause returns the deleted rows. Qualify the table with a database when not using the connection's default database. | string | Yes      |

## See also

* <InternalLink path="cockroachdb-mcp-server">CockroachDB MCP Server</InternalLink>
* <InternalLink path="install-cockroachdb-mcp-server">Install, Configure, and Connect to the CockroachDB MCP Server</InternalLink>
* [CockroachDB MCP Server on GitHub](https://github.com/cockroachdb/cockroachdb-mcp-server)
