home / mcp / postgresql multi-schema mcp server

PostgreSQL Multi-Schema MCP Server

A Model Context Protocol server that provides read-only access to PostgreSQL databases with enhanced multi-schema support.

Installation
Add the following to your MCP client configuration file.

Configuration

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

You run a PostgreSQL MCP Server that exposes read-only access to multiple schemas, letting you inspect schemas across namespaces while keeping strict isolation. It provides a single, unified way to query and explore tables across authorized schemas without risking cross-schema access.

How to use

You connect to the MCP server from an MCP client by using the provided command, which runs the server in a process you can control from your environment. The server accepts a database URL and a comma-separated list of schemas to expose. It ensures all queries run in a read-only transaction and maintains the correct schema context for every operation.

How to install

Prerequisites you need before starting are minimal because you run through a local command with a built-in package runner.

Install Node.js if you do not already have it. You can download it from the official Node.js site or use your system package manager.

Use the following commands to run the server directly with the MCP client. You do not need a separate build step to execute these commands.

npx -y mcp-server-postgres-multi-schema 
  https://localhost:5432/mydb-multi 
  public,audit

Claude Desktop configuration and usage

If you use Claude Desktop, add an MCP server entry in your Claude configuration to run the MCP server through NPX. This enables Claude to interact with the multi-schema server directly.

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

Notes on usage and behavior

- The server exposes only the specified schemas to ensure strict schema isolation. Unauthorized schemas are not accessible.

- Querying is read-only by design. Each operation runs within a read-only transaction to prevent schema modification.

- You can discover metadata about user-defined tables across the allowed schemas, with schema boundaries preserved in results.

Security and access model

Access to data is limited to the explicitly allowed schemas supplied at startup. The server does not expose system catalogs beyond what is necessary to describe user-defined tables in those schemas.

Examples of usage patterns

- Connect to a single schema, e.g., public, to inspect its tables and run read-only queries.

- Connect to multiple schemas in one session to get a cross-schema view of tables while maintaining their distinct namespaces.

Troubleshooting

If you encounter connection errors, verify that the database URL is correct and that the server is started with the intended list of schemas. Check that your client points to the correct host and port and that the schemas you requested exist in the database.

Available tools

query

Execute read-only SQL queries against the connected database. Accepts input sql as a string. All queries run in a READ ONLY transaction with the schema context maintained via a restricted search_path.