VOOZH about

URL: https://glama.ai/mcp/servers/hthuong09/postgres-mcp?locale=zh-CN

⇱ PostgreSQL MCP 服务器 by hthuong09 | Glama


MCP PostgreSQL 服务器

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

安装

npm install -g @hthuong09/postgres-mcp

Related MCP server: PostgreSQL MCP Server

配置

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

  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

执照

麻省理工学院

A
license - permissive license
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

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