chat-sql

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.

Category
Visit Server

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

Databaserun_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 examplesfind_similar_queries, save_query_example, delete_query_example (needs a pgvector DB; set CHATSQL_RAG_DBKEY). Local computerun_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.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured