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 模糊搜索表/列
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.3.0.tar.gz (128.6 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.3.0-py3-none-any.whl (75.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: db_assistant_mcp-0.3.0.tar.gz
  • Upload date:
  • Size: 128.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","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.3.0.tar.gz
Algorithm Hash digest
SHA256 3d67c9d7195299c143d9907f9cdcdc4aed93498fda9d797d45985ab0be761982
MD5 35c5248efaaee5bef871e133b98fc47c
BLAKE2b-256 c8df53a131531ff90ab2a982e212fe5f1b72be50adb41314814cb44276b9af11

See more details on using hashes here.

File details

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

File metadata

  • Download URL: db_assistant_mcp-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 75.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b83da2b330ca494d2171339a271fa1cf9855097a43537228e94cbd50b2e216ad
MD5 3ff5395bec89e34e3b7741df9844ccbf
BLAKE2b-256 1663b7ecda02169b63f48d8a2e31a0637354b80e053695063240f50cbd334ac6

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

0.3.1

2 files

This release

0.3.0 This release

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