这是一个基于 Cursor 的 CockroachDB MCP 服务器,依据 Model Context Protocol (MCP) 规范实现,可让您直接与 CockroachDB 数据库进行交互。
本项目是基于 Cursor 的 CockroachDB MCP 服务器,实现了 MCP 规范,能让您直接与 CockroachDB 数据库交互。以下为您介绍使用前的安装步骤和在 Cursor 中的使用方法。
您可通过 Smithery 自动安装 CockroachDB MCP Server for Cursor:
npx -y @smithery/cli install @Swayingleaves/cockroachdb-mcp-server --client claude
pip install -r requirements.txt
curl -LsSf https://astral.sh/uv/install.sh | sh
{
"mcpServers": {
"cockroachdb-mcp": {
"command": "uv",
"args": [
"--directory",
"/Users/local/cockroachdb-mcp",
"run",
"server.py"
],
"jdbc_url": "jdbc:postgresql://localhost:2626/your_database",
"username": "your_username",
"password": "your_password"
}
}
}
connect_databasejdbc_url:要连接的数据库的 JDBC URL。username:登录数据库的用户名。password:登录数据库的密码。/tables/schema/{table}table:要获取结构信息的表名称。curl http://localhost:2626/tables
# 响应: ["users", "products", "orders"]
curl http://localhost:2626/schema/users
# 响应: {
# "columns": ["id", "name", "email", "created_at"],
# "types": ["int", "text", "text", "timestamp"]
# }
./cockroachdb-mcp-server.logINFO: Server started on port 2626
DEBUG: Received request GET /tables
INFO: Response sent with status 200
ERROR: Error executing query: table 'nonexistent' not found
\ 转义特殊字符。{
"query": "SELECT * FROM `users` WHERE id = \\$1"
}
uvicorn --reload --host 0.0.0.0 --port 2626 yourapp:app
Connection RefusedQuery TimeoutDatabase Not Foundexport DATABASE_URL="jdbc:postgresql://localhost:2626/your_database"
export DB_USER="your_username"
export DB_PASSWORD="your_password"
from typing import List, Dict
import logging
from fastapi import FastAPI
app = FastAPI()
@app.get("/tables")
async def get_tables() -> List[str]:
return ["users", "products", "orders"]
@app.get("/schema/{table}")
async def get_schema(table: str) -> Dict:
schemas: Dict = {
"users": {"columns": ["id", "name", "email"], "types": ["int", "text", "text"]},
"products": {"columns": ["id", "name", "price"], "types": ["int", "text", "float"]}
}
return schemas.get(table, {"error": "Table not found"})
欢迎提交问题和拉取请求! 仓库地址: https://github.com/yourusername/cockroachdb-mcp-server
MIT License