PostgreSQL Multi-Schema MCP server

Provides read-only access to PostgreSQL databases with enhanced multi-schema support, enabling schema inspection, query execution, and isolation across multiple namespaces.
Back to servers
Provider
Harjot Singh Rana
Release date
Feb 25, 2025
Language
TypeScript
Package
Stats
431 downloads
3 stars

This PostgreSQL Multi-Schema MCP Server provides read-only access to PostgreSQL databases across multiple schemas. It enables language models to inspect database structures and execute safe, read-only queries while maintaining proper isolation between different database schemas.

Key Features

  • Multi-Schema Support: Explicitly specify which schemas to expose through command-line configuration
  • Schema Isolation: Strict access control to only authorized schemas listed during server startup
  • Cross-Schema Discovery: Unified view of tables across multiple schemas while maintaining schema boundaries
  • Metadata Security: Filters system catalogs to only expose user-defined tables in specified schemas

Installation

You can run the MCP server directly using npx without installing it globally:

npx -y mcp-server-postgres-multi-schema <database-url> [schemas]

Where:

  • database-url: PostgreSQL connection string (e.g., postgresql://localhost/mydb)
  • schemas: Comma-separated list of schemas to expose (defaults to 'public' if not specified)

Usage Examples

Basic Connection with Default Schema

To connect to a database using only the default public schema:

npx -y mcp-server-postgres-multi-schema postgresql://localhost/mydb

Multiple Schema Access

To connect with access to multiple schemas:

npx -y mcp-server-postgres-multi-schema postgresql://localhost/mydb public,analytics,staging

Configuring with Claude Desktop

To use this MCP server with Claude Desktop, add the "mcpServers" section to your claude_desktop_config.json file:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-postgres-multi-schema",
        "postgresql://localhost/mydb",
        "public,audit"
      ]
    }
  }
}

Capabilities

Available Tools

  • query: Execute read-only SQL queries against the connected database
    • Input: sql (string): The SQL query to execute
    • All queries execute within a READ ONLY transaction
    • Schema context is maintained through search_path restriction

Available Resources

The server provides schema information for tables across authorized schemas:

  • Table Schemas (postgres:///<db_schema>//schema)
    • JSON schema information for each table
    • Includes column names, data types, and type modifiers
    • Automatically discovered from database metadata
    • Multi-schema support with explicit schema allow-list

    How to add this MCP server to Cursor

    There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

    If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

    Adding an MCP server to Cursor globally

    To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

    When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

    {
        "mcpServers": {
            "cursor-rules-mcp": {
                "command": "npx",
                "args": [
                    "-y",
                    "cursor-rules-mcp"
                ]
            }
        }
    }
    

    Adding an MCP server to a project

    To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

    How to use the MCP server

    Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

    The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

    You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

    Want to 10x your AI skills?

    Get a free account and learn to code + market your apps using AI (with or without vibes!).

    Nah, maybe later