Back to MCP directory
publicPublicdnsLocal runtime

pgsql-mcp-server

基于Model Context Protocol (MCP)的PostgreSQL数据库交互工具服务器,支持高性能异步操作和事务安全。

article

README

🚀 PostgreSQL MCP 服务器

一款强大的基于模型上下文协议(MCP)的工具服务器,支持通过MCP调用与PostgreSQL数据库交互,为数据库操作提供高效、便捷的解决方案。

🚀 快速开始

该项目基于 FastMCP 框架构建,并借助 SQLAlchemyasyncpg 库实现高效的异步数据库操作,确保在处理数据库请求时具备高效性和响应性。

✨ 主要特性

  • 异步且高效:完全异步实现基于 asyncio,使用 asyncpg 作为高性能的异步PostgreSQL驱动。
  • 事务安全:DDL、DML 和 DCL 操作均在事务中执行,并配有错误处理和回滚机制。
  • 部署简便:通过简单的命令行界面启动服务器。

📦 安装指南

请确保已安装 Python 3.8+。推荐使用 uvx 进行安装:

uvx pgsql-mcp-server --dsn postgresql://user:password@localhost:5432/db

💻 使用示例

预览与调试

您可以使用官方的 MCP 检查工具,以可视化方式检查服务器提供的工具、查看其参数和描述,并执行测试调用。

npx @modelcontextprotocol/inspector uvx pgsql-mcp-server --dsn "postgresql://user:password@host:port/database"

这将启动一个本地网络服务。在浏览器中打开提供的 URL 即可开始调试。

🤝 贡献

欢迎贡献!如果您有任何改进建议、特性请求或发现任何问题,请随时:

  1. 打开 问题 进行讨论。
  2. 叉取仓库并创建您的功能分支 (git checkout -b feature/AmazingFeature)。
  3. 提交您的更改 (git commit -m 'Add some AmazingFeature')。
  4. 推送到分支 (git push origin feature/AmazingFeature)。
  5. 打开 Pull Request
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client