M

MCP-PG模式

@vinsidious/mcp-pg-schema
0 Stars 333 次浏览 vinsidious 更新于 2026-08-23

提供对 PostgreSQL 数据库的只读访问,使用户能够通过模型上下文协议服务器检查数据库模式并执行只读查询。

MCP 服务配置

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

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

服务介绍

PostgreSQL

一个提供对PostgreSQL数据库只读访问的模型上下文协议服务器。该服务器使LLM能够检查数据库模式并执行只读查询。

组件

工具

  • query
    • 对连接的数据库执行只读SQL查询
    • 输入: sql (字符串): 要执行的SQL查询
    • 所有查询都在只读事务中执行

资源

服务器为数据库中的每个表提供模式信息:

  • 表模式 (postgres://<host>/<table>/schema)
    • 每个表的JSON模式信息
    • 包括列名和数据类型
    • 自动从数据库元数据中发现

与Claude Desktop一起使用

要将此服务器与Claude Desktop应用程序一起使用,请在您的claude_desktop_config.json文件的"mcpServers"部分添加以下配置:

Docker

  • 当在macOS上运行Docker时,如果服务器运行在主机网络(例如localhost)上,请使用host.docker.internal
  • 用户名/密码可以使用postgresql://user:password@host:port/db-name格式添加到PostgreSQL URL中
{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run", 
        "-i", 
        "--rm", 
        "mcp/postgres", 
        "postgresql://host.docker.internal:5432/mydb"]
    }
  }
}

NPX

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

/mydb替换为您的数据库名称。

构建

Docker:

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

许可证

此MCP服务器根据MIT许可证许可。这意味着您可以自由地使用、修改和分发软件,但须遵守MIT许可证的条款和条件。有关更多详细信息,请参阅项目存储库中的LICENSE文件。

相关 MCP 服务