@钴金融/mcp
MCP服务器,为AI代理提供对PostgreSQL数据库的受控读/写访问。
特性
- 阅读工具:
query,list_tables,describe_table,get_relationships - 编写工具:
execute必须经过人工确认(confirm_destructive) - SQL保护:块TRUNCATE、DROP、ALTER、CREATE、GRANT、REVOKE和DELETE,不带WHERE
- 只读交易:SELECT查询在内部运行
BEGIN TRANSACTION READ ONLY - 参数化查询:支持
$1, $2, ...防止SQL注入
安装
npm install -g @cobaltfinance/mcp或者直接使用npx运行:
npx @cobaltfinance/mcp 用法
将PostgreSQL连接字符串作为CLI参数传递,或 DATABASE_URL 环境变量:
cobalt-mcp postgresql://user:pass@host:5432/dbname
# or
DATABASE_URL=postgresql://user:pass@host:5432/dbname cobalt-mcp配置AI客户端
克劳德桌面
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"cobalt": {
"command": "npx",
"args": ["-y", "@cobaltfinance/mcp", "postgresql://user:pass@host:5432/dbname"]
}
}
}克劳德代码
claude mcp add cobalt -- npx -y @cobaltfinance/mcp postgresql://user:pass@host:5432/dbname光标
添加 .cursor/mcp.json:
{
"mcpServers": {
"cobalt": {
"command": "npx",
"args": ["-y", "@cobaltfinance/mcp", "postgresql://user:pass@host:5432/dbname"]
}
}
}工具
query
执行只读SELECT查询。
sql: "SELECT * FROM users WHERE id = $1"
params: [123]list_tables
列出所有具有近似行数和列数的表。
describe_table
获取表的列详细信息(名称、类型、可空、默认值、主键)。
table: "users"get_relationships
获取表(或所有表,如果省略)的外键关系。
table: "transaction"execute
执行写查询(INSERT、UPDATE、DELETE)。需要人工确认。
sql: "UPDATE users SET name = $1 WHERE id = $2"
params: ["New Name", 123]
confirm_destructive: trueAI代理在设置之前必须要求用户明确批准 confirm_destructive: true.
安全
- SELECT查询被包装在
BEGIN TRANSACTION READ ONLY - SQL保护阻止危险的DDL/DCL操作
DELETE没有WHERE条款被阻止- 写入操作需要显式
confirm_destructive: true旗帜 - 所有查询都支持参数化,以防止SQL注入
- 连接字符串在启动时传递,不暴露给AI
许可证
麻省理工学院
