Skip to main content

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}/schemadb://{name}/tablesdb://{name}/semantic

安全设计

  • 仅放行只读语句(SELECT / WITH / EXPLAIN / SHOW),基于 SQL 解析器(sqlglot)校验,解析失败即拒绝(fail-closed)
  • 拒绝多语句、嵌套写入、事务控制、危险函数(pg_read_file、pg_sleep、LOAD_FILE 等)
  • 行数上限 + 查询超时 + 并发限制
  • 敏感列脱敏(***)与排除列/表隐藏
  • 全量审计日志(file / stdout / webhook)
  • 凭据仅通过环境变量或 AES-256-GCM 加密存储

文档

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_assistant_mcp-0.4.0.tar.gz (260.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_assistant_mcp-0.4.0-py3-none-any.whl (77.2 kB view details)

Uploaded Python 3

File details

Details for the file db_assistant_mcp-0.4.0.tar.gz.

File metadata

  • Download URL: db_assistant_mcp-0.4.0.tar.gz
  • Upload date:
  • Size: 260.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for db_assistant_mcp-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8b83c7744d849d4b4f8e40d693a7dde1a30356cb57bf99835472023a6f684781
MD5 9342880940477f0cad757f06aec6c1ae
BLAKE2b-256 e29408c7fbcc684f9a90c24fa74afc83acbb5796c12536f22b0c3108d6bc5b09

See more details on using hashes here.

File details

Details for the file db_assistant_mcp-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: db_assistant_mcp-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 77.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for db_assistant_mcp-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31d27640a0054b1cc0199c0008bd6bee9d53ed095bd0051f361e8bbd8825ed84
MD5 34a96cf3df0e6d6f2ae5c44dcbff049f
BLAKE2b-256 e54ea3deb60213b249951b9f4c179452b288b12b58a5fe6945dc07bf5e257d6b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page