mcp-devdb
mcp-devdb
面向本地开发数据库的安全、只读 MCP 服务器。编码代理经常需要查看你的开发数据库——模式、示例数据、查询计划、表大小——但一个朴素的数据库连接器会赋予它们完整的写入权限。mcp-devdb 是受保护的替代方案:一个 Model Context Protocol 服务器,通过强化的只读 SQL 防护、列掩码、结果上限和每会话查询预算来暴露内省工具。
v1 中的后端:PostgreSQL(通过 postgres)和 SQLite(通过 better-sqlite3)。适配器接口与引擎无关,因此以后可以添加 MySQL。
快速开始
在服务器将要运行的位置旁边创建
mcp-devdb.json(参见mcp-devdb.example.json):
{
"databases": {
"app": { "url": "postgres://dev:dev@localhost:5432/app_development" },
"cache": { "url": "sqlite:./data/cache.db" }
}
}运行它:
npx mcp-devdb --config ./mcp-devdb.json服务器通过 stdio 使用 MCP 协议通信;将你的 MCP 客户端指向该命令。连接字符串仅存在于配置文件或环境变量中("url": "env:MY_DB_URL",或没有配置文件时的 MCP_DEVDB_URL 回退)——模型永远无法提供连接字符串。
Claude Code
claude mcp add devdb -- npx mcp-devdb --config /absolute/path/to/mcp-devdb.jsonClaude Desktop(claude_desktop_config.json)
{
"mcpServers": {
"devdb": {
"command": "npx",
"args": ["mcp-devdb", "--config", "/absolute/path/to/mcp-devdb.json"]
}
}
}Related MCP server: MCP PostgreSQL
工具
工具 | 输入 | 返回内容 |
|
| 模式、表、视图,附带行数估算和磁盘占用大小 |
|
| 列、类型、可空性、默认值、主键、外键、索引 |
|
| 前 N 行;超过 200 字符的单元格被截断;敏感列被掩码为 |
|
| 受防护的只读查询;行数上限(200)+ 字节上限(256 KiB);消耗查询预算 |
|
| 执行计划——PostgreSQL |
|
| 数据库名称、大小、表数量、最大的表、扩展(PG) |
当只配置了一个数据库时,database 是可选的;配置了多个时,请指定你要用的那个。
配置
工作目录中的 mcp-devdb.json,或通过 --config 指定的任意路径:
{
"databases": {
"app": {
"url": "postgres://dev:dev@localhost:5432/app_development",
"allowTables": ["users", "orders", "public.events_*"],
"denyTables": ["audit_log"]
},
"billing": { "url": "env:BILLING_DEV_DATABASE_URL" }
},
"maskPatterns": ["password", "secret", "token", "key", "hash", "ssn", "card"],
"queryBudget": 100,
"rowLimit": 200,
"byteLimit": 262144,
"statementTimeoutMs": 5000
}allowTables/denyTables——不区分大小写的名称,支持*通配符;包含点的规则匹配schema.table。拒绝优先;非空的允许列表是排他性的。maskPatterns——针对列名匹配的不区分大小写的正则表达式。CLI 标志:
--config <path>、--no-mask(禁用列掩码)、--help、--version。
安全模型(摘要)
完整的威胁模型见 SECURITY.md。简而言之:
只读防护:每个
run_query/explain_query语句都会被分词(引号、E'...'转义、注释、美元引用字符串),并且必须以 SELECT / WITH / EXPLAIN / SHOW / VALUES 开头;多语句输入和任何顶层写/DDL 关键字都会被拒绝——CTE 后跟 INSERT 会被捕获,而SELECT 'DROP TABLE x'不会被误报。引擎级强制:SQLite 文件以只读方式打开;PostgreSQL 会话以
default_transaction_read_only=on运行,使用显式BEGIN READ ONLY事务,并设置语句超时。列掩码默认开启(使用
--no-mask选择退出),结果上限,以及每会话查询预算(默认 100;耗尽时会提示你重启服务器)。凭据永远不会到达模型:连接字符串仅来自本地配置/环境变量,并且会从每条错误消息中清除。
冒烟测试
scripts/verify-stdio.mjs 构建一个临时 SQLite 数据库,启动 node dist/cli.js,并通过原始 JSON-RPC 在 stdio 上驱动一次真实的 MCP 握手。实际输出:
$ node scripts/verify-stdio.mjs
initialize -> mcp-devdb 0.1.0 (protocol 2025-06-18)
tools/list -> db_overview, describe_table, explain_query, list_tables, run_query, sample_rows
tools/call list_tables ->
{
"database": "demo",
"dialect": "sqlite",
"tableCount": 2,
"tables": [
{
"schema": null,
"name": "orders",
"type": "table",
"rowEstimate": 3,
"sizeBytes": 4096,
"sizePretty": "4.0 KiB"
},
{
"schema": null,
"name": "users",
"type": "table",
"rowEstimate": 2,
"sizeBytes": 4096,
"sizePretty": "4.0 KiB"
}
]
}
tools/call run_query "DROP TABLE users" -> isError=true
Query rejected by read-only guard: Only read-only statements are allowed; the statement must start with one of: SELECT, WITH, EXPLAIN, SHOW, VALUES
SMOKE TEST PASSED限制
还没有 MySQL。
src/adapters/types.ts中的DbAdapter接口是扩展点。仅限开发数据库。 防护会在 SQL 层面阻止写入,但 SELECT 仍然可能调用标记不当或具有副作用的扩展函数(例如
dblink打开它自己的非只读连接)。对于开发数据库可以接受;切勿将其指向生产环境。参见 SECURITY.md。防护是保守的:未加引号的列如果名称类似被禁止的关键字(例如一个字面意义上名为
update的列)会被拒绝——请给它们加引号("update")以继续。SELECT ... FOR UPDATE会被拒绝(它会获取行锁)。SQLite 行数使用
COUNT(*);在超大文件上list_tables可能会很慢。
开发
npm install
npm run lint && npm run typecheck && npm test && npm run build
node scripts/verify-stdio.mjs许可证
MIT——版权所有(c)2026 Aminyx
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityDmaintenanceA lightweight Postgres MCP server for safe database exploration and query analysis, read-only by default, with multi-database support.43MIT
- AlicenseNot gradedqualityDmaintenanceA read-only MCP server for PostgreSQL that enables safe database introspection and querying via natural language.539MIT
- AlicenseAqualityAmaintenanceRead-only MCP server that lets AI agents safely query SQLite, PostgreSQL, and MySQL/MariaDB. Enforces read-only transactions with column masking, row caps, query timeouts, EXPLAIN-based cost rejection, and rate limiting.7321MIT
- AlicenseNot gradedqualityCmaintenanceRead-only MCP server for SQL databases (SQLite/PostgreSQL) that enables listing tables, describing schemas, and executing SELECT queries with safety guardrails.MIT
Related MCP Connectors
MCP server for managing Prisma Postgres.
MCP server for interacting with the Supabase platform
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/aminyx/mcp-devdb'
If you have feedback or need assistance with the MCP directory API, please join our Discord server