PostgreSQL只读查询服务

一个提供PostgreSQL数据库只读访问的模型上下文协议服务器,允许LLM检查数据库模式和执行只读查询。

  • by vinsidious
  • JavaScript
  • 本地部署
  • 4 星标
  • 更新于
在 GitHub 查看 vinsidious/mcp-pg-schema

使用说明

PostgreSQL

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

组件

工具

  • 怎么翻译
    • 对连接的数据库执行只读SQL查询
    • 输入: sql (string):要执行的SQL查询
    • 所有查询都在只读事务中执行

资源

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

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

使用Claude Desktop

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

码头工人

  • 在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 使用您的数据库名称。

建筑

Docker:

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

许可证

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