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.3.1.tar.gz (251.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.1-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: db_assistant_mcp-0.3.1.tar.gz
  • Upload date:
  • Size: 251.6 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.3.1.tar.gz
Algorithm Hash digest
SHA256 dafa4c494ad8b61320d61e5b8a018c47ca4234a7da03cd43fca74a1d17661a6e
MD5 0f22d48b73fae9d23f700a999376a202
BLAKE2b-256 d774ebef5c4fdef2ed83a9872f637442d42d24d835be7b659a30d28c9d690cf5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: db_assistant_mcp-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 76.5 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2e464eeecdbce4782a3a7e8de04d4c9f5021feb144cabf86c09fae65313981a
MD5 7f6d2001965d6c852cd63470e224098f
BLAKE2b-256 6348d42ef758fcdb5287f8f8701e41369a502cb83518306325feb19bf56bcbcc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.1 This release

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