database-mcp
Automatically discovers database schema, performs data quality checks on tables and columns, and generates natural-language root cause analysis reports using Ollama LLM.
README
database-mcp
A generic MCP server that connects to a DuckDB database, auto-inspects the schema, runs data quality checks across every table and column, and uses a local Ollama LLM to generate a natural-language Root Cause Analysis (RCA) report.
No table names or column names are ever hardcoded. Everything is discovered at runtime from the connection config alone.
Features
- Auto-discovery — pass connection details, the server lists all tables; pick one and it figures out every column and type
- Type-aware checks — numeric columns get distribution stats + Z-score thresholds; VARCHAR columns get cardinality + top values; TIMESTAMP columns get gap detection
- Ollama ReAct loop —
llama3.2(default) iteratively calls tools to drill down, then writes a plain-English RCA report - MCP tools — usable directly from any MCP client (Claude, etc.)
- REST API — thin FastAPI layer for programmatic access
Stack
| Layer | Tool |
|---|---|
| MCP framework | FastMCP |
| Database | DuckDB |
| LLM | Ollama (llama3.2 default, mistral:7b optional) |
| REST API | FastAPI + Uvicorn |
| Tests | Plain Python scripts (python tests/test_*.py) |
Installation
git clone https://github.com/hargurjeet/database-mcp.git
cd database-mcp
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
Ollama must be running locally:
ollama pull llama3.2
ollama serve
Configuration
Edit .env:
OLLAMA_MODEL=llama3.2 # or mistral:7b
OLLAMA_BASE_URL=http://localhost:11434
REPORTS_PATH=./data/reports/
Usage
1. MCP server
python mcp_server/server.py
Available tools:
| Tool | What it does |
|---|---|
tool_list_tables |
Lists all tables — call this first |
tool_get_schema |
Columns + types for a table |
tool_check_null_rates |
Null % per column |
tool_get_row_count |
Total row count |
tool_get_distribution_stats |
Mean / std / min / max for a numeric column |
tool_get_cardinality |
Distinct count + top values for a VARCHAR column |
tool_detect_timestamp_gaps |
Gap analysis for a TIMESTAMP column |
tool_run_full_check |
Runs all applicable checks — returns full summary |
All tools accept a config_json string:
{"db_type": "duckdb", "db_path": "./data/warehouse.db", "table": "trips"}
table is only required for table-specific tools. tool_list_tables needs only the connection fields.
2. REST API
uvicorn api.main:app --reload
# Swagger UI at http://localhost:8000/docs
| Method | Endpoint | Body / Params | What it does |
|---|---|---|---|
GET |
/tables |
?db_path=./data/warehouse.db |
List all tables |
POST |
/check/{table} |
{"db_type":"duckdb","db_path":"..."} |
Full quality check, returns JSON |
POST |
/rca/{table} |
{"db_type":"duckdb","db_path":"..."} |
Full check + Ollama RCA, saves Markdown report |
GET |
/report/{table} |
— | Retrieve last saved RCA report |
Example:
# List tables
curl "http://localhost:8000/tables?db_path=./data/warehouse.db"
# Run full quality check
curl -X POST http://localhost:8000/check/trips \
-H "Content-Type: application/json" \
-d '{"db_type":"duckdb","db_path":"./data/warehouse.db"}'
# Generate RCA report (requires Ollama)
curl -X POST http://localhost:8000/rca/trips \
-H "Content-Type: application/json" \
-d '{"db_type":"duckdb","db_path":"./data/warehouse.db"}'
3. Run the agent directly
python agent/dispatcher.py '{
"db_type": "duckdb",
"db_path": "./data/warehouse.db",
"table": "trips"
}'
Report is printed to stdout and saved to data/reports/trips_rca.md.
Tests
python tests/test_null_tools.py
python tests/test_schema_tools.py
python tests/test_distribution_tools.py
python tests/test_volume_tools.py
python tests/test_cardinality_tools.py
python tests/test_timestamp_tools.py
python tests/test_api.py
23 tests total. All use in-memory DuckDB — no external dependencies required.
Project structure
database-mcp/
├── api/
│ ├── main.py # FastAPI app
│ └── routes.py # Route handlers
│
├── mcp_server/
│ ├── server.py # FastMCP entrypoint + tool registration
│ ├── introspector.py # Schema → check plan mapping
│ ├── connectors/
│ │ ├── base.py # Abstract connector interface
│ │ └── duckdb_connector.py
│ └── tools/
│ ├── schema_tools.py
│ ├── null_tools.py
│ ├── volume_tools.py
│ ├── distribution_tools.py
│ ├── cardinality_tools.py
│ └── timestamp_tools.py
│
├── agent/
│ ├── dispatcher.py # Ollama ReAct loop
│ ├── ollama_client.py
│ └── prompts.py
│
├── data/reports/ # Saved RCA reports
├── docs/session_log.md # Full development history
└── tests/
Roadmap
| Phase | Status |
|---|---|
| Phase 1 — DuckDB + core tools + Ollama loop | Complete |
| Phase 2 — PostgreSQL / MySQL connectors | Skipped |
| Phase 3 — Prefect scheduled scans | Skipped |
| Phase 4 — REST API | Complete |
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。