
Postgres
io.github.marcelo-ochoa由 GitHub 账号 marcelo-ochoa 发布v1.0.8更新于 Oct 24, 2026
MCP server for interacting with PostgreSQL databases
概览
本地 MCP 服务器,让助手以只读方式访问 PostgreSQL 数据库:执行查询、查看表结构、解释执行计划并生成性能统计。
- 可以做什么
- 在只读事务中执行只读 SQL 查询,并解释查询的执行计划。获取单表统计信息,并生成类似 Oracle AWR 的性能报告,涵盖数据库统计、高频查询、表和索引统计及优化建议。以资源形式浏览自动发现的表结构,包括列名和数据类型。运行时通过连接串、用户名和密码连接数据库。
- 适用场景
- 适合让助手安全地探查或分析已有的 PostgreSQL 数据库,例如回答数据相关问题、查看表结构,或在不授予写权限的情况下排查慢查询和性能问题。
- 运行要求
- 以 stdio 方式在本地运行,可通过 npm(npx)或 Docker 安装。需要可访问的 PostgreSQL 服务器,以及包含主机、端口和数据库名的连接串,并通过环境变量或连接工具提供数据库用户名和密码。可通过连接串参数或环境变量启用 SSL。
安装
在 SourceWeft 中
- 打开 控制台中的 Postgres,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
PostgreSQL
A Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.
Components
Tools
-
pg-query
- Execute read-only SQL queries against the connected database
- Input:
sql(string): The SQL query to execute - All queries are executed within a READ ONLY transaction
-
pg-stats
- Get statistics for a specific table
- Input:
name(string): The name of the table to get statistics for
-
pg-explain
- Explain Plan for a given SQL query
- Input:
sql(string): The SQL query to explain
-
pg-connect
- Connect to a PostgreSQL database
- Inputs:
connectionString(string): The PostgreSQL connection string without credentials (e.g. postgresql://host:port/dbname or host:port/dbname)user(string): The PostgreSQL usernamepassword(string): The PostgreSQL password
Example: pg-connect host.docker.internal:5432/postgres postgres pg_2025
- pg-awr
- Generate a PostgreSQL performance report similar to Oracle AWR. Includes database statistics, top queries (requires pg_stat_statements extension), table/index statistics, connection info, and optimization recommendations.
Resources
The server provides schema information for each table in the database:
- Table Schemas (
postgres://<dbname>/<table>/schema)- JSON schema information for each table
- Includes column names and data types
- Automatically discovered from database metadata
Change Log
See Change Log for the history of changes.
Configuration
The PostgreSQL server uses environment variables or the pg-connect tool for secure credential management:
PG_USER: PostgreSQL username (optional if usingpg-connect)PG_PASSWORD: PostgreSQL password (optional if usingpg-connect)
Connection String
The connection string should contain only the host, port, and database information (without embedded credentials). Providing it as a command-line argument is optional. If omitted at startup, you must use the pg-connect tool to establish a connection before using other functionality.
Supported connection string formats:
postgresql://host:port/dbnamehost:port/dbname
To enable encryption (SSL), append ?sslmode=require to the connection string or set the PG_SSL environment variable to true.
Usage with Claude Desktop
To use this server with the Claude Desktop app, add the following configuration to the "mcpServers" section of your claude_desktop_config.json:
Docker
- When running Docker on macOS, use
host.docker.internalif the PostgreSQL server is running on the host network (e.g., localhost) - Credentials are passed via environment variables
PG_USERandPG_PASSWORD
Note: You can still provide the connection string as a final argument if you want to connect automatically on startup: "args": [..., "mochoa/mcp-postgres", "postgresql://host.docker.internal:5432/mydb"].
NPX
Replace /mydb with your database name.
Note: Replace the following placeholders with your actual values:
myuserandmypasswordwith your PostgreSQL credentialslocalhost:5432with your PostgreSQL server host and portmydbwith your database name
Usage with VS Code
For quick installation, use one of the one-click install buttons below...
[Install with NPX in VS Code] [Install with NPX in VS Code Insiders]
[Install with Docker in VS Code] [Install with Docker in VS Code Insiders]
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P and typing Preferences: Open User Settings (JSON).
Optionally, you can add it to a file called .vscode/mcp.json in your workspace. This will allow you to share the configuration with others.
Note that the
mcpkey is not needed in the.vscode/mcp.jsonfile.
Docker
Note: When using Docker and connecting to a PostgreSQL server on your host machine, use host.docker.internal instead of localhost in the connection URL.
Note: You can add an input for pg_url and append it to args if you want to connect on startup.
NPX
PostgreSQL AWR in action
See PostgreSQL AWR in action for an example of a performance report generated by the pg-awr tool for a production Moodle database, highlighting critical performance issues and optimization opportunities.
Demos
See Demos for usage examples with Claude Desktop, Docker AI, Gemini CLI, and Antigravity Code Editor.
Building
Docker:
Sources
As usual the code of this extension is at GitHub, feel free to suggest changes and make contributions, note that I am a beginner developer of React and TypeScript so contributions to make this UI better are welcome.
📜 License
This project is licensed under the Apache License, Version 2.0 for new contributions, with existing code under MIT - see the LICENSE file for details.
来源:src/postgres/README.md,提交 bd2ce8f
工具
0版本历史
1- v1.0.8最新Sep 16, 2026
评分
已满足适用检查项的 40%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分
请在仓库或注册中心条目中声明许可证。