Lets AI coding agents query, modify, and inspect PostgreSQL databases, manage connection profiles, and diagnose performance.
Auch bekannt als microsoft/postgres-mcp, @microsoft/postgres-mcp
- Stars
- 86
- Tools
- —
- Downloads, 30 Tage
- —
- Neueste Version
- —
- Letzter Commit
- 5. Nov. 2026
- Lizenz
- MIT
Was ist PostgreSQL MCP?
PostgreSQL ist ein MCP server. Lets AI coding agents query, modify, and inspect PostgreSQL databases, manage connection profiles, and diagnose performance.
Zusammenfassung generiert aus dem README des Projekts
Über PostgreSQL MCP server
Coding agents that need to work directly against a PostgreSQL database can call postgres-mcp for queries, schema design, diagnostics and CSV imports. It runs on Node.js 22+ as an MCP server over stdio, started through npx with no install step, and works with any MCP client including GitHub Copilot, Claude Code, Codex, Open Code, Cursor, VS Code and Claude Desktop. Client configs point at the npx run command and carry no credentials; the agent picks up a saved profile at runtime.
Profiles are created once with the connection add command from a libpq URI or key=value string, and the password is kept in the OS keyring rather than a config file. Headless or CI setups without a keyring can take a connection string from the environment. Microsoft Entra ID is chosen automatically for Azure profiles with no stored keyring password. The tool set covers read-only SQL through postgres_mcp_query, DDL and DML through postgres_mcp_modify, CREATE scripts for tables, indexes, functions and sequences, CSV description and bulk loading via COPY, capability probing and performance metric groups.
Access control rests with the database role, since the server executes requests as that user; read-only profiles are set with access_mode: ro. Local file reads are limited to the startup working directory unless paths are allowed explicitly, and secrets are scrubbed from error messages.
Was du damit machen kannst
- 1Pull recent orders from PostgresAsk the agent to show the ten most recent orders so you can check test data without opening a SQL client.
- 2Find current database bottlenecksHave the agent collect performance metric groups to see what is slowing the server down right now.
- 3List tables in a databaseGet an inventory of tables in the connected database as a starting point for schema work.
Geschrieben aus dem README des Projekts. Jeder Use Case wurde gegen ein Zitat daraus geprüft.
So installierst du PostgreSQL MCP
Formate geprüft am 10. Nov. 2026PostgreSQL MCP in Claude Code installieren
$ claude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcpPostgreSQL MCP in Cursor installieren
~/.cursor/mcp.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}PostgreSQL MCP in VS Code installieren
.vscode/mcp.json
{
"servers": {
"postgres-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}PostgreSQL MCP in Claude Desktop installieren
claude_desktop_config.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}PostgreSQL MCP in Codex installieren
~/.codex/config.toml
[mcp_servers.postgres-mcp] command = "npx" args = ["-y", "@microsoft/postgres-mcp"]
PostgreSQL MCP in Gemini CLI installieren
~/.gemini/settings.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}Automatisierte Checks
Geluften am 13. Nov. 2026Vollständiger Bericht →Unsere automatisierten Checks bestanden. Das ist kein Security-Audit: Lies den Code und gib dem Server nur den minimal notwendigen Zugriff. Wie die Checks funktionieren
- Source Repository verknüpft und erreichbarBestanden
- Open Source Lizenz (OSI)Bestanden
- Commit oder Release im letzten JahrBestanden
- Package-Name ähnelt keinem populären PackageBestanden
- Remote Endpoint nutzt HTTPSNicht geprüft
- Destruktive Tools sind markiertNicht geprüft
- Keine versteckten Anweisungen an das ModellBestanden
- Kein kritischer Hinweis im Paket oder seinen AbhängigkeitenNicht geprüft
README
Auf GitHub ansehenPostgres 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.
- npm: https://www.npmjs.com/package/@microsoft/postgres-mcp
- No install required — run it straight from
npx.
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 addpermit write tools unlessaccess_mode: rois 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 |
| Query | read‑only SQL (postgres_mcp_query), DDL/DML (postgres_mcp_modify) |
| Schema | fetch CREATE scripts for tables, indexes, functions, sequences… |
| Data | describe a CSV, bulk‑load a CSV via COPY |
| Diagnostics | probe server capabilities, collect performance metric groups |
See the usage guide for tools, configuration, authentication (including Microsoft Entra ID), TLS, and the security model.
Security in one minute
- The server doesn't decide what's allowed — your database does. It just passes requests along to PostgreSQL and runs them as the database user in your connection profile. It can't tell the difference between a request you meant to make and one the AI invented or was tricked into making, so anything that database user can do, the AI can do. What actually protects you is the permissions you give that user, the approval prompts in your MCP client, and the model you choose to run. See Security model for who's responsible for what, plus a checklist for locking things down.
postgres_mcp_queryis read‑only. Omitted profileaccess_modepermits write tools; setaccess_mode: roand use a read-only database role unless writes are intentionally delegated.- Microsoft Entra ID (AAD) is selected automatically for Azure profiles without a stored keyring password. Store a profile password to use password authentication instead.
- Local file reads (
postgres_mcp_bulk_load_csv,postgres_mcp_describe_csv) are limited to the MCP server's startup working directory by default and paths allowed withallow-access-to-path <path>. A file allows only itself; a directory allows recursive access. - Secrets are scrubbed from error messages before they leave the process.
See more info about security model in the usage guide.
Requirements
- Node.js 22+ (to run via
npx). - Linux x64/arm64, macOS x64/arm64, or Windows x64. Windows ARM uses x64 emulation.
- A reachable PostgreSQL database — local, Docker, on‑premises, Azure Database for PostgreSQL, Amazon RDS/Aurora, Google Cloud SQL/AlloyDB, or any wire‑compatible server.
Changelog
See CHANGELOG.md for release notes.
License
This repository is a getting started information package. It is licensed under the MIT License © Microsoft. The postgres-mcp project itself is proprietary and its source code is not avialable under MIT license.
PostgreSQL MCP Fragen
Wie füge ich PostgreSQL MCP zu Claude Code hinzu?
Führe claude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcp in deinem Terminal aus. Füge --scope user hinzu, damit der Server in jedem Projekt verfügbar ist.
Wie füge ich PostgreSQL MCP zu Cursor hinzu?
Öffne ~/.cursor/mcp.json und füge den Server unter mcpServers hinzu, mit der Cursor-Config aus dem Installationsabschnitt oben.
How do I connect postgres-mcp to Claude Code or GitHub Copilot?
Add a stdio entry pointing at npx @microsoft/postgres-mcp run in your client's mcpServers config; no credentials go in that config.
Where is the database password stored?
Passwords are saved in the OS keyring with connection set-password, not in a config file.
Is the query tool read-only?
Yes, postgres_mcp_query is read-only, but write tools are available unless the profile sets access_mode to ro.
Can I use it without saving a profile, e.g. in CI?
Yes, the server can take a database connection string from the environment when no keyring is available.
What Node.js version does it require?
Node.js 22 or newer is required to run it via npx.