home / mcp / mcp postgresql server

MCP PostgreSQL Server

Provides read-only PostgreSQL access via MCP with selectable queries, schema exploration, and common read-only utilities.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "japentaca-mcp-postgres-readonly": {
      "url": "https://mcp.example.com/mcp/postgresql",
      "headers": {
        "PORT": "3000",
        "NODE_ENV": "production",
        "MCP_PG_CONNSTR": "postgresql://user:pass@localhost:5432/db"
      }
    }
  }
}

You set up a dedicated MCP server that connects to your PostgreSQL database and only allows read-only SELECT queries. This keeps your data safe while letting you explore schemas, list tables, and run common read-only queries from any MCP client.

How to use

You use the MCP server by configuring a read-only connection string in your project and then starting the MCP server to serve queries to your MCP clients. The server reads the connection string from MCP_PG_CONNSTR in the root of the project you are editing. Your clients can then ask the MCP server to run prepared SELECT queries, list tables, describe tables, and perform predefined helpful queries.

How to install

Prerequisites: Node.js 18 or higher, a PostgreSQL database that your client has read access to.

git clone <repository-url>
cd postgres
npm install

Additional configuration and usage notes

Place the environment configuration in the root of the project you are editing (not in the MCP server folder). Create a .env file at the root of your project and define MCP_PG_CONNSTR with your PostgreSQL connection string.

# In the root of your project (not inside the MCP server folder)
MCP_PG_CONNSTR=postgresql://usuario:contraseña@localhost:5432/basededatos

Run the MCP server

Start the MCP server from its local directory using the normal run commands shown for the server. You can use the standard start flow or development flow as needed.

# Normal start
npm start

# Development with auto-restart
npm run dev

Integration with Claude Desktop

If you use Claude Desktop, point the client to the local MCP server by configuring the MCP connection in Claude’s config. Use the server as a local stdio MCP endpoint so Claude can communicate with it through the same interface you use for other MCP servers.

Available tools

execute_select_query

Runs a custom SELECT query with optional prepared statement parameters.

list_tables

Lists all tables available in the connected database.

describe_table

Returns detailed information about table columns.

execute_common_queries

Executes predefined useful queries such as database version, current user, current database, and table sizes.