MCP PostgreSQL 服务器
这是一个用于与 PostgreSQL 数据库交互的模型上下文协议服务器。它提供了一个只读接口来查询 PostgreSQL 数据库并检查其架构。
安装
npm install -g @hthuong09/postgres-mcpRelated MCP server: PostgreSQL MCP Server
配置
服务器可以通过多种方式配置,按优先级顺序列出:
环境变量
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”以启用)
命令行
npx @hthuong09/postgres-mcp "postgres://user:pass@host:5432/dbname"
资源
表模式:数据库中的每个表都作为资源公开
资源 URI 格式:
postgres://user@host/dbname/table_name/schema响应格式:列定义(名称和数据类型)的 JSON 数组
使用示例
使用环境变量:
export POSTGRES_HOST=localhost export POSTGRES_DB=mydb export POSTGRES_USER=myuser export POSTGRES_PASSWORD=mypassword npx @hthuong09/postgres-mcp使用连接 URL:
npx @hthuong09/postgres-mcp "postgres://myuser:mypassword@localhost:5432/mydb"将环境变量与 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使用自定义 .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.jsonWindows:
%TEMP%/postgres-mcp-debug.json
执照
麻省理工学院
This server cannot be installed
Maintenance
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
