PostgreSQL

PostgreSQL

具有模式检查功能的只读数据库访问

概述

PostgreSQL MCP 服务器允许大语言模型:

  • 检查数据库模式
  • 执行只读 SQL 查询
  • 自动获取表结构信息

安装与配置

将以下配置添加到 claude_desktop_config.json"mcpServers" 部分:

使用 Docker

{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run", 
        "-i", 
        "--rm", 
        "mcp/postgres", 
        "postgresql://user:password@host:port/db-name"]
    }
  }
}

注意: 在 macOS 上使用 Docker 时,如需连接本地数据库,请将 localhost 替换为 host.docker.internal

使用 NPX

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/mydb"
      ]
    }
  }
}

功能

  • 查询工具: 执行只读 SQL 查询
  • 表模式资源: 自动提供所有表的结构信息 (postgres://<host>/<table>/schema)

构建 (可选)

Docker 构建命令:

docker build -t mcp/postgres -f src/postgres/Dockerfile .

许可证

MIT 许可