Skip to main content
Glama

PostgreSQL MCP Server

by hthuong09

MCP PostgreSQL 服务器

这是一个用于与 PostgreSQL 数据库交互的模型上下文协议服务器。它提供了一个只读接口来查询 PostgreSQL 数据库并检查其架构。

安装

npm install -g @hthuong09/postgres-mcp

配置

服务器可以通过多种方式配置,按优先级顺序列出:

  1. 环境变量
    • POSTGRES_URL :完整数据库 URL(例如, postgres://user:pass@host:5432/dbname
    • 单独的连接参数:
      • POSTGRES_HOST :数据库主机
      • POSTGRES_PORT :数据库端口(默认值:5432)
      • POSTGRES_DB :数据库名称
      • POSTGRES_USER :数据库用户
      • POSTGRES_PASSWORD :数据库密码
      • POSTGRES_SSL :启用 SSL 模式(设置为“true”以启用)
      • POSTGRES_SCHEMA :数据库模式(默认值:'public')
    • 附加配置:
      • DOTENV_PATH :.env 文件的自定义路径
      • DEBUG_MCP :启用调试日志记录(设置为“true”以启用)
  2. 命令行
    npx @hthuong09/postgres-mcp "postgres://user:pass@host:5432/dbname"

资源

  • 表模式:数据库中的每个表都作为资源公开
  • 资源 URI 格式: postgres://user@host/dbname/table_name/schema
  • 响应格式:列定义(名称和数据类型)的 JSON 数组

使用示例

  1. 使用环境变量:
    export POSTGRES_HOST=localhost export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword npx @hthuong09/postgres-mcp
  2. 使用连接 URL:
    npx @hthuong09/postgres-mcp "postgres://myuser:mypassword@localhost:5432/mydb"
  3. 将环境变量与 SSL 结合使用:
    export POSTGRES_HOST=db.example.com export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword export POSTGRES_SSL=true npx @hthuong09/postgres-mcp
  4. 使用自定义 .env 文件位置:
    DOTENV_PATH=/path/to/.env npx @hthuong09/postgres-mcp

安全注意事项

  • 数据库凭证应保持安全
  • 在生产环境中使用环境变量或 .env 文件而不是命令行参数,以避免在进程列表中暴露凭据
  • 考虑在生产环境中使用 SSL
  • 为了安全起见,服务器只允许只读事务
  • 密码会自动从资源 URI 中删除

发展

要在本地构建服务器:

npm install npm run build

在开发期间以监视模式运行:

npm run watch

调试

设置DEBUG_MCP=true以启用调试日志记录。日志将写入:

  • Unix/macOS: /tmp/postgres-mcp-debug.json
  • Windows: %TEMP%/postgres-mcp-debug.json

执照

麻省理工学院

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

模型上下文协议服务器,可与 PostgreSQL 数据库交互以列出表、检索模式和执行只读 SQL 查询。

  1. 安装
    1. 配置
      1. 资源
    2. 使用示例
      1. 安全注意事项
        1. 发展
          1. 调试
            1. 执照

              Related MCP Servers

              • -
                security
                A
                license
                -
                quality
                A Model Context Protocol server providing LLMs read-only access to PostgreSQL databases for inspecting schemas and executing queries.
                Last updated -
                16,948
                17
                JavaScript
                MIT License
                • Apple
              • -
                security
                A
                license
                -
                quality
                A Model Context Protocol server that provides read-only access to PostgreSQL databases with enhanced multi-schema support, allowing LLMs to inspect database schemas across multiple namespaces and execute read-only queries while maintaining schema isolation.
                Last updated -
                13
                2
                JavaScript
                MIT License
              • -
                security
                F
                license
                -
                quality
                A Model Context Protocol server providing both read and write access to PostgreSQL databases, enabling LLMs to query data, modify records, and manage database schemas.
                Last updated -
                4
                JavaScript
              • -
                security
                -
                license
                -
                quality
                A Model Context Protocol server that provides read-only access to PostgreSQL databases, enabling LLMs to inspect database schemas and execute read-only queries.
                Last updated -
                JavaScript

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/hthuong09/postgres-mcp'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server