db-assistant-mcp
MCP 数据库助手:为 Claude Code / Cursor / Codex 等 AI 编程工具提供 PostgreSQL / MySQL 的只读数据库能力。默认只读、强制安全边界、可审计。
安装
# 方式一:从 PyPI 安装(发布后)
pip install db-assistant-mcp
# 方式二:源码开发安装
uv pip install -e .
# 离线/内网:构建并安装 wheel
python scripts/build_wheel.py
pip install dist/db_assistant_mcp-*.whl
快速开始
export DB_ASSISTANT_CONFIG="$HOME/.config/db-assistant/config.toml"
# 管理连接(交互式输入密码,不回显)
db-assistant add postgres --name local-dev --host 127.0.0.1 --dbname app --user root --mode full
db-assistant list
db-assistant test local-dev
# 以 stdio 模式启动 MCP Server
python -m db_assistant_mcp
# 以 streamable HTTP 模式启动(远程共享部署,需先配置 [http] token_env)
# export DB_ASSISTANT_HTTP_TOKEN="$(openssl rand -hex 32)"
# python -m db_assistant_mcp --transport streamable-http --host 0.0.0.0 --port 8000
在 Cursor / Claude Desktop 的 MCP 配置中加入:
{
"mcpServers": {
"db-assistant": {
"command": "db-assistant-mcp",
"env": {
"DB_ASSISTANT_CONFIG": "/path/to/config.toml"
}
}
}
}
工具
| 工具 | 说明 |
|---|---|
list_databases |
列出已配置的连接 |
list_tables |
列出连接下的表/视图与行数估算(含注释与类型) |
get_table_schema |
获取表结构:列/类型/主外键/索引/注释 |
search_schema |
模糊搜索表/列(命中 glossary 中文语义词,含 pattern 展开) |
execute_query |
只读执行 SELECT / WITH / EXPLAIN |
explain_query |
查看执行计划(analyze / format: raw、tree、markdown) |
translate_sql |
SQL 方言转换(postgres ↔ mysql,产物只读回验) |
refresh_schema |
主动失效 schema 缓存 |
ping |
连接健康检查 |
资源:db://{name}/schema、db://{name}/tables、db://{name}/semantic。
安全设计
- 仅放行只读语句(SELECT / WITH / EXPLAIN / SHOW),基于 SQL 解析器(sqlglot)校验,解析失败即拒绝(fail-closed)
- 拒绝多语句、嵌套写入、事务控制、危险函数(pg_read_file、pg_sleep、LOAD_FILE 等)
- 行数上限 + 查询超时 + 并发限制
- 敏感列脱敏(
***)与排除列/表隐藏 - 全量审计日志(file / stdout / webhook)
- 凭据仅通过环境变量或 AES-256-GCM 加密存储
文档
Metadata
Release files for db-assistant-mcp 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| db_assistant_mcp-0.4.0.tar.gz | 260.2 kB | Without provenance | Details for db_assistant_mcp-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| db_assistant_mcp-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for db_assistant_mcp-0.4.0-py3-none-any.whl |
Total release size: 337.4 kB
Release files / db_assistant_mcp-0.4.0.tar.gz
| Download URL | db_assistant_mcp-0.4.0.tar.gz |
|---|---|
| Size | 260.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b83c7744d849d4b4f8e40d693a7dde1a30356cb57bf99835472023a6f684781
|
|
BLAKE2b-256 checksum How to use checksums |
e29408c7fbcc684f9a90c24fa74afc83acbb5796c12536f22b0c3108d6bc5b09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / db_assistant_mcp-0.4.0-py3-none-any.whl
| Download URL | db_assistant_mcp-0.4.0-py3-none-any.whl |
|---|---|
| Size | 77.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31d27640a0054b1cc0199c0008bd6bee9d53ed095bd0051f361e8bbd8825ed84
|
|
BLAKE2b-256 checksum How to use checksums |
e54ea3deb60213b249951b9f4c179452b288b12b58a5fe6945dc07bf5e257d6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for db-assistant-mcp 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.