The CockroachDB MCP Server is a natural language interface designed for LLMs and agentic applications to manage, monitor, and query data in CockroachDB. It integrates seamlessly with MCP (Model Content Protocol) clients, such as Claude Desktop or Cursor, enabling AI-driven workflows to interact directly with your database. - Cluster Monitoring - Database Operations - Table Management - Query Engin
Add this skill
npx mdskills install amineelkouhen/mcp-cockroachdbComprehensive CockroachDB interface with well-organized tools and excellent setup documentation
1# CockroachDB MCP Server2[](https://opensource.org/licenses/MIT)3[](https://www.python.org/downloads/)4[](https://mcp.so/server/cockroachdb-mcp-server/cockroachdb)5[](https://archestra.ai/mcp-catalog/amineelkouhen__mcp-cockroachdb)67## Overview89The CockroachDB MCP Server is a **natural language interface** designed for LLMs and agentic applications to manage, monitor, and query data in CockroachDB. It integrates seamlessly with **MCP (Model Content Protocol)** clients, such as Claude Desktop or Cursor, enabling AI-driven workflows to interact directly with your database.1011## Table of Contents12- [Overview](#overview)13- [Features](#features)14- [Tools](#tools)15 - [Cluster Monitoring](#cluster-monitoring)16 - [Database Operations](#database-operations)17 - [Table Management](#table-management)18 - [Query Engine](#query-engine)19- [Installation](#installation)20 - [Quick Start with uvx](#quick-start-with-uvx)21 - [Development Installation](#development-installation)22 - [With Docker](#with-docker)23- [Configuration](#configuration)24 - [Configuration via command line arguments](#configuration-via-command-line-arguments)25 - [Configuration via Environment Variables](#configuration-via-environment-variables)26- [Integrations](#integrations)27 - [OpenAI Agents SDK](#openai-agents-sdk)28 - [Augment](#augment)29 - [Claude Desktop](#claude-desktop)30 - [VS Code with GitHub Copilot](#vs-code-with-github-copilot)31 - [Cursor](#cursor)32- [Testing](#testing)33- [Contributing](#contributing)34- [License](#license)35- [Quality Badge](#quality-badge)36- [Contact](#contact)3738## Features39- **Natural Language Queries**: Enables AI agents to query and create transactions using natural language, supporting complex workflows.40- **Search & Filtering**: Supports efficient data retrieval and searching in CockroachDB.41- **Cluster Monitoring**: Check and monitor the CockroachDB cluster status, including node health and replication.42- **Database Operations**: Perform all operations related to databases, such as creation, deletion, and configuration.43- **Table Management**: Handle tables, indexes, and schemas for flexible data modeling.44- **Seamless MCP Integration**: Works with any **MCP client** for smooth communication.45- **Scalable & Lightweight**: Designed for **high-performance** data operations.4647## Tools4849The CockroachDB MCP Server Server provides tools to manage the data stored in CockroachDB.50515253The tools are organized into four main categories:5455### Cluster Monitoring5657Purpose:58Provides tools for monitoring and managing CockroachDB clusters.5960Summary:61- Get cluster health and node status.62- Show currently running queries.63- Analyze query performance statistics.64- Retrieve replication and distribution status for tables or the whole database.65- Get query execution insights with optional keyword filtering.66- Find slow queries from statement statistics with optional keyword filtering.67- Get transaction execution insights with optional keyword filtering.68- View contention events with optional table filtering.69- Get index recommendations from query insights.7071### Database Operations7273Purpose:74Handles database-level operations and connection management.7576Summary:77- Connect to a CockroachDB database.78- List, create, drop, and switch databases.79- Get connection status and active sessions.80- Retrieve database settings.8182### Table Management8384Purpose:85Provides tools for managing tables, indexes, views, and schema relationships in CockroachDB.8687Summary:88- Create, drop, and describe tables and views.89- Bulk import data into tables.90- Manage indexes (create/drop).91- List tables, views, and table relationships.92- Analyze schema structure and metadata.9394### Query Engine9596Purpose:97Executes and manages SQL queries and transactions.9899Summary:100- Execute SQL queries with formatting options (JSON, CSV, table).101- Run multi-statement transactions.102- Explain query plans for optimization.103- Track and retrieve query history.104105## Installation106107The CockroachDB MCP Server supports the `stdio` [transport](https://modelcontextprotocol.io/docs/concepts/transports#standard-input%2Foutput-stdio) and the `streamable-http` transport.108109### Quick Start with uvx110111The easiest way to use the CockroachDB MCP Server is with `uvx`, which allows you to run it directly from GitHub (from a branch, or use a tagged release). It is recommended to use a tagged release. The `main` branch is under active development and may contain breaking changes. As an example, you can execute the following command to run the `0.1.0` release:112113```commandline114uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git@0.1.0 cockroachdb-mcp-server --url postgresql://localhost:26257/defaultdb115```116117Check the release notes for the latest version in the [Releases](https://github.com/amineelkouhen/mcp-cockroachdb/releases) section.118Additional examples are provided below.119120```sh121# Run with CockroachDB URI122uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --url postgresql://localhost:26257/defaultdb123124# Run with individual parameters125uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --host localhost --port 26257 --database defaultdb --user root --password mypassword126127# See all options128uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --help129130# Run with streamable HTTP transport131uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \132 --url postgresql://localhost:26257/defaultdb \133 --transport http \134 --http-host 0.0.0.0 \135 --http-port 8000 \136 --http-path /mcp137```138139### Development Installation140141For development or if you prefer to clone the repository:142143```sh144# Clone the repository145git clone https://github.com/amineelkouhen/mcp-cockroachdb.git146cd mcp-cockroachdb147148# Install dependencies using uv149uv venv150source .venv/bin/activate151uv sync152153# Run with CLI interface154uv run cockroachdb-mcp-server --help155156# Or run the main file directly (uses environment variables)157uv run src/main.py158```159160Once you cloned the repository, installed the dependencies and verified you can run the server, you can configure Claude Desktop or any other MCP Client to use this MCP Server running the main file directly (it uses environment variables). This is usually preferred for development.161The following example is for Claude Desktop, but the same applies to any other MCP Client.1621631. Specify your CockroachDB credentials and TLS configuration1642. Retrieve your `uv` command full path (e.g. `which uv`)1653. Edit the `claude_desktop_config.json` configuration file166 - on a MacOS, at `~/Library/Application Support/Claude/`167168```json169{170 "mcpServers": {171 "cockroach": {172 "command": "<full_path_uv_command>",173 "args": [174 "--directory",175 "<your_mcp_server_directory>",176 "run",177 "src/main.py"178 ],179 "env": {180 "CRDB_HOST": "<your_cockroachdb_hostname>",181 "CRDB_PORT": "<your_cockroachdb_port>",182 "CRDB_DATABASE": "<your_cockroach_database>",183 "CRDB_USERNAME": "<your_cockroachdb_user>",184 "CRDB_PWD": "<your_cockroachdb_password>",185 "CRDB_SSL_MODE": "disable|allow|prefer|require|verify-ca|verify-full",186 "CRDB_SSL_CA_PATH": "<your_cockroachdb_ca_path>",187 "CRDB_SSL_KEYFILE": "<your_cockroachdb_keyfile_path>",188 "CRDB_SSL_CERTFILE": "<your_cockroachdb_certificate_path>",189 }190 }191 }192}193```194195You can troubleshoot problems by tailing the log file.196197```commandline198tail -f ~/Library/Logs/Claude/mcp-server-cockroach.log199```200201### With Docker Compose (Local Development)202203For local development and testing, use the provided `docker-compose.yaml` to spin up both CockroachDB and the MCP server:204205```bash206# Start CockroachDB and MCP server207docker compose up -d208209# The MCP server is available at http://localhost:8000/mcp/210# CockroachDB UI is available at http://localhost:8080211212# View logs213docker compose logs -f mcp-server214215# Stop and clean up216docker compose down -v217```218219### With Docker220221You can use a dockerized deployment of this server. You can either build your image or use the official [CockroachDB MCP Docker](https://hub.docker.com/r/mcp/cockroachdb) image.222223If you'd like to build your image, the CockroachDB MCP Server provides a Dockerfile. Build this server's image with:224225```commandline226docker build -t mcp-cockroachdb .227```228229Finally, configure the client to create the container at start-up. An example for Claude Desktop is provided below. Edit the `claude_desktop_config.json` and add:230231```json232{233 "mcpServers": {234 "cockroach": {235 "command": "docker",236 "args": ["run",237 "--rm",238 "--name",239 "cockroachdb-mcp-server",240 "-e", "CRDB_HOST=<cockroachdb_host>",241 "-e", "CRDB_PORT=<cockroachdb_port>",242 "-e", "CRDB_DATABASE=<cockroachdb_database>",243 "-e", "CRDB_USERNAME=<cockroachdb_user>",244 "mcp-cockroachdb"]245 }246 }247}248```249250To use the [CockroachDB MCP Docker](https://hub.docker.com/mcp/server/cockroachdb) image, just replace your image name (`mcp-cockroachdb` in the example above) with `mcp/cockroachdb`.251252## Configuration253254The CockroachDB MCP Server can be configured in two ways: either via command-line arguments or via environment variables.255The precedence is: CLI arguments > environment variables > default values.256257### Configuration via command line arguments258259When using the CLI interface, you can configure the server with command line arguments:260261```sh262# Basic CockroachDB connection263uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \264 --host localhost \265 --port 26257 \266 --db defaultdb \267 --user root \268 --password mypassword269270# Using CockroachDB URI (simpler)271uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \272 --url postgresql://root@localhost:26257/defaultdb273274# SSL connection275uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \276 --url postgresql://user:pass@cockroach.example.com:26257/defaultdb?sslmode=verify-full&sslrootcert=path/to/ca.crt&sslcert=path/to/client.username.crt&sslkey=path/to/client.username.key277278# See all available options279uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --help280```281282**Available CLI Options:**283- `--url` - CockroachDB connection URI (postgresql://user:pass@host:port/db)284- `--host` - CockroachDB hostname285- `--port` - CockroachDB port (default: 26257)286- `--db` - CockroachDB database name (default: defaultdb)287- `--user` - CockroachDB username288- `--password` - CockroachDB password289- `--ssl-mode` - SSL mode - Possible values: require, verify-ca, verify-full, disable (default)290- `--ssl-key` - Path to SSL Client key file291- `--ssl-cert` - Path to SSL Client certificate file292- `--ssl-ca-cert` - Path to CA (Root) certificate file'293- `--transport` - MCP transport to use (`stdio` or `http`)294- `--http-host` - HTTP host to bind for streamable HTTP transport295- `--http-port` - HTTP port to bind for streamable HTTP transport296- `--http-path` - HTTP path for streamable HTTP transport (e.g., /mcp)297- `--stateless-http` - Enable stateless HTTP mode for horizontal scaling298- `--use-env` - Use environment variables for CockroachDB configuration299300### Configuration via Environment Variables301302If desired, you can use environment variables. Defaults are provided for all variables.303304| Name | Description | Default Value |305|----------------------|--------------------------------------------------------------------------------|------------------|306| `CRDB_HOST` | The host name or address of a CockroachDB node or load balancer. | 127.0.0.1 |307| `CRDB_PORT` | The port number of the SQL interface of the CockroachDB node or load balancer. | 26257 |308| `CRDB_DATABASE` | A database name to use as the current database. | defaultdb |309| `CRDB_USERNAME` | The SQL user that will own the client session. | root |310| `CRDB_PWD` | The user's password. | None |311| `CRDB_SSL_MODE` | Which type of secure connection to use. | disable |312| `CRDB_SSL_CA_PATH` | Path to the CA certificate, when sslmode is not `disable`. | None |313| `CRDB_SSL_CERTFILE` | Path to the client certificate, when sslmode is not `disable`. | None |314| `CRDB_SSL_KEYFILE` | Path to the client private key, when sslmode is not `disable`. | None |315316There are several ways to set environment variables:3173181. **Using a `.env` File**:319Place a `.env` file in your project directory with key-value pairs for each environment variable. Tools like `python-dotenv`, `pipenv`, and `uv` can automatically load these variables when running your application. This is a convenient and secure way to manage configuration, as it keeps sensitive data out of your shell history and version control (if `.env` is in `.gitignore`).320For example, create a `.env` file with the following content from the `.env.example` file provided in the repository:321322```bash323cp .env.example .env324```325326Then edit the `.env` file to set your CockroachDB configuration:327328OR,3293302. **Setting Variables in the Shell**:331You can export environment variables directly in your shell before running your application. For example:332333```sh334export CRDB_URL= postgresql://root@127.0.0.1:26257/defaultdb335```336337This method is helpful for temporary overrides or quick testing.338339## Integrations340341Integrating this MCP Server with development frameworks like OpenAI Agents SDK or using tools like Claude Desktop, VS Code, or Augment is described in the following sections.342343### OpenAI Agents SDK344345Integrate this MCP Server with the OpenAI Agents SDK. Read the [documents](https://openai.github.io/openai-agents-python/mcp/) to learn more about the integration of the SDK with MCP.346347Install the Python SDK.348349```commandline350pip install openai-agents351```352353Configure the OpenAI token:354355```commandline356export OPENAI_API_KEY="<openai_token>"357```358359And run the [application](./examples/cockroachdb_assistant.py).360361```commandline362python3 examples/cockroachdb_assistant.py363```364365You can troubleshoot your agent workflows using the [OpenAI dashboard](https://platform.openai.com/traces/).366367### Augment368369You can configure the CockroachDB MCP Server in Augment by importing the server via JSON:370371```json372{373 "mcpServers": {374 "CockroachDB MCP Server": {375 "command": "uvx",376 "args": [377 "--from",378 "git+https://github.com/cockroachdb/mcp-cockroachdb.git",379 "cockroachdb-mcp-server",380 "--url",381 "postgresql://root@localhost:26257/defaultdb"382 ]383 }384 }385}386```387388### Claude Desktop389390The simplest way to configure MCP clients is using `uvx`. Add the following JSON to your `claude_desktop_config.json`, remember to provide the full path to `uvx`.391392```json393{394 "mcpServers": {395 "cockroach-mcp-server": {396 "type": "stdio",397 "command": "/opt/homebrew/bin/uvx",398 "args": [399 "--from", "git+https://github.com/amineelkouhen/mcp-cockroachdb.git",400 "cockroachdb-mcp-server",401 "--url", "postgresql://localhost:26257/defaultdb"402 ]403 }404 }405}406```407408Please follow the prompt and give the details to configure the server and connect to CockroachDB (e.g., using a managed CockroachDB instance).409The procedure will create the proper configuration in the `claude_desktop_config.json` configuration file.410411### VS Code with GitHub Copilot412413To use the CockroachDB MCP Server with VS Code, you must enable the [agent mode](https://code.visualstudio.com/docs/copilot/chat/chat-agent-mode) tools. Add the following to your `settings.json`:414415```json416{417 "chat.agent.enabled": true418}419```420421You can start the GitHub desired version of the CockroachDB MCP server using `uvx` by adding the following JSON to your `settings.json`:422423```json424"mcp": {425 "servers": {426 "CockroachDB MCP Server": {427 "type": "stdio",428 "command": "uvx",429 "args": [430 "--from", "git+https://github.com/amineelkouhen/mcp-cockroachdb.git",431 "cockroachdb-mcp-server",432 "--url", "postgresql://root@localhost:26257/defaultdb"433 ]434 },435 }436},437```438439Alternatively, you can start the server using `uv` and configure your `mcp.json` or `settings.json`. This is usually desired for development.440441```json442{443 "servers": {444 "cockroach": {445 "type": "stdio",446 "command": "<full_path_uv_command>",447 "args": [448 "--directory",449 "<your_mcp_server_directory>",450 "run",451 "src/main.py"452 ],453 "env": {454 "CRDB_HOST": "<your_cockroachdb_hostname>",455 "CRDB_PORT": "<your_cockroachdb_port>",456 "CRDB_DATABASE": "<your_cockroach_database>",457 "CRDB_USERNAME": "<your_cockroachdb_user>",458 "CRDB_PWD": "<your_cockroachdb_password>"459 }460 }461 }462}463```464465For more information, see the [VS Code documentation](https://code.visualstudio.com/docs/copilot/chat/mcp-servers).466467### Cursor468469Read the configuration options [here](#configuration-via-environment-variables) and input your selections with this link:470471[](https://cursor.com/install-mcp?name=cockroachdb&config=JTdCJTIyY29tbWFuZCUyMiUzQSUyMmRvY2tlciUyMHJ1biUyMC1pJTIwLS1ybSUyMC1lJTIwQ1JEQl9IT1NUJTIwLWUlMjBDUkRCX1BPUlQlMjAtZSUyMENSREJfREFUQUJBU0UlMjAtZSUyMENSREJfVVNFUk5BTUUlMjAtZSUyMENSREJfU1NMX01PREUlMjAtZSUyMENSREJfU1NMX0NBX1BBVEglMjAtZSUyMENSREJfU1NMX0tFWUZJTEUlMjAtZSUyMENSREJfU1NMX0NFUlRGSUxFJTIwLWUlMjBDUkRCX1BXRCUyMG1jcCUyRmNvY2tyb2FjaGRiJTIyJTJDJTIyZW52JTIyJTNBJTdCJTIyQ1JEQl9IT1NUJTIyJTNBJTIyMTI3LjAuMC4xJTIyJTJDJTIyQ1JEQl9QT1JUJTIyJTNBJTIyMjYyNTclMjIlMkMlMjJDUkRCX0RBVEFCQVNFJTIyJTNBJTIyZGVmYXVsdGRiJTIyJTJDJTIyQ1JEQl9VU0VSTkFNRSUyMiUzQSUyMnJvb3QlMjIlMkMlMjJDUkRCX1NTTF9NT0RFJTIyJTNBJTIyZGlzYWJsZSUyMiUyQyUyMkNSREJfU1NMX0NBX1BBVEglMjIlM0ElMjIlMjIlMkMlMjJDUkRCX1NTTF9LRVlGSUxFJTIyJTNBJTIyJTIyJTJDJTIyQ1JEQl9TU0xfQ0VSVEZJTEUlMjIlM0ElMjIlMjIlMkMlMjJDUkRCX1BXRCUyMiUzQSUyMiUyMiU3RCU3RA%3D%3D)472473## Testing474475You can use the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) for visual debugging of this MCP Server.476477```sh478npx @modelcontextprotocol/inspector uv run src/main.py479```480481## Contributing4821. Fork the repository4832. Create a new branch (`feature-branch`)4843. Commit your changes4854. Push to your branch and submit a pull request.486487## License488This project is licensed under the **MIT License**.489490## Quality Badge491492<a href="https://glama.ai/mcp/servers/@amineelkouhen/mcp-cockroach">493 <img width="380" height="200" src="https://glama.ai/mcp/servers/@amineelkouhen/mcp-cockroach/badge" />494</a>495496## Contact497If you have any questions or need support, please feel free to contact us through [GitHub Issues](https://github.com/amineelkouhen/mcp-cockroachdb/issues).498
Full transparency — inspect the skill content before installing.