DB MCP Gateway
Provides read-only access to databases for MCP-compatible AI tools, allowing schema exploration and SELECT queries without exposing credentials or risking data changes.
README
DB MCP Gateway
Give Claude Code, Cursor, Windsurf, or any MCP-compatible AI tool read-only access to your databases — without exposing credentials or risking data changes.
Self-hosted. Everything runs locally. Your passwords never leave your machine.
What it does
Instead of copy-pasting query results between your DB client and your AI tool, the gateway lets your AI query the database directly. It can explore schemas, inspect tables, and run SELECT queries. It cannot insert, update, delete, or drop anything.
Quick Start
1. Install and run
# Prerequisites: Bun (https://bun.sh)
git clone https://github.com/mdadul/db-mcp
cd db-mcp
bun install
bun run dev
Open http://localhost:4080 — the web UI is ready.
2. Add a database
Click Add Your First Database and fill in:
- Host, port, database name
- A read-only database user and password (recommended — the gateway enforces read-only at the query level regardless, but defense in depth is good)
Hit Test Connection to confirm it works.
3. Get your MCP token
The gateway generates a token in .env on first run:
grep MCP_TOKEN .env
4. Connect your AI tool
Claude Code (CLI)
claude mcp add --transport http db-mcp http://localhost:4080/mcp \
--header "Authorization: Bearer <MCP_TOKEN>"
Then restart Claude Code.
Cursor / Windsurf / Claude Desktop
Add to your mcp.json:
{
"mcpServers": {
"db-mcp": {
"url": "http://localhost:4080/mcp",
"headers": {
"Authorization": "Bearer <MCP_TOKEN>"
}
}
}
}
Claude.ai Web
Claude.ai requires HTTPS. Expose the gateway through a tunnel first:
# Option A — Cloudflare (no account needed)
npx cloudflared tunnel --url http://localhost:4080
# Option B — ngrok
ngrok http 4080
Copy the https://... URL from the tunnel output, then add it in Claude.ai → Settings → Integrations → Add MCP Server.
Using it with your AI
Once connected, just ask naturally:
"How many orders were created this week?" "What columns does the
userstable have?" "Show me the last 10 failed jobs."
The AI will call the gateway tools automatically — no copy-pasting.
Available tools
| Tool | What it does |
|---|---|
list_databases |
Lists all connected databases |
get_database_schema |
Lists tables (optional name filter) |
get_table_schema |
Shows columns, indexes, and foreign keys for a table |
execute_read_query |
Runs a SELECT query (capped at 100 rows by default, max 1000) |
Environment variables
| Variable | Required | Description |
|---|---|---|
DATABASE_PATH |
Yes | Path for the local SQLite metadata store (e.g. ./data/db-mcp.sqlite) |
ENCRYPTION_KEY |
Yes | 64-char hex key for credential encryption. Generate: openssl rand -hex 32 |
MCP_TOKEN |
Yes | Bearer token for the /mcp endpoint. Generate: openssl rand -base64 32 |
PORT |
No | HTTP port (default: 4080) |
A .env file is created with generated values on first run.
Troubleshooting
Tools not showing up in Claude Code
Restart Claude Code after adding the MCP server. If still missing, run claude mcp list to confirm it's registered and shows ✓ Connected.
"Failed to connect" in Claude Code
Check the gateway is running (http://localhost:4080 should load) and the token in your config matches .env.
"Session not found" errors The gateway is stateless — each request is independent. If you see this, reconnect the MCP server in your IDE.
"URL must start with https" (Claude.ai Web) Claude.ai blocks plain HTTP. Use a tunnel — see the Claude.ai Web setup above.
Connection refused to my database
If the gateway runs in Docker and your database is on the host, use host.docker.internal instead of localhost as the host.
Security notes
- The
MCP_TOKENcontrols access to all your databases via the gateway. Treat it like a password. - Database credentials are encrypted with AES-256-GCM. The key lives only in
ENCRYPTION_KEY— never in the database. - Only
SELECT,SHOW,DESCRIBE, andEXPLAINare permitted. Write operations are rejected at the gateway layer before reaching the database. - All queries are logged in the web dashboard under each database's Logs tab.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。