sql-guard-mcp
sql-guard-mcp
为 AI 代理提供只读 SQL,并带有多层安全防护。
让 LLM 代理直接访问原始数据库,无异于埋下隐患。这个 MCP 服务器通过四个独立的防护层向代理开放 SQLite 数据库,因此代理最坏的情况也只是读取得慢一些——而连这种情况也会被中止。
韩语文档: README.ko.md
防护层
防护层 | 阻止的内容 | 实现方式 |
查询校验 | 写入、schema 变更、通过堆叠语句进行的注入 | 仅允许单个 |
表级白名单 | 读取敏感表(PII、凭据) | 将 |
行数上限 | 淹没上下文窗口 | 每个查询都会被包装为带服务端 |
执行上限 | 失控查询(笛卡尔连接) | SQLite 进度处理器的看门狗在 N 个 VM 步后中止查询,并给出可操作的提示信息 |
操作系统级只读 | 以上所有防护失效时 | 使用 |
这一设计原则源自为生产环境中的 LLM 代理构建决策防护的经验:不要指望模型会小心谨慎——要让粗心大意变得不可能,并让每一条拒绝消息都告诉代理应该怎么做。
Related MCP server: sqlite-analyst
工具
sql_list_tables— 可见的表(已应用白名单)sql_describe_table— 列、类型、行数sql_query— 受防护的只读查询sql_guard_status— 当前防护配置(调试时透明可见)
演示
已连接 Claude Desktop,正在查询内置的广告活动演示数据库——并拒绝了一个删除请求:

代理可以自由探索和聚合(“哪个活跃广告活动的 CTR 最高?”),但当被要求清空 campaigns 表时,防护层会拒绝请求,代理会解释原因——只读是设计使然,由代码强制执行,而非依赖提示词。
安装
除 MCP SDK 之外零依赖——内置一个合成的广告活动演示数据库,首次运行时自动创建。
pip install -e .
# optional configuration
export SQLGUARD_DB="/path/to/your.db" # default: bundled demo
export SQLGUARD_ALLOWED_TABLES="campaigns,daily_stats" # default: all tables
export SQLGUARD_MAX_ROWS="200"Claude Desktop
{
"mcpServers": {
"sql-guard-mcp": {
"command": "sql-guard-mcp",
"env": { "SQLGUARD_ALLOWED_TABLES": "campaigns,daily_stats" }
}
}
}然后这样问:“上周哪个活跃广告活动的 CTR 最高?”——代理会在防护框架内探索 schema 并发起查询。试着让它删除某些内容;看看它的拒绝说明。
测试
pip install -e ".[dev]"
pytest # guard validation + execution enforcement, no external DB needed测试涵盖对抗性用例:堆叠语句、以 SELECT 开头的写入语句、通过 JOIN 绕过白名单、尝试用用户提供的 LIMIT 覆盖限制,以及被 VM 步看门狗中止的笛卡尔连接失控查询。
许可证
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables safe, read-only SQL access to SQLite databases for AI agents, allowing schema exploration and SELECT queries with defense-in-depth protections.3MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to explore and query SQLite databases through read-only tools, with defense-in-depth sandboxing preventing any data modifications.MIT
- FlicenseAqualityCmaintenanceEnables AI agents to safely explore and query a SQLite database in read-only mode, allowing them to inspect schema and run analytical SQL queries without risking data modification.3-
- FlicenseAqualityCmaintenanceEnables 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-