|
| 1 | +# cockroachdb-mcp-server |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +A Model Context Protocol (MCP) server implemented in Python using FastAPI and CockroachDB. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## 🧠 What This Is |
| 13 | + |
| 14 | +`cockroachdb-mcp-server` is a production-grade, spec-aligned MCP server that: |
| 15 | + |
| 16 | +- Implements the [Model Context Protocol](https://modelcontextprotocol.io/introduction) |
| 17 | +- Uses **CockroachDB** as a resilient, SQL-compatible backend |
| 18 | +- Exposes full **CRUD APIs** for managing model contexts |
| 19 | +- Stores context definitions as **JSONB**, allowing arbitrary input/output schema |
| 20 | +- Works seamlessly with the [`cockroachdb-mcp-client`](https://github.com/viragtripathi/cockroachdb-mcp-client) CLI |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## ✅ Feature Highlights |
| 25 | + |
| 26 | +- ✅ REST API for MCP context management (`/contexts`) |
| 27 | +- ✅ Schema bootstrapping via CLI flag or env var |
| 28 | +- ✅ CRDB URL auto-detection and dialect fix |
| 29 | +- ✅ ASCII banner and version info |
| 30 | +- ✅ Structured logging and configurable log level |
| 31 | +- ✅ Ready for `/run`, `/deploy`, `/evaluate` extensions |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## 🚀 Quickstart |
| 36 | + |
| 37 | +### 📦 Install from PyPI |
| 38 | + |
| 39 | +```bash |
| 40 | +pip install cockroachdb-mcp-server |
| 41 | +```` |
| 42 | + |
| 43 | +### 🏃 Run with schema init |
| 44 | + |
| 45 | +```bash |
| 46 | +cockroachdb-mcp-server serve --init-schema --log-level INFO |
| 47 | +``` |
| 48 | + |
| 49 | +Or: |
| 50 | + |
| 51 | +```bash |
| 52 | +export MCP_AUTO_INIT_SCHEMA=true |
| 53 | +cockroachdb-mcp-server serve |
| 54 | +``` |
| 55 | + |
| 56 | +> Server runs at `http://localhost:8081` by default |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | +## 🔧 CLI Usage |
| 61 | + |
| 62 | +```bash |
| 63 | +cockroachdb-mcp-server serve --init-schema |
| 64 | +cockroachdb-mcp-server serve --port 8081 --host 127.0.0.1 --reload |
| 65 | +cockroachdb-mcp-server --version |
| 66 | +cockroachdb-mcp-server --banner |
| 67 | +``` |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## 🔐 Configuring the Database |
| 72 | + |
| 73 | +### ✅ Set the `CRDB_URL` environment variable |
| 74 | + |
| 75 | +```bash |
| 76 | +export CRDB_URL="postgresql://root@localhost:26257/defaultdb?sslmode=disable" |
| 77 | +``` |
| 78 | + |
| 79 | +> Automatically rewritten to `cockroachdb://...` under the hood for compatibility. |
| 80 | + |
| 81 | +Alternatively, set it directly: |
| 82 | + |
| 83 | +```bash |
| 84 | +export CRDB_URL="cockroachdb://root@localhost:26257/defaultdb?sslmode=disable" |
| 85 | +``` |
| 86 | + |
| 87 | +✅ Both formats are supported. |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## 🧪 API Endpoints |
| 92 | + |
| 93 | +| Method | Path | Description | |
| 94 | +|--------|------------------|-------------------| |
| 95 | +| POST | `/contexts` | Create a context | |
| 96 | +| GET | `/contexts` | List all contexts | |
| 97 | +| GET | `/contexts/{id}` | Get context by ID | |
| 98 | +| PUT | `/contexts/{id}` | Update context | |
| 99 | +| DELETE | `/contexts/{id}` | Delete context | |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## 🧱 Schema Auto-Bootstrap |
| 104 | + |
| 105 | +Run this manually: |
| 106 | + |
| 107 | +```bash |
| 108 | +cockroachdb-mcp-server serve --init-schema |
| 109 | +``` |
| 110 | + |
| 111 | +Or automatically with: |
| 112 | + |
| 113 | +```bash |
| 114 | +export MCP_AUTO_INIT_SCHEMA=true |
| 115 | +``` |
| 116 | + |
| 117 | +The schema created is: |
| 118 | + |
| 119 | +```sql |
| 120 | +CREATE TABLE IF NOT EXISTS mcp_contexts ( |
| 121 | + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), |
| 122 | + context_name STRING NOT NULL, |
| 123 | + context_version STRING NOT NULL, |
| 124 | + body JSONB NOT NULL, |
| 125 | + created_at TIMESTAMP DEFAULT now() |
| 126 | +); |
| 127 | +``` |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## 🔗 Related Projects |
| 132 | + |
| 133 | +* [cockroachdb-mcp-client](https://github.com/viragtripathi/cockroachdb-mcp-client): CLI tool to manage MCP contexts, simulate LLM runs, export, and batch simulate across providers. |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## 🙌 Contributions |
| 138 | + |
| 139 | +This project is designed for internal and community use. |
| 140 | + |
| 141 | +PRs welcome to extend functionality (auth, deployment support, `/evaluate`, telemetry, etc.). |
0 commit comments