A2db

io.github.agentic-eng由 GitHub 账号 agentic-eng 发布v0.2.1更新于 Oct 27, 2026

Safe, read-only database access for AI agents. 5 databases, batch queries, SQLGlot.

已验证STDIO仅桌面数据库数据与分析

概览

AI 生成的概览

A2db 让 AI 助手以只读方式安全访问 PostgreSQL、SQLite、MySQL/MariaDB、Oracle 和 SQL Server,并可在一次调用中执行多条命名查询。

可以做什么
  • 对指定连接执行批量命名查询,支持分页,返回紧凑的 TSV 或 JSON 结果
  • 浏览数据库结构:按详细程度列出表和字段
  • 管理已保存的连接:新增(先连接验证)、列出(不暴露密钥)、删除
  • 启动时预注册连接,助手可立即查询
  • 也可通过命令行执行临时查询和查看结构
适用场景
适合让助手基于一个或多个关系型数据库回答问题,同时不允许其修改数据;尤其适用于每轮需要多条查询,或希望连接只配置一次而不必每次调用重复填写的场景。
运行要求
本机安装 Python 包 a2db(pip install a2db),由 MCP 客户端以 stdio 进程启动。需要每个连接的数据库 DSN,密码以环境变量形式引用(如 DB_PASSWORD),在建立连接时才展开。需要能访问数据库主机的网络。
安装前请注意
连接以 TOML 文件保存在用户配置目录中,本机会留存数据库地址。只读通过 SQL 解析强制执行,但 README 仍建议使用只读数据库账号。核心已实现写入功能,但尚未通过 MCP 开放。助手可以新增和删除已保存的连接,查询结果会离开数据库进入模型上下文。

安装

在 SourceWeft 中

  1. 打开 控制台中的 A2db,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

🗄️ a2db

Agent-to-Database

Give AI agents safe, read-only access to your databases. One call, multiple queries, clean results.

5 databases · batch queries · pre-configured connections · SQLGlot read-only

[PyPI] [Python versions] [License] [CI] [MCP Registry]

Quick Start · MCP Tools · Security · Comparison · Setup


Agent: "Show me active users and their recent orders"  ↓a2db execute → 2 queries, 1 call, structured results  ↓Agent: "Got it — 847 active users, avg order $42.50"

Why a2db?

Most database MCP servers make you run one query at a time, repeat connection details on every call, and return results double-encoded inside JSON strings. a2db fixes all of that:

  • Pre-configured connections — define databases in .mcp.json with --register, agent queries immediately
  • Batch queries — run multiple named queries in a single tool call
  • Default connection — set connection once, use it across all queries in a batch
  • Clean output — structured JSON envelope with compact TSV data and per-query timing (see why TSV?)
  • Read-only enforced — SQLGlot AST parsing blocks all write operations
  • All drivers bundled — pip install a2db and you're done
  • Secrets stay in env — ${DB_PASSWORD} in DSNs, expanded only at connection time

Supported Databases

DatabaseDriverAsync
PostgreSQLasyncpgnative
SQLiteaiosqlitenative
MySQL / MariaDBmysql-connector-pythonwrapped
Oracleoracledbwrapped
SQL Serverpymssqlwrapped

Quick Start

bash
pip install a2db

As an MCP Server (recommended)

Claude Code (with pre-configured connection):

bash
claude mcp add -s user a2db -- a2db-mcp \  --register myapp/prod/main 'postgresql://user:${DB_PASSWORD}@host/mydb'

Claude Code (minimal — agent calls login on demand):

bash
claude mcp add -s user a2db -- a2db-mcp

Claude Desktop / Cursor / any MCP client (.mcp.json):

json
{  "mcpServers": {    "a2db": {      "command": "uvx",      "args": [        "a2db-mcp",        "--register", "myapp/prod/main", "postgresql://user:${DB_PASSWORD}@host/mydb"      ],      "env": {        "DB_PASSWORD": "your-password-here"      }    }  }}

Multiple databases:

json
{  "args": [    "a2db-mcp",    "--register", "myapp/prod/main", "postgresql://user:${DB_PASSWORD}@host/maindb",    "--register", "myapp/prod/analytics", "postgresql://user:${DB_PASSWORD}@host/analytics"  ]}

--register pre-registers connections at server startup — the agent can query immediately. Passwords use ${ENV_VAR} syntax and are expanded at connection time, never stored in plaintext.

As a CLI

bash
# Save a connection (validates immediately)a2db login -p myapp -e prod -d main 'postgresql://user:${DB_PASSWORD}@localhost/mydb'
# Querya2db query -p myapp -e prod -d main "SELECT * FROM users LIMIT 10"
# JSON outputa2db query -p myapp -e prod -d main -f json "SELECT * FROM users LIMIT 10"
# Explore schemaa2db schema -p myapp -e prod -d main tablesa2db schema -p myapp -e prod -d main columns -t users
# List / remove connectionsa2db connectionsa2db logout -p myapp -e prod -d main

MCP Tools

ToolDescription
loginSave a connection — validates by connecting first
logoutRemove a saved connection
list_connectionsList connections (no secrets exposed)
executeRun named batch queries with pagination
search_objectsExplore schema — tables, columns, with detail levels

execute — the core tool

Named dict with default connection (preferred):

json
{  "connection": {"project": "myapp", "env": "prod", "db": "main"},  "queries": {    "active_users": {"sql": "SELECT id, name FROM users WHERE active = true"},    "recent_orders": {"sql": "SELECT id, total FROM orders ORDER BY created_at DESC LIMIT 5"}  }}

List format (auto-named q1, q2, ...):

json
{  "connection": {"project": "myapp", "env": "prod", "db": "main"},  "queries": [    {"sql": "SELECT COUNT(*) AS cnt FROM users"},    {"sql": "SELECT AVG(total) AS avg_order FROM orders"}  ]}

Response (TSV format — default):

json
{  "active_users": {    "data": "id\tname\n1\tAlice\n2\tBob\n3\tCharlie",    "rows": 3,    "truncated": false,    "time_ms": 12  },  "recent_orders": {    "data": "id\ttotal\n501\t129.00\n500\t49.99",    "rows": 2,    "truncated": false,    "time_ms": 8  }}

No ::text casts needed — integers, floats, timestamps, arrays, NULLs all work natively.

Error context

When a query fails with a column error, a2db enriches the message:

column "nme" does not existDid you mean: name?Available columns: id (integer), name (text), email (text), active (integer)

Why TSV?

LLM context windows are expensive. JSON row data is verbose — every row repeats every column name, adds braces, commas, and quotes. TSV is a flat grid: one header row, then just values separated by tabs.

For a 100-row, 5-column result set, TSV typically uses 40-60% fewer tokens than JSON row format. The structured JSON envelope still gives you metadata (row count, truncation status) — only the row payload is TSV.

Set format="json" if you need full structured output with column names on every row.

Security

Read-Only Enforcement

Every query is parsed by SQLGlot before execution:

  • Blocked: INSERT, UPDATE, DELETE, DROP, TRUNCATE, ALTER, CREATE, GRANT, REVOKE
  • Bypass-resistant: multi-statement attacks and comment-wrapped writes are caught at the AST level, not just keyword matching
  • Allowed: SELECT, UNION, EXPLAIN, SHOW, DESCRIBE, PRAGMA

This is defense-in-depth — you should also use a read-only database user, but a2db won't let writes through even if the user has write permissions.

Write support is implemented in the core but not yet exposed via MCP. Planned: per-connection write permissions, explicitly enabled by the human operator — not the agent. See TODO.md.

Credential Storage

Connections are saved in ~/.config/a2db/connections/ as TOML files.

  • ${DB_PASSWORD} syntax — environment variable references are stored literally and expanded only at connection time. Secrets stay in your environment, not on disk.
  • No secrets in list output — list_connections shows project/env/db and database type, never DSNs or passwords
  • Connection files are local to your machine and outside any repository

Deployment Scope

a2db currently runs as a local stdio MCP server. It inherits environment variables from the process that launches it (your shell, Claude Code, Docker). This is the standard model for local MCP servers — the same approach used by DBHub, Google Toolbox, and others.

Planned: remote HTTP transport with OAuth 2.1 per the MCP spec. For now, if running in Docker, inject secrets via environment variables at container runtime.

Comparison

Featurea2dbDBHubGoogle ToolboxPGMCPSupabase MCP
Databases5 (PG, SQLite, MySQL, Oracle, MSSQL)5 (PG, MySQL, MSSQL, MariaDB, SQLite)40+ (cloud + OSS)PG onlyPG (Supabase)
Batch queriesNamed dict + listSemicolon-separatedNoNoNo
Default connectionSet once, use for allPer-queryN/ASingle DBSingle project
Read-onlySQLGlot AST (enforced)Keyword check (config)Hint/annotationRead-only tx + regexConfig flag
Write supportPlanned (per-connection)Config flagVia tool definitionNoConfig flag
OutputJSON + TSV dataStructured textMCP protocolTable / JSON / CSVJSON
Schema discovery3 detail levelsDedicated toolPrebuilt toolsVia NL-to-SQLDedicated tools
Pre-configured--register in MCP configConfig fileYAML configEnv varCloud-managed
Credentials${ENV_VAR} in DSNDSN stringsEnv vars + GCP IAMEnv varOAuth 2.1
Drivers bundledAll includedAll includedVariesBuilt-inManaged
CLIYesNoYesYesNo
Error contextColumn suggestions + typesNoNoNoNo
LicenseApache 2.0MITApache 2.0Apache 2.0Apache 2.0

When to use what:

  • a2db — multi-DB batch queries with clean output, agent-first design, fast setup
  • DBHub — custom tools via TOML config, web workbench UI
  • Google Toolbox — GCP ecosystem, IAM integration, 40+ sources
  • PGMCP — natural-language-to-SQL for PostgreSQL (requires OpenAI key)
  • Supabase MCP — full Supabase platform management (edge functions, branching, storage)

Setup by Environment

Local (macOS / Linux)

bash
pip install a2db
# CLIa2db login -p myapp -e dev -d main 'postgresql://user:pass@localhost/mydb'
# Or add as MCP server (see Quick Start)

Docker

dockerfile
FROM python:3.12-slimRUN pip install a2dbCMD ["a2db-mcp", "--register", "myapp/prod/main", "postgresql://user:${DB_PASSWORD}@host/mydb"]
bash
docker run -e DB_PASSWORD=secret -i my-a2db-image

Secrets are injected as environment variables at runtime — never baked into the image.

CI / Automation

bash
pip install a2db
# Pre-configured — no login neededa2db-mcp --register myapp/ci/main "postgresql://ci_user:${CI_DB_PASSWORD}@db-host/mydb"
# Or use CLI directlya2db login -p myapp -e ci -d main "postgresql://ci_user:${CI_DB_PASSWORD}@db-host/mydb"a2db query -p myapp -e ci -d main "SELECT COUNT(*) FROM migrations"

Development

bash
make bootstrap   # Install deps + hooksmake check       # Lint + test + security (full gate)make test        # Tests with coverage (90% minimum)make lint        # Lint only (never modifies files)make fix         # Auto-fix + lint

License

Apache 2.0


🗄️ Agent-first database access since 2025.

Built by Denis Tomilin

来源:README.md,提交 3c33b3e

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.2.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分