
Database Mcp
io.github.cocaxcode由 GitHub 帳號 cocaxcode 發布v0.1.14更新於 Oct 24, 2026
MCP server for database connectivity. Multi-DB (PostgreSQL, MySQL, SQLite), 19 tools.
概覽
讓助理連線 PostgreSQL、MySQL 與 SQLite 資料庫,檢視結構、執行查詢與寫入,並可回復變更。
- 可以做什麼
- 這是一套本機資料庫工作台,提供 33 個工具,涵蓋三種資料庫引擎。它管理依專案目錄分組的具名連線,支援三種詳細程度的結構探查,並透過 MCP Resources 提供結構資訊,讓助理自動組合 JOIN。它執行查詢、寫入與 EXPLAIN 執行計畫,具備自動 LIMIT、寫入前快照回復、匯出/還原,以及依專案記錄的查詢歷史。
- 適用情境
- 適合想用自然語言瀏覽與查詢自己的 PostgreSQL、MySQL 或 SQLite 資料庫、依專案目錄區分開發/測試/正式連線,並能撤銷誤操作的情況。若只是偶爾透過資料庫命令列執行一次性查詢,則不太需要。
- 執行需求
- 需要 Node.js 與 npx,以 stdio 方式在本機執行 npm 套件 @cocaxcode/database-mcp。使用 npx 時須全域安裝資料庫驅動程式:postgres、mysql2,或 SQLite 的 sql.js。資料庫連線資訊(主機、資料庫、使用者、密碼)透過助理輸入並儲存在本機;未宣告需要雲端帳號或 API 金鑰。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Database Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
@cocaxcode/database-mcp
Your databases, one conversation away.
33 tools · PostgreSQL · MySQL · SQLite · Connection Groups · Rollback · Dump/Restore · Schema auto-discovery
[npm version] [npm downloads] [License] [Node] [33 tools]
Overview · Just Talk to It · Connection Groups · Installation · Features · Tool Reference · Storage · Architecture
Quick Overview
The most complete MCP server for databases. 33 tools across 3 engines (PostgreSQL, MySQL, SQLite), with connection groups, named connection management, automatic rollback, dump/restore, schema auto-discovery via MCP Resources, and full query history — all from natural language.
This is not just a query runner. It is a full database workbench: organize connections into groups scoped to your project directories, set defaults that persist between sessions, introspect schemas at three levels of detail, get pre-mutation snapshots on every write, undo mistakes with reverse SQL, dump and restore entire databases, and track every query you run — per project, per connection.
Every connection belongs to a group. Groups have scopes (directories), a default connection, and an active connection. When you work inside a scoped directory, you only see that group's connections — no clutter, no confusion.
You describe what you need. The AI reads your schema, writes the SQL, and executes it safely — with automatic LIMIT injection, pre-mutation snapshots, and confirmation before destructive operations. No cloud accounts, no ORMs, no config files. Credentials never leave your machine. Everything runs locally.
Works with Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, Codex CLI, Gemini CLI, and any MCP-compatible client.
Just Talk to It
You don't need to memorize tool names or SQL syntax. Just say what you want.
The AI already knows your schema through MCP Resources. It reads db://schema to discover tables and db://tables/{name}/schema for columns, foreign keys, and indexes. When you ask for data across tables, it builds correct JOINs automatically.
Connection Groups
Every connection belongs to a group. Groups are the organizing unit for your database connections — they keep things scoped, clean, and automatic.
A group has three key concepts:
- Scopes: directories that share the group's connections. When you work inside a scoped directory, you only see that group's connections. No global clutter.
- Default: the connection that activates automatically when you enter a scoped directory. Persists between sessions.
- Active: the connection being used right now. Session only — resets to the default on restart.
Here is a practical workflow:
The first connection added to a group becomes the default automatically. Switching connections only changes the active for the current session — restart and you are back to the default. If you want the change to stick, set a new default explicitly.
This means you can safely switch to production for a quick query and know that next time you open the project, you will be back on your development database.
Installation
Claude Code
Claude Desktop
Add to your config file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS, %APPDATA%\Claude\claude_desktop_config.json on Windows):
Cursor / Windsurf
Add to .cursor/mcp.json or .windsurf/mcp.json in your project root:
VS Code
Add to .vscode/mcp.json:
Codex CLI (OpenAI)
Or add to ~/.codex/config.toml:
Gemini CLI (Google)
Add to ~/.gemini/settings.json:
Driver installation
Install only the driver(s) you need — they load dynamically at runtime:
Note: When using
npx, drivers must be installed globally. If you install the server globally (npm install -g @cocaxcode/database-mcp), drivers can be local or global.
Features
Multi-database, one interface
Most database MCP servers make you reconfigure credentials every session. This one does not. Named connections persist inside groups — create them once, use them forever.
Named connections work like git branches. You create dev, staging, prod once inside a group and they are always there. Switching is instant — one command, zero reconfiguration:
Group-scoped connections mean different projects see different databases automatically. Working on project A? You see project A's group and connections. Switch to project B's directory and it picks up project B's group with its own default. No manual switching, no interference between projects:
Now each directory has its own isolated set of connections.
100% local credentials. Every connection is stored as a JSON file in ~/.database-mcp/connections/. Passwords never leave your machine. Nothing is sent to the cloud. Nothing is committed to git. Your credentials are yours.
Live management. Create, duplicate, rename, test, export, and switch connections mid-conversation. No restart needed, no config file editing, no context loss.
Safety built in
Rollback snapshots
Every mutation captures a pre-state snapshot. Undo anything.
Schema introspection
Three levels of detail, with pattern filtering:
MCP Resources (db://schema and db://tables/{name}/schema) give AI agents automatic access to your schema — no manual SQL needed for multi-table queries.
Query execution with EXPLAIN
Compression modes (v0.3+)
SQL results often carry TEXT / JSON / HTML columns that can be kilobytes per row. AI agents pay for every byte that reaches the context window. execute_query, execute_mutation and explain_query accept four optional parameters that cut 60-95% of those tokens while keeping rows and structure intact.
Modes:
minimal— onlyrowCount,executionTimeMs,affectedRows, and a preview of the first row. Ideal for INSERT/UPDATE/DELETE confirmation, COUNT queries, polling. Saves ~90-95% tokens.normal(default) — full rows, but each cell truncated tomax_cell_byteswith a…(+NB)marker. Preserves table structure. Saves ~60-80% tokens on wide rows.full— entire result untouched. Use when you need the complete value of every cell.
Typical savings on SELECT * FROM blog_posts LIMIT 100 where content is ~2KB HTML per row (~200KB total):
For a head-to-head comparison against raw
psqlwith measured numbers, see Native alternatives below.
Recovering the full result: every compressed response includes a call_id. If you need the complete cells later, call inspect_last_query({ call_id }) — without re-executing the SQL, preserving DB load and any side-effects. Results are kept in a 20-slot ring buffer and persisted to ~/.database-mcp/last-queries/ with a 1-hour TTL.
Native alternatives: real token cost
How this MCP compares against the native options Claude Code has when database is not available (Bash + psql, sqlite3, mysql CLI, etc.).
TL;DR: compared to raw psql, execute_query saves between 78% and 96% of context tokens depending on the mode, with no loss of debugging information. Measured on a real call to SELECT * FROM blog_posts LIMIT 5 on a PostgreSQL table with a content column of ~1 KB of HTML per row:
Why this table's numbers differ from the "Compression modes" section above: these come from a 5-row real-world query, while the previous table extrapolates to a 100-row result with heavier content. Trend and order of magnitude are the same.
Notes:
- Raw
psqloutput gets worse as rows grow — JSONB and long TEXT columns have no native filter. The MCP cell-truncation preserves structure (row count + column list) while collapsing heavy cells with a…(+NB)marker. inspect_last_queryrecovers the complete result without re-running the SQL. Withpsqlyou would have to re-execute, paying DB CPU again and risking re-triggering side-effects onRETURNINGclauses.- The MCP also adds features that have no direct native equivalent: connection groups scoped to project directories, automatic rollback snapshots on mutations, query history, schema introspection via MCP Resources, and dump/restore.
- Schema context is added at the end of the response when relevant (default
truefornormal/full). Disable withinclude_schema_context: falseif the agent already knows the schema. - Every registered MCP adds a fixed overhead of ~300-600 tokens per session (its instructions block + tool names). Typical break-even: 1 real query per session.
Dump and restore
Full database backup in SQL format — structure only or structure + data.
Generated SQL handles DROP TABLE IF EXISTS, FK disable/enable, and dialect-aware DDL.
Query history
Every query logged per-project with timestamp, connection, execution time, and result type.
Export and import connections
Tool Reference
33 tools in 8 categories, plus 2 MCP Resources:
Resources: db://schema · db://tables/{tableName}/schema
Tip: You never need to call these tools directly. Just describe what you want and the AI picks the right one.
Storage
Storage is split into two locations by design. This separation is intentional and solves a real problem: your credentials belong to you, your project history belongs to the project.
Global: ~/.database-mcp/ — groups, connections, credentials, and settings. Lives in your home directory. Never inside a project. Never in git. Never shared with anyone unless you explicitly export them.
Per-project: {project}/.database-mcp/ — query history, rollback snapshots, and database dumps. Lives inside the project directory and is automatically added to .gitignore on first write.
The result: you can share a project repo freely — collaborators get the history and rollback structure, but zero credentials. They create their own connections and groups locally.
Configuration
Configurable from the conversation or via environment variables:
Priority: env var > saved config > default.
Warning: If you override
DATABASE_MCP_DIRto a path inside a git repository, add.database-mcp/to your.gitignoreto avoid pushing credentials.
Architecture
- Zero runtime deps beyond
@modelcontextprotocol/sdkandzod - Strict TypeScript — no
any - Dynamic driver loading —
import('postgres')/import('mysql2/promise')/import('sql.js')at runtime - < 60KB bundled via tsup
- Factory pattern —
createServer(storageDir?, projectDir?)for isolated test instances
來源:README.md,提交 b40119f
工具
0版本歷史
1- v0.1.14最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分