sqlite-analyst
Provides safe, read-only access to a SQLite database file: lists the available tables, describes a table's columns and schema, and executes a single validated SELECT/WITH query (blocked writes, 5-second timeout, 200-row cap), plus a schema://database resource for schema discovery.
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 Agent: Chat with Your Database
Two pieces that work together, and each is useful on its own:
sqlite-analyst: a Model Context Protocol (MCP) server that gives any AI client safe, read-only access to a SQLite database. It works with Claude Code, Claude Desktop, IDEs, or your own agents.A LangGraph agent that connects to that server, discovers its tools at runtime, and answers business questions by exploring the schema, writing SQL, fixing its own errors and explaining the result.
Example output:
$ python -m mcp_sql_agent "Which product category made the most revenue, and how did it trend month by month?"
Connected to MCP server. Tools: list_tables, describe_table, run_query
> list_tables
> describe_table orders
> describe_table order_items
> run_query SELECT p.category, SUM(oi.quantity * oi.unit_price) AS revenue ...
> run_query SELECT strftime('%Y-%m', o.order_date) AS month, ...
**Electronics** is the top category with $273,235 in completed-order revenue,
more than double the next category (Home, $114,623) ...Architecture
flowchart LR
subgraph Agent["LangGraph agent (MCP client)"]
A[agent node<br/>Claude] -->|tool calls| T[ToolNode]
T -->|results / errors| A
end
T <-->|MCP over stdio| S
subgraph S["sqlite-analyst MCP server"]
L[list_tables]
D[describe_table]
Q[run_query]
R[(schema:// resource)]
end
S --> DB[(SQLite, read-only)]
O[Claude Code / Claude Desktop / IDE] <-->|MCP| SRelated MCP server: MCP SQLite Server (Read-Only)
Safety: defense in depth
The model is never trusted to write safe SQL. The server enforces read-only access in four independent layers:
The database is opened with SQLite's
mode=roURI.A SQLite authorizer callback denies every operation except reads, at the engine level.
Only a single
SELECT/WITHstatement is accepted.A progress handler kills queries after 5 seconds, and results are capped at 200 rows to protect the model's context window.
The tests try DROP, ATTACH, statement stacking and write-CTEs, and all of them are blocked.
Quickstart
git clone <this-repo> && cd mcp-sql-agent
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # add your ANTHROPIC_API_KEY
python -m mcp_sql_agent.seed # creates data/shop.db (sample e-commerce data)
python -m mcp_sql_agent # interactive chat with memory for follow-ups
python -m mcp_sql_agent "Who are our top 5 customers by lifetime revenue?"
python -m mcp_sql_agent --db path/to/your.db # use your own SQLite databaseUse the server from Claude Code or Claude Desktop
claude mcp add sqlite-analyst -- python -m mcp_sql_agent.server --db /absolute/path/to/shop.dbClaude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"sqlite-analyst": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["-m", "mcp_sql_agent.server", "--db", "/absolute/path/to/shop.db"],
"cwd": "/absolute/path/to/mcp-sql-agent"
}
}
}What this project demonstrates
Building an MCP server: tools, a resource (
schema://database) and a reusable prompt (analyze) with the officialmcpSDKConsuming MCP from an agent:
langchain-mcp-adaptersturns MCP tools into LangGraph tools at runtimeThe ReAct loop as an explicit graph:
agent ⇄ toolswithtools_condition, plus a checkpointer for multi-turn memoryError recovery: SQL errors are returned to the model as tool results, so it can fix its query and retry (covered by a test)
Secure tool design for LLMs, as described above
Tests
pytestThey cover the safety layers, a real MCP round-trip over stdio, and the full agent loop with a scripted model, including recovery from a bad query.
Ideas to extend
Add a PostgreSQL backend that uses a read-only role
Add a
charttool that returns a PNG with matplotlibExpose the server over Streamable HTTP for remote clients
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
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- AlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to explore and query SQLite databases through read-only tools, with defense-in-depth sandboxing preventing any data modifications.MIT
- FlicenseAqualityDmaintenanceEnables AI agents to safely inspect and query a SQLite database through read-only MCP tools for listing tables, describing schemas, and running paginated SELECT queries.3-
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to safely query and explore SQLite databases through read-only, guard-protected tools that block writes, sensitive table access, and runaway queries.1MIT
- AlicenseBqualityNot gradedmaintenanceEnables AI assistants to safely run read-only SQL against SQLite databases through whitelist-validated queries, capped result sets, and confined file paths. It also exposes schema inspection so models can discover tables and columns before querying.2MIT