连接器指南阅读约 2 分钟5 个 MCP 工具7 种语言

如何将 PostgreSQL 连接到 Claude — 通过 MCP

直接查询 PostgreSQL 数据库:列出表、描述列并运行只读 SQL。安装后为只读;凭证会加密保存,而不是放在连接字符串中。

HC作者:HelpCode 团队更新于 2 分钟阅读 在 GitHub 开源

无需信用卡 · 7 天试用 · 提供自托管方案

PostgreSQL

PostgreSQL

Query a PostgreSQL database directly: list tables, describe columns and run read-only SQL. Installs read-only; credentials are held encrypted rather than in the connection string.

个工具

5

区域

INTL

类别

数据库

身份验证

Connection string

所需环境变量

POSTGRES_HOSTPOSTGRES_PORTPOSTGRES_DATABASEPOSTGRES_USERPOSTGRES_PASSWORD
在 Cloud 上一键安装

7 天免费试用 · 无需信用卡

  • 7 天免费试用
    无需信用卡
  • 符合 GDPR,SOC 2 就绪
    数据驻留欧盟,审计日志
  • 在 GitHub 开源
    开源 · AGPL-3.0
  • 支持 ChatGPT、Claude、Gemini
    任何兼容 MCP 的客户端

跳过安装。2 分钟内即可运行。

在 cloud.anythingmcp.com 开始免费试用,一键添加 PostgreSQL,然后将你的 AI 客户端(Claude、ChatGPT、Copilot 或 Cursor)指向生成的 MCP 端点。无需 Docker,无需 git clone,无需任何工程经验。

开始免费试用

AnythingMCP 已收录在 Claude 的连接器目录中:一键添加到 Claude (在新标签页中打开),然后登录并选择 Claude 可以使用哪些 MCP 服务器。

摘要

直接查询 PostgreSQL 数据库:列出表、描述列并运行只读 SQL。安装后为只读;凭证会加密保存,而不是放在连接字符串中。

试试这样问

PostgreSQL 的示例提示

点击任意提示即可复制,然后粘贴到 Claude、ChatGPT、Cursor、Gemini、Copilot 或 OpenClaw 中,在该连接器上运行。

PostgreSQL · 通过 MCP 实时
分享
Opus 4.7

Claude 是 AI,可能会出错。请核对回答。

💡 无需安装? 直接使用 cloud.anythingmcp.com。 登录、点击 Connectors → PostgreSQL、粘贴凭证、生成 MCP API key — 完成。无 Docker、无 git clone、无本地服务器。

PostgreSQL + Claude

直接查询 PostgreSQL 数据库:列出表、描述列并运行只读 SQL。安装后为只读;凭证会加密保存,而不是放在连接字符串中。

前提条件

完整的设置说明已内置在连接器中 (在 store 中选择连接器时可见)。所需环境变量:

POSTGRES_HOST, POSTGRES_PORT, POSTGRES_DATABASE, POSTGRES_USER, POSTGRES_PASSWORD

步骤 1 — 获取凭证

Setup

  1. Create a dedicated role for the agent and grant it only what it needs:
    CREATE ROLE amcp_reader LOGIN PASSWORD 'change-me';
    GRANT CONNECT ON DATABASE sales TO amcp_reader;
    GRANT USAGE ON SCHEMA public TO amcp_reader;
    GRANT SELECT ON ALL TABLES IN SCHEMA public TO amcp_reader;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO amcp_reader;
    
    The last line matters: without it, tables created tomorrow are invisible.
  2. Set POSTGRES_HOST, POSTGRES_PORT (5432), POSTGRES_DATABASE, POSTGRES_USER and POSTGRES_PASSWORD.

…(continued in the in-app connector instructions)

步骤 2 — 安装 adapter

curl -fsSL https://raw.githubusercontent.com/HelpCode-ai/anythingmcp/main/docker-compose.quickstart.yml -o docker-compose.yml
printf 'JWT_SECRET=%s\nENCRYPTION_KEY=%s\n' "$(openssl rand -hex 32)" "$(openssl rand -hex 32)" > .env
docker compose up -d

步骤 3 — 在 Claude 中添加连接器

你的服务器 URL: 在 AnythingMCP 中打开 MCP Servers → 此连接器所在的服务器,复制它的 URL(https://cloud.anythingmcp.com/mcp/…)。本指南中出现 YOUR_SERVER_ID 的地方都用它替换。

推荐路径 — 在 claude.ai web 上工作,无需触碰任何配置文件。

  1. 在 Claude 中打开 Customize → Connectors。
  2. 点击 +,然后点击 Add custom connector。
  3. 输入名称(例如 PostgreSQL)和远程 MCP 服务器 URL https://cloud.anythingmcp.com/mcp/YOUR_SERVER_ID,然后点击 Add。
  4. 点击 Connect,登录 AnythingMCP(OAuth)并允许访问。

下面所有工具都会出现在你的聊天中 — 开始输入提示。

可用工具

ToolWhat it does
postgres_list_tablesList the tables and views in the database with their schema and, where the server tracks it, an approximate row count
postgres_describe_tableDescribe one table: every column with its data type, nullability and default
postgres_find_columnsFind columns across every table whose name matches a pattern — the fast way to locate where customer e-mail addresses, IBANs or order number
postgres_queryRun a read-only SQL statement against PostgreSQL and return up to 1000 rows
postgres_query_examplesShow worked example queries for PostgreSQL: how to list schemas, find large tables, inspect indexes and check what is running right now

FAQ

Claude Code 和 Claude Desktop 一样工作吗? 是的 — 两者都指向 https://cloud.anythingmcp.com/mcp/YOUR_SERVER_ID。

下一步

这份指南对你有帮助吗?

你的 PostgreSQL 智能体只差一次点击。

安装连接器,粘贴密钥,向 Claude 提问。免费试用 7 天,无需信用卡。

相关指南