首页
/ Postgres MCP Pro安装与配置指南

Postgres MCP Pro安装与配置指南

2026-01-31 04:24:01作者:农烁颖Land

1. 项目基础介绍

Postgres MCP Pro 是一个开源的 Model Context Protocol (MCP) 服务器,旨在在整个开发过程中支持开发者和AI代理。该服务器不仅提供了数据库连接的功能,还具有数据库健康检查、索引优化、模式智能和安全执行SQL等特性。

主要编程语言:Python

2. 项目使用的关键技术和框架

  • MCP (Model Context Protocol):一种用于AI和数据库之间通信的协议。
  • Docker:用于容器化应用,确保在不同环境中的一致性。
  • Python 3.12+:Python的高级特性用于实现项目功能。

3. 安装和配置准备工作

在开始安装前,请确保以下准备工作已完成:

  • 数据库访问凭证:确保你有访问PostgreSQL数据库的凭证。
  • Docker或Python环境:根据你的偏好选择安装Docker或Python环境。Docker推荐用于减少环境配置问题。

安装步骤

使用Docker安装

  1. 拉取Postgres MCP Pro Docker镜像

    docker pull crystaldba/postgres-mcp
    
  2. 启动Postgres MCP Pro容器

    docker run -i --rm -e DATABASE_URI="postgresql://username:password@localhost:5432/dbname" crystaldba/postgres-mcp --access-mode=unrestricted
    

    替换 postgresql://username:password@localhost:5432/dbname 为你的数据库连接URI。

使用Python安装

  1. 安装Postgres MCP Pro

    如果你的系统中已安装了 pipx,可以使用以下命令:

    pipx install postgres-mcp
    

    如果没有安装 pipx,可以使用以下命令:

    uv pip install postgres-mcp
    

    如果需要安装 uv,请参考官方安装说明。

  2. 运行Postgres MCP Pro

    postgres-mcp --access-mode=unrestricted
    

    同样,替换 --access-mode=unrestricted--access-mode=restricted 如果你想在受限模式下运行。

配置AI助手

根据你使用的AI助手(如Claude Desktop、Cursor、Windsurf或Goose),编辑相应的配置文件,以添加Postgres MCP Pro服务器的配置。

以下是Claude Desktop的配置示例:

{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_URI",
        "crystaldba/postgres-mcp",
        "--access-mode=unrestricted"
      ],
      "env": {
        "DATABASE_URI": "postgresql://username:password@localhost:5432/dbname"
      }
    }
  }
}

确保将 postgresql://username:password@localhost:5432/dbname 替换为你的数据库连接URI。

以上就是Postgres MCP Pro的详细安装和配置指南,按照以上步骤操作,你将能够成功安装并配置Postgres MCP Pro。

登录后查看全文
热门项目推荐
相关项目推荐