使用说明
PostgreSQL MCP服务器
提供PostgreSQL数据库管理功能的模型上下文协议(MCP)服务器。该服务器协助分析现有的PostgreSQL设置,提供实现指导,并调试数据库问题。
特性
1.数据库分析(analyze_database)
分析PostgreSQL数据库配置和性能指标:
- 配置分析
- 性能指标
- 安全评估
- 优化建议
// Example usage
{
"connectionString": "postgresql://user:password@localhost:5432/dbname",
"analysisType": "performance" // Optional: "configuration" | "performance" | "security"
}
2.设置说明(get_setup_instructions)
提供PostgreSQL安装和配置的分步指导:
- 平台特定安装步骤
- 配置建议
- 安全最佳实践
- 安装后任务
// Example usage
{
"platform": "linux", // Required: "linux" | "macos" | "windows"
"version": "15", // Optional: PostgreSQL version
"useCase": "production" // Optional: "development" | "production"
}
3.数据库调试(debug_database)
调试常见的PostgreSQL问题:
- 连接问题
- 性能的瓶颈
- 锁定冲突
- 复制状态
// Example usage
{
"connectionString": "postgresql://user:password@localhost:5432/dbname",
"issue": "performance", // Required: "connection" | "performance" | "locks" | "replication"
"logLevel": "debug" // Optional: "info" | "debug" | "trace"
}
先决条件
- Node.js>=18.0.0
- PostgreSQL服务器(用于目标数据库操作)
- 目标PostgreSQL实例的网络访问
安装
通过Smithery安装
通过以下方式自动安装PostgreSQL MCP Server for Claude Desktop 史密瑟里:
npx -y @smithery/cli install @nahmanmate/postgresql-mcp-server --client claude
手动安装
- 克隆存储库
- 安装依赖项:
npm install - 构建服务器:
npm run build - 添加到MCP设置文件:
{ "mcpServers": { "postgresql-mcp": { "command": "node", "args": ["/path/to/postgresql-mcp-server/build/index.js"], "disabled": false, "alwaysAllow": [] } } }
发展
npm run dev-使用热重新加载启动开发服务器npm run lint-运行ESLintnpm test-运行测试
安全考虑
-
连接安全性
- 使用连接池
- 实现连接超时
- 验证连接字符串
- 支持SSL/TLS连接
-
查询安全
- 验证SQL查询
- 防止危险操作
- 实现查询超时
- 记录所有操作
-
认证
- 支持多种身份验证方法
- 实施基于角色的访问控制
- 强制执行密码策略
- 安全地管理连接凭据
最佳实践
- 始终使用具有正确凭据的安全连接字符串
- 遵循敏感环境的生产安全建议
- 定期监控和分析数据库性能
- 保持PostgreSQL版本最新
- 实施适当的备份策略
- 使用连接池进行更好的资源管理
- 实施适当的错误处理和日志记录
- 定期安全审计和更新
错误处理
服务器实现了全面的错误处理:
- 连接失败
- 查询超时
- 身份验证错误
- 权限问题
- 资源限制
运行评估和测试
evals包加载一个mcp客户端,然后运行index.ts文件,因此不需要在测试之间重建。您可以查看完整的文档 这里.
OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts src/index.ts
贡献
- 分叉存储库
- 创建要素分支
- 提交您的更改
- 推到分支
- 创建拉取请求
许可证
此项目根据AGPLv3许可证获得许可-有关详细信息,请参阅License文件。