sqlite-mcp-server

sqlite-mcp-server

Read-only MCP server for SQLite databases, enabling AI assistants to safely query and inspect database schemas without write access.

Category
访问服务器

README

sqlite-mcp-server

An MCP (Model Context Protocol) server that gives an AI assistant safe, structured access to a SQLite database.

Point it at any .db file and an MCP-compatible client (Claude Desktop, Claude Code, etc.) can inspect the schema and query it directly.

Why this one

  • Read-only by default. The assistant can SELECT all it wants, but can't INSERT/UPDATE/DELETE/DROP anything unless you explicitly turn writes on with an environment variable.
  • Every statement is checked before it runs — not just trusted blindly. Stacked statements (SELECT 1; DROP TABLE users;) are rejected outright.
  • Results are capped (1000 rows by default) so a SELECT * on a huge table can't flood the assistant's context window.
  • Schema-aware. The assistant can list tables, describe columns, and read the full schema before it ever writes a query — fewer guesses, fewer mistakes.

Install

git clone <this-repo-url>
cd sqlite-mcp-server
pip install -r requirements.txt

Try it immediately with sample data

python3 seed_sample_db.py

This creates ./data/app.db with two small tables (customers, orders) so you can test the server without hooking it up to a real database first.

Run it standalone

python3 server.py

It talks MCP over stdio, so it's meant to be launched by an MCP client, not run interactively on its own.

Connect it to Claude Desktop

Add this to your Claude Desktop MCP config (see claude_desktop_config.example.json in this repo for the full snippet), replacing the paths with the absolute path to where you cloned this repo:

{
  "mcpServers": {
    "sqlite-explorer": {
      "command": "python3",
      "args": ["/absolute/path/to/sqlite-mcp-server/server.py"],
      "env": {
        "MCP_SQLITE_DB_PATH": "/absolute/path/to/sqlite-mcp-server/data/app.db"
      }
    }
  }
}

Restart Claude Desktop, and the assistant will have list_tables, describe_table, query, and execute tools available for that database.

Configuration

Set these as environment variables (see .env.example):

Variable Default Meaning
MCP_SQLITE_DB_PATH ./data/app.db Path to the SQLite file. Created automatically if missing.
MCP_ALLOW_WRITE false Set to true to allow the execute tool to run write statements.
MCP_MAX_ROWS 1000 Maximum rows a single query call can return.

Tools exposed

Tool Description
list_tables() List every table in the database.
describe_table(table) Columns, types, nullability, primary keys, and indexes for one table.
query(sql, params?) Run a read-only SELECT/PRAGMA/EXPLAIN/WITH statement.
execute(sql, params?) Run a write statement. Only works if MCP_ALLOW_WRITE=true.

Plus a resource, schema://database, exposing the full CREATE TABLE statements for the database, so the assistant can read the whole schema at a glance.

Safety model

  • query() only accepts SELECT/PRAGMA/EXPLAIN/WITH. Anything else is rejected with an error before it touches the database.
  • execute() is a hard no-op — it raises PermissionError — unless the server was started with MCP_ALLOW_WRITE=true. This means an assistant can never modify or destroy data unless a human operator deliberately opted in.
  • Multiple statements in one call (SELECT 1; DROP TABLE users;) are rejected outright, whether writes are enabled or not.
  • Known limitation: the multi-statement check is a simple semicolon scan, not a full SQL parser, so a semicolon inside a string literal (SELECT ';' AS x) will also be (harmlessly) rejected. Being overly cautious here was a deliberate trade-off over a more permissive parser that could be tricked into missing a real stacked statement.

Development

The core SQL-safety logic lives in sql_guard.py, which has zero dependency on the mcp package, so it can be tested without installing the full SDK:

python3 -m unittest discover -s tests -v

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选