增强版 PostgreSQL MCP 服务器
提供对 PostgreSQL 数据库的读写访问,支持模式管理与数据操作。
快速入门
-
安装和运行
- 使用 Docker: docker build -t mcp/postgres -f Dockerfile . docker run -i --rm mcp/postgres postgresql://host:port/db-name
- 或使用 NPX: npx -y @modelcontextprotocol/server-postgres postgresql://host:port/db-name
-
配置 Claude Desktop 在
claude_desktop_config.json
中添加以下内容: { "mcpServers": { "postgres": { "command": "docker", "args": [ "run", "-i", "--rm", "mcp/postgres", "postgresql://host.docker.internal:5432/mydb" ] } } } -
示例命令
- 查询数据:/query SELECT * FROM users LIMIT 5
- 插入数据:/insert table="users", data={"name": "John Doe", "email": "john@example.com"}
- 更新数据:/update table="users", data={"status": "inactive"}, where="id='123'"
- 创建表:/createTable tableName="tasks", columns=[{"name": "id", "type": "SERIAL", "constraints": "PRIMARY KEY"}]