企业项目管理、ORK、研发管理与敏捷开发工具平台

网站首页 > 精选文章 正文

010:通过 MCP PostgreSQL 安全访问数据

wudianyun 2025-09-06 14:14:19 精选文章 6 ℃

项目简介

提供对 PostgreSQL 数据库的只读访问功能。该服务器允许大型语言模型(LLMs)检查数据库的模式结构,并执行只读查询操作。

核心功能

  • 提供对 PostgreSQL 数据库的只读访问
  • 允许 LLM(大语言模型)查看数据库架构和执行只读查询
  • 确保数据安全性(仅支持读操作)

配置使用方法

提供了两种配置方式:

Docker 方式

{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run", 
        "-i", 
        "--rm", 
        "mcp/postgres", 
        "postgresql://host.docker.internal:5432/mydb"
      ]
    }
  }
}

特别说明:

  • MacOS 上运行 Docker 时,如果服务器在主机网络上运行,使用 host.docker.internal
  • 可以在 PostgreSQL URL 中添加用户名和密码:postgresql://user:password@host:port/db-name

NPX 方式

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

构建说明

提供了 Docker 构建命令:

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

相关链接

  • MCP PostgreSQL: https://github.com/modelcontextprotocol/servers/tree/main/src/postgres

#MCP #PostgreSQL #NPX #Docker #SQL

Tags:

最近发表
标签列表