modelcontextprotocol/server-postgres logo

modelcontextprotocol/server-postgres

Free

官方参考实现,集成 PostgreSQL,支持查询和模式分析。

FreeFree tier
Type
Open Source

About modelcontextprotocol/server-postgres

A Model Context Protocol (MCP) server that provides read-only access to PostgreSQL databases. It enables LLMs to inspect database schemas and execute read-only SQL queries within a READ ONLY transaction. The server automatically discovers table schemas and exposes them as resources, and provides a single 'query' tool for executing SQL. It is available as an npm package (@modelcontextprotocol/server-postgres) and a Docker image (mcp/postgres), making it easy to integrate with Claude Desktop or VS Code. Licensed under MIT.

Key Features

Execute read-only SQL queries via a single 'query' tool
Automatic discovery of database table schemas as resources
All queries run within a READ ONLY transaction for safety
Supports Docker and npx deployment
Integrates with Claude Desktop and VS Code
MIT licensed open source

Pros & Cons

Pros
  • Read-only mode ensures data integrity
  • Automatic schema discovery reduces manual configuration
  • Supports multiple deployment methods (Docker, npx)
  • Officially maintained by Model Context Protocol project
  • Lightweight and easy to set up
Cons
  • Repository archived as of May 2025, may not receive further updates
  • Only supports read-only queries (no INSERT/UPDATE/DELETE)
  • Requires explicit connection string configuration
  • No built-in authentication or authorization layer

Best For

LLM-based database schema explorationRead-only data retrieval for AI assistantsAutomated database inspection in development toolsSafe integration of LLMs with production databases

FAQ

How do I use this server with Claude Desktop?
Add the configuration to the 'mcpServers' section of your claude_desktop_config.json using either Docker (image mcp/postgres) or npx (@modelcontextprotocol/server-postgres) with your PostgreSQL connection URL.
How do I configure it for VS Code?
Add the JSON block to your User Settings (JSON) or .vscode/mcp.json file. You can use Docker (with host.docker.internal for host access) or npx, and optionally prompt for the database URL.
What database operations are allowed?
Only read-only SQL queries are supported. All queries are executed within a READ ONLY transaction to prevent any modifications.
How are database schemas exposed?
Table schemas are automatically discovered from database metadata and exposed as resources with URLs like postgres://host/table/schema, containing column names and data types in JSON format.
Is this server open source?
Yes, it is licensed under the MIT License.