mcp-sql-analyst
Allows AI agents to safely explore and query SQLite databases read-only: list tables with row counts, describe table schemas with keys and sample rows, and execute single SELECT queries with timeouts and row caps.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mcp-sql-analyst
A Model Context Protocol (MCP) server that lets any AI agent — Claude Desktop, Cursor, VS Code agents, or your own LangGraph/OpenAI-Agents app — explore and query a SQL database safely.
Giving an LLM raw database access is risky. This server exposes a small set of well-described tools and enforces read-only access in two independent layers, so a prompt-injected or confused model still can't modify data or run away with resources.
How it works
sequenceDiagram
participant U as User
participant A as AI agent (MCP client)
participant S as mcp-sql-analyst
participant D as SQLite (read-only)
U->>A: "Which category made the most revenue in Q2?"
A->>S: list_tables()
A->>S: describe_table("order_items"), describe_table("products")
A->>S: run_query("SELECT p.category, SUM(...) ...")
S->>S: Layer 1: static guard (single SELECT, no DDL/DML)
S->>D: Layer 2: ro connection + authorizer + timeout + row cap
D-->>S: rows
S-->>A: {columns, rows, truncated, elapsed_ms}
A-->>U: Answer with the numbersRelated MCP server: MCP Data Bridge
Tools
Tool | Purpose |
| Tables and row counts — the agent's starting map |
| Columns, types, PK/FKs and sample rows, so the model never guesses column names |
| One read-only |
| Whole schema as JSON for clients that preload context |
Safety model
Layer | Control |
Static guard | Comments stripped, string literals masked, single statement only, must start with |
Connection | SQLite opened with |
Authorizer |
|
Resources | Progress-handler timeout (default 5 s) and hard row cap (default 200, with |
Tests prove the database layer rejects writes even if the static guard is bypassed.
Quickstart
pip install -e ".[dev]"
python scripts/seed_db.py data/shop.db # demo e-commerce DB (customers, products, orders, items)
SQL_ANALYST_DB=data/shop.db mcp-sql-analyst # stdio transport
SQL_ANALYST_DB=data/shop.db mcp-sql-analyst --http # streamable HTTP transportUse with Claude Desktop
{
"mcpServers": {
"sql-analyst": {
"command": "mcp-sql-analyst",
"env": { "SQL_ANALYST_DB": "/absolute/path/to/data/shop.db" }
}
}
}Then ask: "What's the monthly revenue trend, and which city has the highest return rate?"
Configuration
Env var | Default | Meaning |
|
| Path to the SQLite file |
|
| Max rows returned per query |
Tests
pytest -q # guardrail cases, read-only enforcement, and end-to-end MCP tool callsRoadmap
Postgres backend using a read-only role and
statement_timeoutQuery-plan cost check before execution
Per-table / per-column allow-lists for PII
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Database guardrails for AI agents: check SQL against your Vericto rules before it runs.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to safely query SQL databases through read-only tools for describing entities, reading records, and aggregating records, with view-based access and fail-closed per-user row-level security.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to securely discover database schemas and execute read-only SQL queries through guardrailed tools that block mutations and clamp result sizes.1MIT
- AlicenseAqualityNot gradedmaintenanceEnables AI assistants to safely explore and query MySQL, MariaDB, PostgreSQL, SQLite and StarRocks databases through read-only tools for schema listing, table description, schema search, row sampling, query execution, and plan explanation. Enforces least-privilege accounts, engine-level read-only sessions with timeouts, parsed SQL guardrails, and column masking so runaway or unsafe queries are refused.8MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely explore and query SQL databases through read-only, AST-checked SQL, database-enforced read-only transactions, timeouts, row caps, PII masking, and audit logging.MIT