Skip to main content
Glama
aeiyannn

PostgreSQL MCP Server

by aeiyannn

PostgreSQL MCP 服务器

一个连接到本地 PostgreSQL 数据库的 MCP (Model Context Protocol) 服务器,使 AI 助手能够查询和管理您的数据库。

提供的工具

工具

描述

query

执行只读 SQL (SELECT, SHOW, EXPLAIN)

execute

执行写入 SQL (INSERT, UPDATE, DELETE, CREATE, ALTER, DROP)

list_tables

列出模式中的所有表

describe_table

显示表的列、类型、键和索引

list_schemas

列出数据库中的所有用户模式

Related MCP server: PostgreSQL MCP Server

资源

  • schema-overview (postgres://schema/overview) — Markdown 格式的完整数据库模式概览

通过标头进行动态连接

此服务器支持动态 PostgreSQL 连接。您可以在初始 SSE 连接请求中通过 HTTP 标头提供数据库凭据。这允许单个已部署的服务器实例服务于多个不同的数据库。

支持的标头

标头

描述

默认值

x-pg-host

PostgreSQL 主机

PG_HOSTlocalhost

x-pg-port

PostgreSQL 端口

PG_PORT5432

x-pg-user

PostgreSQL 用户

PG_USERpostgres

x-pg-password

PostgreSQL 密码

PG_PASSWORDpostgres

x-pg-database

PostgreSQL 数据库

PG_DATABASEpostgres

x-pg-ssl

使用 SSL (true/false)

PG_SSLfalse

x-pg-ca-cert

CA 证书

PG_CA_CERT


在 Antigravity / Cursor (VS Code) 中配置

要在 AntigravityCursor 中使用此服务器,请将以下内容添加到您的 mcp_config.json(通常位于 %APPDATA%\antigravity\ 或您的 IDE 的 MCP 设置中):

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://postgree-mcp-dfadduf9bsdvdwa9.eastasia-01.azurewebsites.net/sse",
        "--header", "x-pg-host: pg-168600c0-aeiyankhan2-d42e.g.aivencloud.com",
        "--header", "x-pg-port: 26768",
        "--header", "x-pg-user: avnadmin",
        "--header", "x-pg-password: YOUR_PASSWORD",
        "--header", "x-pg-database: defaultdb",
        "--header", "x-pg-ssl: true"
      ]
    }
  }
}

在 Claude Code CLI 中配置

如果您使用 Claude Code CLI,可以使用以下命令添加此服务器:

1. 安装 Claude Code(如果尚未安装)

npm install -g @anthropic-ai/claude-code

2. 添加 PostgreSQL MCP 服务器

在您的终端中运行此命令:

claude mcp add postgres -- npx mcp-remote https://postgree-mcp-dfadduf9bsdvdwa9.eastasia-01.azurewebsites.net/sse \
  --header "x-pg-host: pg-168600c0-aeiyankhan2-d42e.g.aivencloud.com" \
  --header "x-pg-port: 26768" \
  --header "x-pg-user: avnadmin" \
  --header "x-pg-password: YOUR_PASSWORD" \
  --header "x-pg-database: defaultdb" \
  --header "x-pg-ssl: true"

在 Claude Desktop 中配置

将此内容添加到您的 claude_desktop_config.json

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://postgree-mcp-dfadduf9bsdvdwa9.eastasia-01.azurewebsites.net/sse",
        "--header", "x-pg-host: pg-168600c0-aeiyankhan2-d42e.g.aivencloud.com",
        "--header", "x-pg-port: 26768",
        "--header", "x-pg-user: avnadmin",
        "--header", "x-pg-password: YOUR_PASSWORD",
        "--header", "x-pg-database: defaultdb",
        "--header", "x-pg-ssl: true"
      ]
    }
  }
}

本地设置(用于开发)

1. 安装依赖项

npm install

2. 配置默认数据库(可选)

您仍然可以使用 .env 文件进行本地开发:

PG_HOST=localhost
PG_PORT=5432
PG_USER=postgres
PG_PASSWORD=your_password_here
PG_DATABASE=your_database_name

3. 构建并运行

npm run build
npm start

使用示例

配置完成后,您可以向 AI 助手询问如下内容:

  • "列出我数据库中的所有表"

  • "描述 users 表"

  • "SELECT * FROM orders WHERE created_at > '2025-01-01'"

  • "创建一个名为 products 的新表"

A
license - permissive license
Not graded
quality - not tested
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Enables Claude to interact with a local PostgreSQL database through SQL queries, schema inspection, and CRUD operations.
    8
    225
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to query and explore PostgreSQL databases with tools for executing SQL queries, listing tables, and describing table structures.
    MIT

View all related MCP servers

Related MCP Connectors

  • Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.

  • Comprehensive PostgreSQL documentation and best practices, including ecosystem tools

  • Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…

View all MCP Connectors

Latest Blog Posts

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/aeiyannn/postgree-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server