Skip to content

Commit 264ad64

Browse files
committed
release v0.1.0
0 parents  commit 264ad64

25 files changed

+703
-0
lines changed

.github/workflows/python-ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e .[dev]
25+
26+
- name: Lint with ruff (non-blocking)
27+
run: ruff check . || true
28+
29+
- name: Format check with black
30+
run: black --check crdb_mcp_server
31+
32+
- name: Run tests
33+
run: pytest tests/

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
*.sw?
2+
.#*
3+
*#
4+
*~
5+
.project
6+
.settings
7+
build
8+
target
9+
*.sublime-*
10+
/scratch
11+
*.iml
12+
*.log
13+
*.gfs
14+
*.idea
15+
logs/**
16+
versions.properties
17+
**/.DS_Store
18+
/.idea/
19+
*.egg-info
20+
/logs/
21+
build/
22+
dist/
23+
*.egg-info/
24+
__pycache__/
25+
venv/
26+
*.py[oc]
27+
wheels/
28+
.venv
29+
.coverage

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
---
6+
7+
## [v0.1.0] - 2025-06-11
8+
9+
### Added
10+
- Initial public release of `cockroachdb-mcp-server`
11+
- FastAPI server implementing MCP spec
12+
- REST endpoints for context CRUD (`/contexts`)
13+
- SQLAlchemy integration with CockroachDB
14+
- Automatic dialect fix for `cockroachdb://` and `postgresql://` prefixes
15+
- CLI entrypoint via `cockroachdb-mcp-server serve`
16+
- Schema bootstrap via `--init-schema` or `MCP_AUTO_INIT_SCHEMA`
17+
- ASCII banner (`--banner`) and version info (`--version`)
18+
- Structured logging (`--log-level`)
19+
20+
### Known Limitations
21+
- No `/run`, `/deploy`, or `/evaluate` endpoints yet
22+
- No auth or rate limiting (coming in future versions)

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
# Install uv globally and install deps into system Python
6+
COPY pyproject.toml .
7+
RUN pip install --no-cache-dir uv && uv pip install --system .
8+
9+
# Copy app
10+
COPY ./app ./app
11+
COPY ./schema ./schema
12+
13+
COPY entrypoint.sh /entrypoint.sh
14+
RUN chmod +x /entrypoint.sh
15+
16+
ENTRYPOINT ["/entrypoint.sh"]
17+
#CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Virag Tripathi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.PHONY: help prepare install format lint test build publish clean
2+
3+
help:
4+
@echo "📦 Makefile for cockroachdb-mcp-server"
5+
@echo ""
6+
@echo "Available targets:"
7+
@echo " prepare Set up virtualenv and install build tools"
8+
@echo " install Install dependencies in editable mode"
9+
@echo " format Format code using black"
10+
@echo " lint Run static checks with ruff"
11+
@echo " test Run tests with pytest"
12+
@echo " build Build wheel and sdist packages"
13+
@echo " publish Upload to PyPI (requires credentials)"
14+
@echo " clean Remove build and metadata artifacts"
15+
16+
prepare:
17+
@echo "🔧 Preparing virtual environment..."
18+
@python3 -m venv .venv
19+
@. .venv/bin/activate && \
20+
python -m ensurepip --upgrade && \
21+
python -m pip install --upgrade pip build
22+
23+
install:
24+
pip install -e .[dev]
25+
26+
format:
27+
black cockroachdb_mcp_server
28+
black app
29+
30+
lint:
31+
ruff cockroachdb_mcp_server
32+
33+
test:
34+
pytest tests/
35+
36+
build:
37+
. .venv/bin/activate && python -m build
38+
39+
publish:
40+
twine upload dist/*
41+
42+
clean:
43+
rm -rf dist/ build/ *.egg-info .pytest_cache .mypy_cache .venv

README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# cockroachdb-mcp-server
2+
3+
![PyPI](https://img.shields.io/pypi/v/cockroachdb-mcp-server)
4+
![Python](https://img.shields.io/pypi/pyversions/cockroachdb-mcp-server)
5+
![License](https://img.shields.io/github/license/viragtripathi/cockroachdb-mcp-server)
6+
![CI](https://github.com/viragtripathi/cockroachdb-mcp-server/actions/workflows/python-ci.yml/badge.svg)
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.).

app/__init__.py

Whitespace-only changes.

app/db/db_connection.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from sqlalchemy import create_engine
2+
from cockroachdb_mcp_server.config import resolve_crdb_url
3+
import logging
4+
5+
logger = logging.getLogger(__name__)
6+
7+
8+
def get_sqlalchemy_engine(opts=None):
9+
if opts is None:
10+
dsn = resolve_crdb_url()
11+
return create_engine(dsn)
12+
13+
base = f"cockroachdb://root@{opts.get('host', 'localhost')}:{opts.get('port', 26257)}/{opts['db']}"
14+
if opts.get("certs_dir"):
15+
base += (
16+
f"?sslmode=verify-full"
17+
f"&sslrootcert={opts['certs_dir']}/ca.crt"
18+
f"&sslcert={opts['certs_dir']}/client.root.crt"
19+
f"&sslkey={opts['certs_dir']}/client.root.key"
20+
)
21+
else:
22+
base += "?sslmode=disable"
23+
24+
logger.debug("Constructed CRDB DSN from opts: %s", base)
25+
return create_engine(base)
26+
27+
28+
""""
29+
def get_psycopg_connection():
30+
url = resolve_crdb_url()
31+
pg_url = url.replace("cockroachdb://", "postgresql://")
32+
print(f"[debug] Using psycopg2 connection: {pg_url}")
33+
return psycopg2.connect(pg_url)
34+
"""

app/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from fastapi import FastAPI
2+
from app.routes import health, contexts
3+
from cockroachdb_mcp_server import __version__
4+
5+
app = FastAPI(title="CockroachDB MCP Server", version={__version__})
6+
7+
app.include_router(health.router)
8+
app.include_router(contexts.router, prefix="/contexts")
9+
10+
11+
@app.get("/")
12+
def root():
13+
return {"message": "MCP Server is running"}

0 commit comments

Comments
 (0)