CockroachDB MCP Server

CockroachDB MCP Server

A natural language interface for LLMs to manage, monitor, and query CockroachDB. It provides tools for cluster monitoring, database operations, table management, and query execution.

Category
访问服务器

README

Add to Cursor Add to VS Code Add to Claude Add to ChatGPT Add to Codex Add to Gemini

CockroachDB MCP Server

License: MIT Python Version MCP Compatible Trust Score

Overview

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.

Table of Contents

Features

  • Natural Language Queries: Enables AI agents to query and create transactions using natural language, supporting complex workflows.
  • Search & Filtering: Supports efficient data retrieval and searching in CockroachDB.
  • Cluster Monitoring: Check and monitor the CockroachDB cluster status, including node health and replication.
  • Database Operations: Perform all operations related to databases, such as creation, deletion, and configuration.
  • Table Management: Handle tables, indexes, and schemas for flexible data modeling.
  • Seamless MCP Integration: Works with any MCP client for smooth communication.
  • Scalable & Lightweight: Designed for high-performance data operations.

Tools

The CockroachDB MCP Server Server provides tools to manage the data stored in CockroachDB.

architecture

The tools are organized into four main categories:

Cluster Monitoring

Purpose: Provides tools for monitoring and managing CockroachDB clusters.

Summary:

  • Get cluster health and node status.
  • Show currently running queries.
  • Analyze query performance statistics.
  • Retrieve replication and distribution status for tables or the whole database.

Database Operations

Purpose: Handles database-level operations and connection management.

Summary:

  • Connect to a CockroachDB database.
  • List, create, drop, and switch databases.
  • Get connection status and active sessions.
  • Retrieve database settings.

Table Management

Purpose: Provides tools for managing tables, indexes, views, and schema relationships in CockroachDB.

Summary:

  • Create, drop, and describe tables and views.
  • Bulk import data into tables.
  • Manage indexes (create/drop).
  • List tables, views, and table relationships.
  • Analyze schema structure and metadata.

Query Engine

Purpose: Executes and manages SQL queries and transactions.

Summary:

  • Execute SQL queries with formatting options (JSON, CSV, table).
  • Run multi-statement transactions.
  • Explain query plans for optimization.
  • Track and retrieve query history.

Installation

The CockroachDB MCP Server supports the stdio transport. Support for the streamable-http transport will be added in a future release.

Quick Start with uvx

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

uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git@0.1.0 cockroachdb-mcp-server --url postgresql://localhost:26257/defaultdb

Check the release notes for the latest version in the Releases section. Additional examples are provided below.

# Run with CockroachDB URI
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --url postgresql://localhost:26257/defaultdb

# Run with individual parameters
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --host localhost --port 26257 --database defaultdb --user root --password mypassword

# See all options
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --help

Development Installation

For development or if you prefer to clone the repository:

# Clone the repository
git clone https://github.com/amineelkouhen/mcp-cockroachdb.git
cd mcp-cockroachdb

# Install dependencies using uv
uv venv
source .venv/bin/activate
uv sync

# Run with CLI interface
uv run cockroachdb-mcp-server --help

# Or run the main file directly (uses environment variables)
uv run src/main.py

Once 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. The following example is for Claude Desktop, but the same applies to any other MCP Client.

  1. Specify your CockroachDB credentials and TLS configuration
  2. Retrieve your uv command full path (e.g. which uv)
  3. Edit the claude_desktop_config.json configuration file    - on a MacOS, at ~/Library/Application Support/Claude/
{
    "mcpServers": {
        "cockroach": {
            "command": "<full_path_uv_command>",
            "args": [
                "--directory",
                "<your_mcp_server_directory>",
                "run",
                "src/main.py"
            ],
            "env": {
                "CRDB_HOST": "<your_cockroachdb_hostname>",
                "CRDB_PORT": "<your_cockroachdb_port>",
                "CRDB_DATABASE": "<your_cockroach_database>",
                "CRDB_USERNAME": "<your_cockroachdb_user>",
                "CRDB_PWD": "<your_cockroachdb_password>",
                "CRDB_SSL_MODE": "disable|allow|prefer|require|verify-ca|verify-full",
                "CRDB_SSL_CA_PATH": "<your_cockroachdb_ca_path>",
                "CRDB_SSL_KEYFILE": "<your_cockroachdb_keyfile_path>",
                "CRDB_SSL_CERTFILE": "<your_cockroachdb_certificate_path>",
            }
        }
    }
}

You can troubleshoot problems by tailing the log file.

tail -f ~/Library/Logs/Claude/mcp-server-cockroach.log

With Docker

You can use a dockerized deployment of this server. You can either build your image or use the official CockroachDB MCP Docker image.

If you'd like to build your image, the CockroachDB MCP Server provides a Dockerfile. Build this server's image with:

docker build -t mcp-cockroachdb .

Finally, 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:

{
  "mcpServers": {
    "cockroach": {
      "command": "docker",
      "args": ["run",
                "--rm",
                "--name",
                "cockroachdb-mcp-server",
                "-e", "CRDB_HOST=<cockroachdb_host>",
                "-e", "CRDB_PORT=<cockroachdb_port>",
                "-e", "CRDB_DATABASE=<cockroachdb_database>",
                "-e", "CRDB_USERNAME=<cockroachdb_user>",
                "mcp-cockroachdb"]
    }
  }
}

To use the CockroachDB MCP Docker image, just replace your image name (mcp-cockroachdb in the example above) with mcp/cockroachdb.

Configuration

The CockroachDB MCP Server can be configured in two ways: either via command-line arguments or via environment variables. The precedence is: CLI arguments > environment variables > default values.

Configuration via command line arguments

When using the CLI interface, you can configure the server with command line arguments:

# Basic CockroachDB connection
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \
  --host localhost \
  --port 26257 \
  --db defaultdb \
  --user root \
  --password mypassword

# Using CockroachDB URI (simpler)
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \
  --url postgresql://root@localhost:26257/defaultdb

# SSL connection
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server \
  --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.key

# See all available options
uvx --from git+https://github.com/amineelkouhen/mcp-cockroachdb.git cockroachdb-mcp-server --help

Available CLI Options:

  • --url - CockroachDB connection URI (postgresql://user:pass@host:port/db)
  • --host - CockroachDB hostname
  • --port - CockroachDB port (default: 26257)
  • --db - CockroachDB database name (default: defaultdb)
  • --user - CockroachDB username
  • --password - CockroachDB password
  • --ssl-mode - SSL mode - Possible values: require, verify-ca, verify-full, disable (default)
  • --ssl-key - Path to SSL Client key file
  • --ssl-cert - Path to SSL Client certificate file
  • --ssl-ca-cert - Path to CA (Root) certificate file'

Configuration via Environment Variables

If desired, you can use environment variables. Defaults are provided for all variables.

Name Description Default Value
CRDB_HOST The host name or address of a CockroachDB node or load balancer. 127.0.0.1
CRDB_PORT The port number of the SQL interface of the CockroachDB node or load balancer. 26257
CRDB_DATABASE A database name to use as the current database. defaultdb
CRDB_USERNAME The SQL user that will own the client session. root
CRDB_PWD The user's password. None
CRDB_SSL_MODE Which type of secure connection to use. disable
CRDB_SSL_CA_PATH Path to the CA certificate, when sslmode is not disable. None
CRDB_SSL_CERTFILE Path to the client certificate, when sslmode is not disable. None
CRDB_SSL_KEYFILE Path to the client private key, when sslmode is not disable. None

There are several ways to set environment variables:

  1. Using a .env File:   Place 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). For example, create a .env file with the following content from the .env.example file provided in the repository:
cp .env.example .env

Then edit the .env file to set your CockroachDB configuration:

OR,

  1. Setting Variables in the Shell:   You can export environment variables directly in your shell before running your application. For example:
export CRDB_URL= postgresql://root@127.0.0.1:26257/defaultdb

This method is helpful for temporary overrides or quick testing.

Integrations

Integrating 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.

OpenAI Agents SDK

Integrate this MCP Server with the OpenAI Agents SDK. Read the documents to learn more about the integration of the SDK with MCP.

Install the Python SDK.

pip install openai-agents

Configure the OpenAI token:

export OPENAI_API_KEY="<openai_token>"

And run the application.

python3 examples/cockroachdb_assistant.py

You can troubleshoot your agent workflows using the OpenAI dashboard.

Augment

You can configure the CockroachDB MCP Server in Augment by importing the server via JSON:

{
  "mcpServers": {
    "CockroachDB MCP Server": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/cockroachdb/mcp-cockroachdb.git",
        "cockroachdb-mcp-server",
        "--url",
        "postgresql://root@localhost:26257/defaultdb"
      ]
    }
  }
}

Claude Desktop

The 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.

{
    "mcpServers": {
        "cockroach-mcp-server": {
            "type": "stdio",
            "command": "/opt/homebrew/bin/uvx",
            "args": [
                "--from", "git+https://github.com/amineelkouhen/mcp-cockroachdb.git",
                "cockroachdb-mcp-server",
                "--url", "postgresql://localhost:26257/defaultdb"
            ]
        }
    }
}

Please follow the prompt and give the details to configure the server and connect to CockroachDB (e.g., using a managed CockroachDB instance). The procedure will create the proper configuration in the claude_desktop_config.json configuration file.

VS Code with GitHub Copilot

To use the CockroachDB MCP Server with VS Code, you must enable the agent mode tools. Add the following to your settings.json:

{
  "chat.agent.enabled": true
}

You can start the GitHub desired version of the CockroachDB MCP server using uvx by adding the following JSON to your settings.json:

"mcp": {
    "servers": {
        "CockroachDB MCP Server": {
        "type": "stdio",
        "command": "uvx", 
        "args": [
            "--from", "git+https://github.com/amineelkouhen/mcp-cockroachdb.git",
            "cockroachdb-mcp-server",
            "--url", "postgresql://root@localhost:26257/defaultdb"
        ]
        },
    }
},

Alternatively, you can start the server using uv and configure your mcp.json or settings.json. This is usually desired for development.

{
  "servers": {
    "cockroach": {
      "type": "stdio",
      "command": "<full_path_uv_command>",
      "args": [
        "--directory",
        "<your_mcp_server_directory>",
        "run",
        "src/main.py"
      ],
      "env": {
        "CRDB_HOST": "<your_cockroachdb_hostname>",
        "CRDB_PORT": "<your_cockroachdb_port>",
        "CRDB_DATABASE": "<your_cockroach_database>",
        "CRDB_USERNAME": "<your_cockroachdb_user>",
        "CRDB_PWD": "<your_cockroachdb_password>"
      }
    }
  }
}

For more information, see the VS Code documentation.

Cursor

Read the configuration options here and input your selections with this link:

Install MCP Server

Testing

You can use the MCP Inspector for visual debugging of this MCP Server.

npx @modelcontextprotocol/inspector uv run src/main.py

Contributing

  1. Fork the repository
  2. Create a new branch (feature-branch)
  3. Commit your changes
  4. Push to your branch and submit a pull request.

License

This project is licensed under the MIT License.

Quality Badge

<a href="https://glama.ai/mcp/servers/@amineelkouhen/mcp-cockroach"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@amineelkouhen/mcp-cockroach/badge" /> </a>

Contact

If you have any questions or need support, please feel free to contact us through GitHub Issues.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选