DB Insights MCP Server
Enables AI assistants to query SQL databases safely with read-only access, allowing schema discovery and SELECT queries while blocking writes and DDL operations.
README
DB Insights MCP Server
An MCP server that lets an AI assistant answer questions about a SQL database —
read-only, by design. The model can discover the schema and run SELECT
queries through a guarded interface, but it physically cannot insert, update, or
drop anything. The server is the safety wall between the model and your data.
MCP (Model Context Protocol) is the standard way to give an AI client — Claude Desktop, Cursor, an agent — access to external tools and data. This server exposes a database as a set of safe tools any MCP client can use.
Why read-only is the whole point
"Let our AI talk to our database" is easy to ask for and scary to ship. A model
(or a prompt injection riding in on some untrusted text) might try
DROP TABLE customers. This server makes that impossible: every query is checked
before it runs, and anything that isn't a single read-only SELECT is rejected.
Rejected: Only SELECT (or WITH ... SELECT) queries are allowed.
The guard (server/safety.py) strips comments, allows a single statement only,
requires it to start with SELECT/WITH, blocks write and DDL keywords, and
blocks SELECT ... INTO. On top of that, queries run in a connection that never
commits (and SET TRANSACTION READ ONLY on Postgres), and every result is capped.
Architecture
MCP client (Claude Desktop / MCP Inspector / agent)
│ MCP over stdio (local) or Streamable HTTP (deployed)
▼
this server (FastMCP)
├─ tools: list_tables · describe_table · sample_rows · run_query
├─ resource: schema://overview (schema, loaded into the model's context)
├─ prompt: explore(question) (a starter prompt template)
├─ safety: SELECT-only · single statement · no DDL/DML · row cap · no commit
└─ SQLAlchemy ──> SQLite (seeded sample DB) | Postgres/MySQL via DATABASE_URL
The client's model decides which tools to call and writes the SQL. This server validates and runs it. The server never calls an LLM itself — so it needs no API key. Following MCP's own distinction: the schema is a resource (data read into context), and the queries are tools (actions).
Run and test it
1. Install dependencies
pip install -r requirements.txt
2. Test with MCP Inspector (no LLM needed)
Use forward slashes — backslashes cause a path mangling bug on Windows:
mcp dev server/main.py
That opens the Inspector in your browser. Click Connect, then go to the
Tools tab. Call list_tables, then run_query with something like:
SELECT p.category, ROUND(SUM(oi.quantity * oi.unit_price), 2) AS revenue
FROM order_items oi JOIN products p ON p.id = oi.product_id
GROUP BY p.category ORDER BY revenue DESC;
Then try DELETE FROM customers and watch it get rejected.
Windows note: if the Inspector shows a
VIRTUAL_ENVwarning on connect, that's harmless —uvignores the active venv and manages its own environment.
3. Wire up Claude Desktop
Open the config via Claude Desktop → profile icon → Settings → Developer → Edit Config.
Or navigate to it directly:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Set cwd to the absolute path of this folder and command to the full path of
the Python executable in your virtual environment:
{
"mcpServers": {
"db-insights": {
"command": "C:\\path\\to\\venv\\Scripts\\python.exe",
"args": ["-m", "server.main"],
"cwd": "C:\\path\\to\\db-insights-mcp"
}
}
}
Fully quit Claude Desktop (system tray → Quit or clear from Task-manager), then relaunch it. Ask something
like "which product category made the most revenue?" and it will call the tools
on its own.
4. Run the tests
pytest
SQLite by default, your database by env var
One setting, no code change:
| Variable | Default | What it does |
|---|---|---|
DATABASE_URL |
sqlite:///./sample.db |
seeded sample DB; point at Postgres for real |
MAX_ROWS |
200 |
hard cap on rows any query returns |
TRANSPORT |
stdio |
stdio locally, streamable-http to deploy |
For a real database:
DATABASE_URL=postgresql+psycopg://user:pass@host:5432/dbname
Seeding only ever touches the default SQLite file — it never writes to a database you point it at.
When this helps (and when it doesn't)
Good fit: internal analytics assistants, "ask our data in plain English," letting an agent explore a reporting database safely.
Be careful when: the database holds sensitive rows the model shouldn't read (the
guard stops writes, not reads — scope the connection's user/permissions for
that), or queries can be expensive (set MAX_ROWS and a DB-side statement timeout).
Notes
- Built on the official MCP Python SDK (
mcp.server.fastmcp.FastMCP). - SSE transport is deprecated upstream; this uses stdio and Streamable HTTP.
- The guard is intentionally strict — a literal like
SELECT 'DROP'is refused. Better a rare false reject than one destructive query slipping through.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器