使用说明
PostgreSQL MCP服务器
PostgreSQL模型上下文协议(MCP)服务器的实现。启用只读SQL查询执行和数据库架构信息检索。
特性
- 怎么翻译:执行只读SQL查询
- list表格:获取数据库中的表列表
- getTableSchema:获取指定表的架构信息
安装
来自npm
npm install -g @daitasu/postgres-mcp
来源
# Clone the repository
git clone https://github.com/daitasu/postgres-mcp.git
cd postgres-mcp
# Install dependencies
pnpm install
# Build
pnpm run build
配置
使用npx(推荐)
添加到您的Claude Desktop或MCP客户端配置中:
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["@daitasu/postgres-mcp", "postgresql://user:password@localhost:5432/database"]
}
}
}
使用全局安装
如果全局安装:
{
"mcpServers": {
"postgres": {
"command": "postgres-mcp",
"args": ["postgresql://user:password@localhost:5432/database"]
}
}
}
使用本地安装
{
"mcpServers": {
"postgres": {
"command": "node",
"args": ["/path/to/postgres-mcp/dist/index.js", "postgresql://user:password@localhost:5432/database"]
}
}
}
命令行执行
# Using npx (no installation required)
npx @daitasu/postgres-mcp postgresql://user:password@localhost:5432/database
# Using global installation
postgres-mcp postgresql://user:password@localhost:5432/database
# Using node directly
node dist/index.js postgresql://user:password@localhost:5432/database
工具使用
1.查询-执行SQL查询
Input: { "sql": "SELECT * FROM users LIMIT 10" }
Output: Query results (JSON format)
2.listTables-获取表列表
Input: {}
Output: List of table names
3.getTableSchema-获取表模式
Input: { "tableName": "users" }
Output: List of column names and data types
安全
- 所有查询都在只读事务中执行
- 无法修改数据
- 自动回滚
发展
# Development mode
pnpm run dev
# Tests
pnpm test
# Type checking
pnpm run typecheck
# Lint
pnpm run lint
许可证
麻省理工学院