MCP Server for PostgreSQL
PostgreSQL 的 MCP 服务器
PostgreSQL 的模型上下文协议 (MCP) 服务器实现,提供通过 MCP 与 PostgreSQL 数据库交互的简单接口。
特征
使用参数化输入执行 SQL 查询
运行 INSERT/UPDATE/DELETE 操作
创建新数据库
创建或更新表架构
调试 PostgreSQL 连接
使用 Docker 进行容器化,易于部署
基于环境的配置
Related MCP server: MCP PostgreSQL Server
先决条件
Python 3.8+
PostgreSQL 10+
Docker(可选,用于容器化部署)
Docker Compose(可选,用于开发)
安装
使用 Docker(推荐)
克隆存储库:
git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgres复制示例环境文件:
cp .env.example .env使用您的 PostgreSQL 凭证更新
.env文件:PG_HOST=postgres PG_PORT=5432 PG_USER=postgres PG_PASSWORD=your_password PG_DATABASE=your_database HOST=0.0.0.0 PORT=8056使用 Docker Compose 启动服务:
docker-compose up -d
手动安装
克隆存储库:
git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgres创建并激活虚拟环境:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate安装依赖项:
pip install -r requirements.txt复制示例环境文件并更新:
cp .env.example .env # Edit .env with your configuration运行服务器:
python mcp_server_postgres.py
用法
MCP 服务器提供以下端点:
sql_query
运行 SELECT 查询并以 JSON 形式返回结果。
参数:
query:SQL 查询字符串params:查询参数的可选 JSON 字符串(列表或字典)
例子:
{
"query": "SELECT * FROM users WHERE id = $1",
"params": [1]
}sql_execute
执行 INSERT/UPDATE/DELETE 语句。
参数:
query:SQL语句params:查询参数的可选 JSON 字符串(列表或字典)
例子:
{
"query": "INSERT INTO users (name, email) VALUES ($1, $2)",
"params": ["John Doe", "john@example.com"]
}create_database
创建一个新的 PostgreSQL 数据库。
参数:
database_name:要创建的数据库的名称
create_or_update_table
创建或更新表模式。
参数:
sql:CREATE TABLE 或 ALTER TABLE SQL 语句
debug_postgres_connection
调试 PostgreSQL 连接。
环境变量
多变的 | 默认 | 描述 |
PG_HOST | 本地主机 | PostgreSQL 主机 |
PG_PORT | 5432 | PostgreSQL 端口 |
PG_用户 | PostgreSQL | PostgreSQL 用户名 |
PG_密码 | PostgreSQL 密码 | |
PG_数据库 | PostgreSQL | 默认数据库名称 |
主持人 | 0.0.0.0 | 绑定 MCP 服务器的主机 |
港口 | 8056 | 运行 MCP 服务器的端口 |
发展
运行测试
# Install test dependencies
pip install -r requirements-dev.txt
# Run tests
pytest构建 Docker 镜像
docker build -t mcp-server-postgres .API 文档
有关详细的 API 文档,请参阅OpenAPI 规范。
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
致谢
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
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.
Related MCP Connectors
- SupabaseOAuthcom.supabase
MCP server for interacting with the Supabase platform
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Related MCP Servers
- AlicenseBqualityBmaintenanceA Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.181,632198AGPL 3.0
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.607MIT
- AlicenseNot gradedqualityCmaintenanceA Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.29MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to interact with PostgreSQL databases by executing SQL queries and inspecting database schemas. It provides tools for standardized database exploration and management through the Model Context Protocol.-
Appeared in Searches
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/asadudin/mcp-server-postgres'
If you have feedback or need assistance with the MCP directory API, please join our Discord server