PostgreSQL

lm203688/postgresql-mcp-server
0 Stars 101 次浏览 更新于 2026-08-23

一个允许AI安全地读取和操作您的PostgreSQL数据库的服务器,具有schema支持、JSON格式EXPLAIN输出等功能,默认为只读模式以确保安全性。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "postgresql": {
      "args": [
        "-m",
        "postgresql_mcp_server"
      ],
      "command": "python",
      "env": {
        "PG_MCP_DATABASE": "your_db",
        "PG_MCP_HOST": "localhost",
        "PG_MCP_PASSWORD": "your_password",
        "PG_MCP_PORT": "5432",
        "PG_MCP_USER": "postgres"
      }
    }
  }
}

该服务需要配置环境变量:PG_MCP_DATABASE、PG_MCP_HOST、PG_MCP_PASSWORD、PG_MCP_PORT、PG_MCP_USER

服务介绍

PostgreSQL MCP Server

让AI安全地理解和操作你的PostgreSQL数据库

✨ 特性

  • 🔒 安全优先 — 默认只读模式
  • 📊 Schema支持 — 完整支持PostgreSQL的Schema体系
  • 🔍 执行计划 — JSON格式EXPLAIN输出
  • 🇨🇳 中文优先

🚀 快速开始

{
  "mcpServers": {
    "postgresql": {
      "command": "python",
      "args": ["-m", "postgresql_mcp_server"],
      "env": {
        "PG_MCP_HOST": "localhost",
        "PG_MCP_PORT": "5432",
        "PG_MCP_USER": "postgres",
        "PG_MCP_PASSWORD": "your_password",
        "PG_MCP_DATABASE": "your_db"
      }
    }
  }
}

🛠️ 工具列表

工具 功能 安全级别
list_databases 列出数据库 🟢 只读
list_schemas 列出Schema 🟢 只读
list_tables 列出表 🟢 只读
describe_table 表结构+索引+约束 🟢 只读
query 执行SQL查询 🟢 只读
explain_query 执行计划 🟢 只读
execute_write 写操作 🔴 需关闭只读

📄 License

MIT License

相关 MCP 服务