PostgreSQL代理服务

一个集成Claude LLM的PostgreSQL数据库模型上下文协议(MCP)服务器,用于智能查询和管理数据库。

  • by shnkreddy98
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 shnkreddy98/postgres-agent

使用说明

Postgres代理

与Claude LLM集成的PostgreSQL数据库的模型上下文协议(MCP)服务器。

先决条件

安装uv(Python包管理器):

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# Or with pip
pip install uv

快速开始

1.克隆和设置

git clone https://github.com/shnkreddy98/postgres-agent.git
cd postgres-agent
uv venv
uv sync

2.激活虚拟环境

source .venv/bin/activate
# On Windows: .venv\Scripts\activate

3.设置环境变量

创建一个 .env 项目根目录中的文件:

ANTHROPIC_API_KEY=your_anthropic_api_key_here
PGUSER=your_postgres_username
PGDATABASE=your_database_name
PGHOST=localhost
PGPASSWORD=your_postgres_password

4.运行服务器

uv run main.py postgres_server.py

替代方案:使用Claude Desktop进行配置

添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "postgres-agent": {
      "command": "uv",
      "args": ["run", "main.py", "postgres_server.py"],
      "cwd": "/path/to/postgres-agent"
    }
  }
}

然后重新启动Claude Desktop。

就是这样!现在,您可以让Claude查询您的PostgreSQL数据库。