DB-MCP
An MCP server that bridges AI assistants with data warehouses through Cube.js to enable governed, natural language semantic analytics queries. It provides tools for metadata discovery and secure query execution while enforcing governance policies like PII blocking and access limits.
README
DB-MCP
Give AI assistants governed access to your databases through the Model Context Protocol. Connect any supported database, define governance rules, and let AI query your data safely.
Supported databases: PostgreSQL, MySQL, BigQuery, Snowflake, Redshift, ClickHouse
Quick Start
Demo Data (try it in 2 minutes)
git clone https://github.com/syam/db-mcp.git
cd db-mcp
docker compose up
- Open http://localhost:3000 and click Try with Demo Data
- The demo sets up a sample e-commerce database with cubes and governance rules pre-configured
- Your MCP endpoint is live at
http://localhost:3000/mcp/default
Add to Claude Desktop (Settings > MCP Servers):
{
"mcpServers": {
"db-mcp": {
"url": "http://localhost:3000/mcp/default"
}
}
}
Your Own Database
git clone https://github.com/syam/db-mcp.git
cd db-mcp
cp .env.example .env # optionally set ANTHROPIC_API_KEY for AI chat
docker compose up
- Open http://localhost:3000 and click Add Database
- Fill in the connection form and click Test Connection to verify
- Generate cubes — go to the Tables page, click Generate All Cubes (or generate per-table). This creates the YAML definitions that tell the semantic layer what's queryable.
- Configure governance (optional) — go to the Governance page to mark PII fields, control member exposure, and set query restrictions
- Your MCP endpoint is live at
http://localhost:3000/mcp/{your-database-id}
Important: Without generating cubes (step 3), MCP tools will return no data. The semantic layer automatically picks up new and changed cube files — no restart needed.
How It Works
Your Database → Cube Definitions (YAML) → Semantic Layer → Governance Rules → MCP Tools → AI Assistant
- Cube definitions map your database tables into queryable measures and dimensions
- Governance rules control which members AI can access (PII blocking, exposure, query limits)
- MCP tools expose the governed semantic layer to any MCP-compatible AI assistant
Cube Definitions
Cubes are YAML files that define what AI can query. Each cube maps a database table to typed measures (aggregations) and dimensions (attributes).
Location: data/databases/{id}/cube/model/cubes/*.yml
How to create: Use the Tables page in the admin UI and click Generate All Cubes. If you have ANTHROPIC_API_KEY set, the generator will add rich descriptions to help AI understand your data. You can also write cube YAML manually.
Example:
cubes:
- name: orders
sql_table: orders
measures:
- name: count
type: count
- name: total_amount
type: sum
sql: "{CUBE}.amount"
dimensions:
- name: status
sql: "{CUBE}.status"
type: string
- name: created_at
sql: "{CUBE}.created_at"
type: time
Supported measure types: count, sum, avg, min, max, count_distinct
Supported dimension types: string, number, time, boolean
The semantic layer automatically detects new and changed cube files — no restart needed.
Governance
Governance controls which members AI can access and how. Configure via the Governance page in the admin UI, or edit data/databases/{id}/agent_catalog.yaml directly.
Example:
version: "1.0"
defaults:
exposed: true
pii: false
members:
Users.email:
exposed: false
pii: true
Orders.total_amount:
allowedGroupBy:
- Orders.status
- Orders.created_at
Features:
- PII Protection — Mark sensitive fields to block them from all queries
- Member Exposure — Control which measures and dimensions are queryable
- Query Limits — Enforce maximum row counts per query
- Group-by Restrictions — Limit which dimensions can be used for grouping
- Default Filters — Automatically apply security filters (e.g., tenant isolation) to all queries
- Default Segments — Apply pre-defined segments to all queries
Connect to AI Assistants
Each database gets its own MCP endpoint at /mcp/{databaseId}.
Claude Desktop — Add to Settings > MCP Servers:
{
"mcpServers": {
"db-mcp": {
"url": "http://localhost:3000/mcp/default"
}
}
}
Cursor / Other MCP Clients — Point to http://localhost:3000/mcp/{databaseId} as an HTTP MCP endpoint.
Built-in AI Chat — Set ANTHROPIC_API_KEY in your .env and use the Chat page in the admin UI to query your data conversationally.
MCP Tools
| Tool | Description |
|---|---|
catalog_search |
Search for measures, dimensions, and segments with fuzzy matching |
catalog_describe |
Get detailed member information including governance status |
query_semantic |
Execute governed queries against the semantic layer |
Configuration
For Docker, set these in your .env file or shell before running docker compose up:
| Variable | Required | Purpose |
|---|---|---|
CUBE_JWT_SECRET |
Auto-set | JWT secret shared with Cube.js (default provided in docker-compose.yml) |
ANTHROPIC_API_KEY |
No | Enable AI chat and LLM-enhanced cube generation |
ADMIN_SECRET |
No | Encrypt stored database credentials with AES-256-GCM (min 32 chars) |
Copy .env.example to .env to see all available variables.
Local Development
For contributors working on db-mcp itself:
# Start infrastructure with exposed ports
docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d postgres cube
# Install dependencies
npm install
# Copy and edit env file
cp .env.example .env
# Start backend (port 3000)
npm run dev
# Start frontend (port 3001, in another terminal)
cd admin/frontend && npm install && npm run dev
npm run test # Run tests
npm run lint # Lint
npm run build # Build for production
npx playwright test # E2E tests
Architecture
See docs/architecture.md for detailed architecture, API reference, and troubleshooting.
localhost:3000 (nginx)
├── /api/* Admin REST API
├── /mcp/:id MCP endpoints (Streamable HTTP + SSE)
├── /health Health check
└── /* Admin UI (React SPA)
│
▼
Express Backend
│
▼
Semantic Layer (Cube.js)
│
▼
Your Databases
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。