PostgreSQL

PostgreSQL

🚀 MCP PostgreSQL 服务器

MCP PostgreSQL 服务器基于模型上下文协议(MCP)构建,借助 MCP 工具实现对 PostgreSQL 数据库的便捷操作,为数据库管理提供高效解决方案。

🚀 快速开始

MCP PostgreSQL 服务器可通过一系列简单步骤完成安装与启动,以下是详细指引:

  1. 克隆仓库:
git clone https://github.com/a21071/mcp-postgres.git
cd mcp-postgres
  1. 安装依赖:
npm install
  1. 配置 PostgreSQL 数据库:
docker-compose up -d
  1. 运行数据库迁移:
npx prisma migrate dev
  1. 构建项目:
npm run build
  1. 运行服务器:
npm start

✨ 主要特性

  • 实体 CRUD 操作:支持用户和帖子实体的创建、读取、更新和删除操作。
  • 类型安全操作:借助 Prisma 实现类型安全的数据库操作,保障数据处理的准确性。
  • 工具接口兼容:提供与 MCP 兼容的工具接口,方便集成其他系统。
  • 类型安全保障:采用 TypeScript 编写,确保代码的类型安全。

💻 使用示例

基础用法

运行服务器:

npm start

高级用法

可用的 MCP 工具

  • getData:从 PostgreSQL 检索用户数据
{
"tableName": "user"
}
  • addUserData:添加新用户到数据库
{
"email": "user@example.com",
"name": "John Doe",
"age": 30
}
  • deleteUserData:根据 ID、邮箱或名称删除用户
{
"id": "clxyz...",
"email": "user@example.com",
"name": "John Doe"
}
  • updateUserData:更新用户信息
{
"id": "clxyz...",
"email": "new@example.com",
"name": "New Name"
}

🔧 技术细节

该服务器使用以下 Prisma 模式:

model User {
id        String   @id @default(cuid())
email     String   @unique
name      String?
age       Int?
createdAt DateTime @default(now())
posts     Post[]
}

📦 开发相关

监视模式

若需在开发过程中实时监控代码变化,可使用监视模式:

npm run watch

📚 依赖项

📄 许可证

本项目采用 MIT 许可证。

  • 0 关注
  • 0 收藏,11 浏览
  • system 提出于 2025-09-24 18:15

相似服务问题