PostgreSQL MCP服务

一个通过自然语言实现PostgreSQL数据库交互的MCP(Model-Context-Protocol)服务器,为语言模型(LLMs)提供结构化的数据库访问和操作功能。

  • by lzvxck
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 lioarce01/postgres-mcp-server

使用说明

Postgres MCP服务器

该项目实现了一个MCP(模型上下文协议)服务器,用于使用LLM(语言模型)与PostgreSQL数据库进行交互。它允许通过自然语言对PostgreSQL数据库进行结构化访问和操作。

特性

  • 向LLM公开PostgreSQL接口
  • 使用TypeScript和Node.js
  • 使用TypeScript编译
  • 使用多阶段构建的轻量级Docker镜像

需求

  • 码头工人
  • PostgreSQL数据库

地方发展

要在本地运行:

pnpm install
pnpm run build
node dist/index.js postgresql://<user>:<password>@<host>:<port>/<database>

例子:

node dist/index.js postgresql://postgres:admin@localhost:5432/postgres

Docker使用

构建Docker镜像

docker build -t postgres-mcp .

使用Docker运行

docker run --rm -it postgres-mcp postgresql://username:password@host.docker.internal:5432/mydb

LLM集成(例如与Claude或VSCode副驾驶)

要配置服务器以与LLM代理一起使用,请执行以下操作:

{
  "mcpServers": {
    "postgres": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "postgres-mcp",
        "postgresql://username:password@host.docker.internal:5432/mydb"
      ]
    }
  }
}

项目结构

├── index.ts
├── dist/
├── Dockerfile
├── LICENSE
├── README.md
├── package.json
├── tsconfig.json
└── pnpm-lock.yaml

许可证

麻省理工学院