chat-sql
MCP server that enables natural-language SQL queries across multiple databases (ClickHouse, Teradata, PostgreSQL, MySQL, SQL Server, DB2, Oracle, MongoDB) with dialect-correct SQL generation, PII masking, and security-by-construction controls.
README
chat_sql
A governed natural-language → SQL agent for Claude, delivered as an MCP server. Ask a question in plain English; the agent selects the right database, writes dialect-correct SQL, runs it through security-enforcing tools, and returns results — across ClickHouse, Teradata, PostgreSQL/GaussDB, MySQL, SQL Server, DB2, Oracle, and MongoDB.
Its defining feature is that the LLM is treated as untrusted. It is structurally unable to read raw PII, to modify any table it did not create, or to reach a database outside the sanctioned tools — regardless of how it is prompted.
Why it's safe by construction
LLM (untrusted)
│ MCP over stdio — tool calls only
▼
mcp_server.py ── UNPRIVILEGED face ──────────────────
• no credentials, cannot import a connector
• forwards every DB call over a local UNIX socket
• run_python: no creds, no network (sandboxed)
│ UNIX socket (0600)
▼
dbgateway.py ── PRIVILEGED broker ───────────────────
• the only holder of credentials + connectors
• statement guard → write-guard → PII masking
• returns sanitized rows only
| Guarantee | How |
|---|---|
| No raw PII to the LLM | Results are masked in the broker: a PII registry + column-name heuristics (default-deny) + a cell-level pattern backstop. Identifiers return as sha256 hashes or ***; aggregates return raw. |
| No writes to tables it didn't create | Writes/creates allowed only on tmp_ scratch tables recorded in an ownership ledger; everything else is refused before touching the DB. |
| No direct connector access | The connectors package won't import without a secret token that lives only in the broker — not in the LLM-facing process, not in run_python. |
Full threat model and control matrix: docs/SECURITY.md.
Quick start
git clone <your-fork> chat_sql && cd chat_sql
uv venv && uv pip install -r requirements.txt # install the DB drivers you need
cp database_creds.example.json database_creds.json # add your databases
cp pii_policy.example.yaml pii_policy.yaml # classify your PII columns
cp .env.example .env # set CHATSQL_PII_SALT etc.
Register the MCP server with your client (.mcp.json or ~/.claude/settings.json):
{
"mcpServers": {
"chat-sql": {
"command": "uv",
"args": ["--directory", "/path/to/chat_sql", "run", "python", "mcp_server.py"]
}
}
}
For airtight run_python isolation, install bubblewrap (bwrap) or run the
broker as a separate OS user — see docs/SECURITY.md §6.
Configuring databases
Each entry in database_creds.json has a short code (the db_key you pass to
tools) and a service that selects the connector:
{
"pg_demo": {
"service": "postgres", "alias": "demo analytics",
"host": "localhost", "port": 5432,
"user": "…", "password": "…", "database": "analytics", "schema": "public"
}
}
Supported service values: clickhouse, teradata, mysql, postgres
(psql/gaussdb), mssql, db2, oracle, mongo.
Classifying PII
pii_policy.yaml pins which columns are masked and how (hash | redact). The
broker also applies name-heuristics (default-deny on identifier-looking columns)
and a raw-pattern backstop, so unlisted PII is still caught — but pin known PII
explicitly. See pii_policy.example.yaml.
Tools
Database — run_query, run_query_file, export_to_csv, load_file,
drop_table, list_databases, explain_query, table_info, search_schema,
long_running_queries, kill_query.
RAG examples — find_similar_queries, save_query_example,
delete_query_example (needs a pgvector DB; set CHATSQL_RAG_DBKEY).
Local compute — run_python (sandboxed), notify.
Optional groups (off by default; enable with CHATSQL_*_ENABLED=1) —
WhatsApp (whatsapp_*, transcribe_audio), email (send_email),
Jupyter remote-exec (jupyter_*), wiki/memory (wiki_*).
Use it as a Claude skill
skills/chat-sql/SKILL.md packages the workflow so you can drop it into a
.claude/skills/ directory and invoke it by name. See that file for details.
Running the security tests
uv pip install sqlglot pyyaml pytest
python -m pytest tests/ -v
The suite proves every control (PII masking, write-guard, connector isolation, statement guard) with no live database required.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。