PostgreSQL

Author:@modelcontextprotocol
View on GitHub

Overview

PostgreSQL is a Model Context Protocol server offering read-only access to PostgreSQL databases. It enables schema inspection and the execution of non-modifying queries.

To use it, add the required configuration to the claude_desktop_config.json file within Claude Desktop, specifically in the "mcpServers" section. Ensure you replace the placeholder database name with your actual database name.

Key features include executing read-only SQL queries inside a safe, read-only transaction. It provides detailed table schema information—such as column names and data types—and automatically discovers schemas from the database metadata.

Common use cases are inspecting database schemas to prepare for in-depth data analysis and running read-only queries to generate reports without risk of altering data. It also facilitates integration with LLMs for database-related tasks in applications.

Frequently asked questions clarify its read-only nature: it is not suitable for writing data. While designed for Claude Desktop, it can be integrated into other applications capable of calling its endpoints. Schema information for tables is auto-discovered and accessible via the provided schema endpoint.

Configuration

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/mydb"
      ]
    }
  }
}