Memungkinkan AI coding agent untuk melakukan query, modifikasi, dan inspeksi database PostgreSQL, mengelola profil koneksi, serta mendiagnosis performa.
Juga dikenal sebagai microsoft/postgres-mcp, @microsoft/postgres-mcp
- Stars
- 86
- Tools
- —
- Unduhan, 30 hari
- —
- Versi terbaru
- —
- Commit terakhir
- 5 Nov 2026
- Lisensi
- MIT
Apa itu PostgreSQL MCP?
PostgreSQL adalah MCP server. Memungkinkan AI coding agent untuk melakukan query, modifikasi, dan inspeksi database PostgreSQL, mengelola profil koneksi, serta mendiagnosis performa.
Ringkasan dibuat dari README proyek
Tentang PostgreSQL MCP server
Coding agent yang perlu bekerja langsung pada database PostgreSQL dapat memanggil postgres-mcp untuk keperluan query, desain skema, diagnostik, dan import CSV. Tool ini berjalan di Node.js 22+ sebagai MCP server melalui stdio, dijalankan melalui npx tanpa perlu langkah install, dan kompatibel dengan semua MCP client termasuk GitHub Copilot, Claude Code, Codex, Open Code, Cursor, VS Code, dan Claude Desktop. Konfigurasi client hanya mengarah ke perintah npx run dan tidak menyimpan kredensial; agent akan mengambil profil yang tersimpan saat runtime.
Profil dibuat satu kali menggunakan perintah connection add dari libpq URI atau string key=value, dan password disimpan di OS keyring alih-alih di file config. Setup headless atau CI tanpa keyring dapat menggunakan connection string dari environment. Microsoft Entra ID dipilih secara otomatis untuk profil Azure tanpa password keyring yang tersimpan. Kumpulan tool mencakup SQL read-only melalui postgres_mcp_query, DDL dan DML melalui postgres_mcp_modify, script CREATE untuk tabel, index, function, dan sequence, deskripsi CSV dan bulk loading via COPY, probing kapabilitas, serta grup metrik performa.
Kontrol akses bergantung pada database role, karena server mengeksekusi permintaan sebagai user tersebut; profil read-only dapat diatur dengan access_mode: ro. Pembacaan file lokal dibatasi pada direktori kerja saat startup kecuali path diizinkan secara eksplisit, dan informasi rahasia (secrets) akan dihapus dari pesan error.
Apa yang bisa Anda lakukan dengannya
- 1Mengambil pesanan terbaru dari PostgresMinta agent untuk menampilkan sepuluh pesanan terbaru sehingga Anda dapat memeriksa data uji tanpa harus membuka SQL client.
- 2Menemukan bottleneck database saat iniMinta agent untuk mengumpulkan grup metrik performa guna melihat apa yang memperlambat server saat ini.
- 3Mendaftar tabel dalam databaseDapatkan inventaris tabel dalam database yang terhubung sebagai langkah awal untuk pekerjaan skema.
Ditulis berdasarkan README proyek. Setiap use case diperiksa terhadap kutipan dari README tersebut.
Cara menginstal PostgreSQL MCP
Format diverifikasi 10 Nov 2026Instal PostgreSQL MCP di Claude Code
$ claude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcpInstal PostgreSQL MCP di Cursor
~/.cursor/mcp.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}Instal PostgreSQL MCP di VS Code
.vscode/mcp.json
{
"servers": {
"postgres-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}Instal PostgreSQL MCP di Claude Desktop
claude_desktop_config.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}Instal PostgreSQL MCP di Codex
~/.codex/config.toml
[mcp_servers.postgres-mcp] command = "npx" args = ["-y", "@microsoft/postgres-mcp"]
Instal PostgreSQL MCP di Gemini CLI
~/.gemini/settings.json
{
"mcpServers": {
"postgres-mcp": {
"command": "npx",
"args": [
"-y",
"@microsoft/postgres-mcp"
]
}
}
}Pengecekan otomatis
Berjalan 13 Nov 2026Laporan lengkap →Lolos checks otomatis kami. Ini bukan audit keamanan: baca kodenya dan berikan server akses paling terbatas yang dibutuhkannya. Cara kerja checks
- Source repository terhubung dan dapat dijangkauLolos
- Lisensi open source (OSI)Lolos
- Ada commit atau release dalam satu tahun terakhirLolos
- Nama package tidak mirip dengan package populerLolos
- Remote endpoint menggunakan HTTPSTidak diperiksa
- Tools yang bersifat destruktif telah diberi labelTidak diperiksa
- Tidak ada instruksi tersembunyi untuk modelLolos
- Tidak ada advisory kritis di paket maupun dependensinyaTidak diperiksa
README
Lihat di GitHubPostgres 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.
Pertanyaan tentang PostgreSQL MCP
Bagaimana cara menambahkan PostgreSQL MCP ke Claude Code?
Jalankan claude mcp add postgres-mcp -- npx -y @microsoft/postgres-mcp di terminal Anda. Tambahkan --scope user agar tersedia di semua proyek.
Bagaimana cara menambahkan PostgreSQL MCP ke Cursor?
Buka ~/.cursor/mcp.json dan tambahkan server di bawah mcpServers, menggunakan config Cursor yang ditunjukkan di bagian instalasi di atas.
Bagaimana cara menghubungkan postgres-mcp ke Claude Code atau GitHub Copilot?
Tambahkan entri stdio yang mengarah ke npx @microsoft/postgres-mcp run pada config mcpServers di client Anda; tidak ada kredensial yang perlu dimasukkan ke dalam config tersebut.
Di mana password database disimpan?
Password disimpan di OS keyring menggunakan perintah connection set-password, bukan di dalam file config.
Apakah query tool bersifat read-only?
Ya, postgres_mcp_query bersifat read-only, tetapi write tools tersedia kecuali jika profil mengatur access_mode ke ro.
Bisakah saya menggunakannya tanpa menyimpan profil, misalnya di CI?
Ya, server dapat mengambil database connection string dari environment saat keyring tidak tersedia.
Versi Node.js apa yang dibutuhkan?
Dibutuhkan Node.js 22 atau versi terbaru untuk menjalankannya via npx.