返回市场
邮政数据库

邮政数据库

作者:modelcontextprotocol182 星标更新:2025-05-29

项目介绍

技术文档摘要

PostgreSQL

这是一个提供对PostgreSQL数据库只读访问的Model Context Protocol服务器。此服务器使LLMs能够检查数据库模式并执行只读查询。

组件

工具

  • 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 URL中,格式为postgresql://user:password@host:port/db-name
{
  "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替换为您自己的数据库名称。

与VS Code一起使用

为了快速安装,请使用下面的一个一键安装按钮...

通过NPX在VS Code中安装 通过NPX在VS Code Insiders中安装

通过Docker在VS Code中安装 通过Docker在VS Code Insiders中安装

对于手动安装,请将以下JSON块添加到VS Code中的用户设置(JSON)文件中。您可以通过按Ctrl + Shift + P并键入Preferences: Open User Settings (JSON)来完成此操作。

可选地,您可以将其添加到工作区中的名为.vscode/mcp.json的文件中。这将允许您与其他人员共享配置。

注意:在.vscode/mcp.json文件中不需要mcp键。

Docker

注意:当使用Docker并连接到主机机器上的PostgreSQL服务器时,在连接URL中使用host.docker.internal而不是localhost

{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "pg_url",
        "description": "PostgreSQL URL (e.g. postgresql://user:pass@host.docker.internal:5432/mydb)"
      }
    ],
    "servers": {
      "postgres": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "mcp/postgres",
          "${input:pg_url}"
        ]
      }
    }
  }
}

NPX

{
  "mcp": {
    "inputs": [
      {
        "type": "promptString",
        "id": "pg_url",
        "description": "PostgreSQL URL (e.g. postgresql://user:pass@localhost:5432/mydb)"
      }
    ],
    "servers": {
      "postgres": {
        "command": "npx",
        "args": [
          "-y",
          "@modelcontextprotocol/server-postgres",
          "${input:pg_url}"
        ]
      }
    }
  }
}

构建

Docker:

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

许可证

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