
PostgreSQL MCP Server
io.github.musaddiq-dev由 GitHub 账号 musaddiq-dev 发布v0.1.2更新于 Oct 24, 2026
Python MCP server for PostgreSQL database inspection and querying
概览
本地运行的 Python MCP 服务器,让助手检查并查询 PostgreSQL 数据库:列出表、查看结构、执行有行数上限的只读 SQL 和解释执行计划
- 可以做什么
- 列出表并查看表的列与元数据,获取数据库版本和表数量摘要,搜索公共 SQL 例程与函数。在只读事务中执行有行数上限的只读 SQL,解释查询计划,预览表中最多 10 行数据。检查外键关系以及索引及其大小。执行单条会提交的修改语句(INSERT、UPDATE、DELETE、CREATE、ALTER、DROP、TRUNCATE)。读取表清单和单表结构等被动资源。
- 适用场景
- 适合助手需要探索不熟悉的 PostgreSQL 结构、基于实时数据回答问题,或在对话中查看查询计划和索引时使用。适用于已有数据库连接的本地开发与分析场景。
- 运行要求
- 以 Python 包形式通过 stdio 在本地运行(需 Python 3.11+),用 uvx 启动,并需要可访问的 PostgreSQL 数据库。必需环境变量:POSTGRES_HOST、POSTGRES_PORT、POSTGRES_USER、POSTGRES_DB;POSTGRES_PASSWORD 可选。POSTGRES_READ_QUERY_LIMIT 限制读查询返回行数。需要兼容 MCP 的客户端。
安装
在 SourceWeft 中
- 打开 控制台中的 PostgreSQL MCP Server,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
PostgreSQL MCP Server
A Python Model Context Protocol (MCP) server for inspecting and querying PostgreSQL databases from MCP-compatible clients. It provides schema discovery, safe read-only query execution, query explanation, table previews, index analysis, relationship inspection, and PostgreSQL resources for table metadata.
Features
- List public tables and inspect table schemas
- Execute read-only SQL in a PostgreSQL read-only transaction
- Explain query plans without executing the target query directly
- Preview table rows with a fixed limit
- Inspect foreign-key relationships and indexes
- Expose passive MCP resources for table lists and schema details
Safety Model
postgresql_execute_read_query runs with PostgreSQL read-only transaction mode, caps returned rows by POSTGRES_READ_QUERY_LIMIT, and rolls back after execution. The server also includes postgresql_execute_write_query, which only accepts a single INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, or TRUNCATE statement and can modify data/schema if the connected database user has permission. Do not auto-approve write-capable tools in your MCP client. For public or shared use, run the server with a dedicated read-only PostgreSQL user.
Requirements
- Python 3.11+
- PostgreSQL database
- MCP-compatible client such as Claude Desktop, Cursor, VS Code, or another MCP host
Installation
When published to PyPI, install or run the server like a standard Python MCP package:
For local development from source:
Configuration
Copy the example environment file and update it with your database connection details.
Example read-only user:
Running
From a local checkout before PyPI publication, run:
MCP Client Configuration
For published installs, prefer uvx. MCP servers using stdio must write protocol messages only to stdout; this server writes logs to stderr through Python logging.
Claude Desktop / Cursor / Windsurf / Cline
Most MCP clients accept this mcpServers JSON shape:
For local development from this repository, use the installed console script path instead:
Claude Code CLI
VS Code MCP
VS Code uses the same command/args/env model in its MCP configuration:
Tools
Resources
postgres://list_tablesreturns public table names.postgres://schema/{table_name}returns a generated schema statement for a table.
Smoke Check
Without a database, verify syntax with:
With a configured database, start the server and use your MCP client to call list_tables.
Distribution
This server is published through the standard Python MCP distribution path:
- PyPI package:
mdev-postgresql-mcp-server - MCP Registry name:
io.github.musaddiq-dev/postgresql-mcp-server - Runtime hint:
uvx - Transport:
stdio
The mcp-name marker at the top of this README is required for MCP Registry ownership verification. Users should prefer uvx mdev-postgresql-mcp-server in local MCP client configurations.
Security Notes
- Do not commit
.envor MCP client configs containing credentials. - Use least-privilege database users.
- Treat
execute_write_queryas destructive and require explicit user approval in your MCP client. - Review generated SQL before running write-capable tools.
License
MIT
来源:README.md,提交 3e4ecf6
工具
0版本历史
1- v0.1.2最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分