MP

microsoft/postgres-mcp

开发工具官方

本页由 AI 翻译,技术细节请以原文为准。 查看原文

87 stars 3 forks 质量 85 趋势 17MIT

PostGRES-MCP允许你生成查询并运行分析,设计数据库模式,诊断服务器和查询的性能,安全管理连接,并导入数据。

概览

Postgres-MCP 允许您生成查询并运行分析,设计数据库模式,诊断服务器和查询的性能,安全管理连接并导入数据。它兼容任何 MCP 客户端——GitHub Copilot、Claude Code、Codex、Open Code、Cursor、VS Code 等。 - https://www.npmjs.com/package/@microsoft/postgres-mcp - ——直接从NPX跑。 创建一个命名配置文件一次——密码存储在操作系统密钥圈中,绝不存储在配置文件中: 连接创建的配置文件添加许可写入工具,除非access_mode:ro被设置。对于不应写入的自治代理,使用显式只读配置文件,即只读数据库角色——参见只读配置文件。 服务器通过stdio使用MCP。将你的客户端指向npx @microsoft/postgres-mcp运行——客户端配置中没有凭证;编码代理会在运行时发现并连接到你保存的配置文件。 — 使用 mcpServers 格式(~/.copilot/mcp-config.json、mcp.json、.cursor/mcp.

概述(AI 翻译)

将你的编码代理连接到PostgreSQL。 postgres-mcp 可以让你生成 查询并运行分析,设计数据库模式,诊断性能 服务器和查询,安全管理连接,导入数据。是的 兼容任何MCP客户端——GitHub Copilot、Claude Code、Codex、Open Code, 光标、VS Code等。

快速开始

1.保存连接配置文件

创建一个命名配置文件一次——密码存储在操作系统密钥圈里,永远不会存储在 一个配置文件:

由connection add创建的配置文件允许写入工具,除非 access_mode: ro 是设置的。对于不应写入的自主代理,请使用 显式只读配置文件 和只读数据库角色 — 参见 只读配置文件。

2.将 postgres-mcp 添加到你的编码代理中

服务器通过stdio使用MCP通信。指向你的客户端 npx @microsoft/postgres-mcp run — 客户端配置中不放入凭证;该 编码代理会在运行时发现并连接你保存的配置文件。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Postgres MCP Server

Connect your coding agent to PostgreSQL. postgres-mcp lets you generate queries and run analytics, design database schemas, diagnose performance of the server and queries, securely manage connections, and import data. It is compatible with any MCP client — GitHub Copilot, Claude Code, Codex, Open Code, Cursor, VS Code, and more.

Quick start

1. Save a connection profile

Create a named profile once — the password is stored in your OS keyring, never in a config file:

# add a profile from a libpq URI or key=value string
npx -y @microsoft/postgres-mcp connection add local \
  "postgresql://postgres@localhost:5432/postgres"

# store its password securely (hidden prompt)
npx -y @microsoft/postgres-mcp connection set-password local

# check it
npx -y @microsoft/postgres-mcp connection list

Profiles created by connection add permit write tools unless access_mode: ro is set. For autonomous agents that should not write, use an explicit read-only profile and a read-only database role — see Read-only profiles.

2. Add postgres-mcp to your coding agent

The server speaks MCP over stdio. Point your client at npx @microsoft/postgres-mcp run — no credentials go in the client config; the coding agent discovers and connects to your saved profile at runtime.

GitHub Copilot CLI, Claude Code, Cursor & Claude Desktop — clients that use the mcpServers format (~/.copilot/mcp-config.json, mcp.json, .cursor/mcp.json, claude_desktop_config.json, …):

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@microsoft/postgres-mcp", "run"]
    }
  }
}

Running headless or in CI, without a keyring? The server can also take a database connection string from the environment — see Connecting without a profile in the guide.

3. Ask your coding agent

“List the tables in my PostgreSQL database.” “Show me the 10 most recent orders from my PostgreSQL database.” “What’s slowing down my PostgreSQL server right now?”

The agent calls the server’s tools (postgres_mcp_connect, postgres_mcp_query, postgres_mcp_db_context, …) for you.


What it can do

Area Tools
Connections list / add / remove profiles, connect, disconnect, list databases
在 GitHub 查看完整 README

安装

npx -y @microsoft/postgres-mcp run
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "postgres": { "command": "npx", "args": ["-y", "@microsoft/postgres-mcp", "run"] } } }