MCP PostgreSQL 服务器
这是一个用于与 PostgreSQL 数据库交互的模型上下文协议服务器。它提供了一个只读接口来查询 PostgreSQL 数据库并检查其架构。
安装
配置
服务器可以通过多种方式配置,按优先级顺序列出:
环境变量
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”以启用)
命令行
资源
表模式:数据库中的每个表都作为资源公开
资源 URI 格式:
postgres://user@host/dbname/table_name/schema
响应格式:列定义(名称和数据类型)的 JSON 数组
使用示例
使用环境变量:
使用连接 URL:
将环境变量与 SSL 结合使用:
使用自定义 .env 文件位置:
安全注意事项
数据库凭证应保持安全
在生产环境中使用环境变量或 .env 文件而不是命令行参数,以避免在进程列表中暴露凭据
考虑在生产环境中使用 SSL
为了安全起见,服务器只允许只读事务
密码会自动从资源 URI 中删除
发展
要在本地构建服务器:
在开发期间以监视模式运行:
调试
设置DEBUG_MCP=true
以启用调试日志记录。日志将写入:
Unix/macOS:
/tmp/postgres-mcp-debug.json
Windows:
%TEMP%/postgres-mcp-debug.json
执照
麻省理工学院
This server cannot be installed
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 查询。
Related MCP Servers
- -securityFlicense-qualityA 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 -5837
- AsecurityAlicenseAqualityA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.Last updated -181,016119AGPL 3.0
- AsecurityAlicenseAqualityA Model Context Protocol server that enables interaction with PostgreSQL databases for analyzing setups, debugging issues, managing schemas, migrating data, and monitoring performance.Last updated -101MIT License
- -securityFlicense-qualityA Model Context Protocol server implementation that provides a simple interface to interact with PostgreSQL databases, enabling SQL queries, database operations, and schema management through MCP.Last updated -