PostgreSQL MCP Server
Provides tools for interacting with PostgreSQL databases in a multi-tenant setup, including listing tenants, exploring schemas, running read-only queries, and executing writes or DDL statements.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCP Serverwhich tenant has the most users?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL MCP Server
Safe, tool-based access to a multi-tenant PostgreSQL setup — for Cursor, Claude Desktop, or any MCP client.
One admin database holds tenant connection records. Every tenant gets its own isolated database. The agent discovers tenants, explores schemas, and runs queries — all through natural language, with reads and writes kept in separate tools so nothing destructive happens by accident.
Stack: TypeScript · Official MCP SDK · pg · stdio transport
Table of Contents
Related MCP server: postgres-mcp-server
Why this exists
In a multi-tenant architecture, every tenant's data lives in its own database — great for isolation, painful for day-to-day access. Checking a tenant's data normally means finding the right connection string, opening a DB client, and writing SQL by hand, every single time.
This server removes that friction. Point your MCP client at it, and you can ask things like "which tenant has the most users?" — the agent resolves the tenant, opens the right connection, and runs the query for you.
Architecture
MCP Client (Cursor / Claude Desktop / etc.)
│ stdio · JSON-RPC
▼
postgres-mcp-server (this repo)
│
├── Admin DB → "Tenant" registry
│ (id, dbHost, dbName, dbUsername, dbPassword)
│
└── Tenant DBs → one connection pool per tenantId
(cached, max 3 connections each)How a request flows:
On startup, the server opens a pool to the admin DB via
ADMIN_DATABASE_URL.When a tool call includes a
tenantId, the server looks up that tenant's connection details in the"Tenant"table.A dedicated pool is opened (or reused, if cached) for that tenant only.
Every data tool requires an explicit
tenantId— there is no code path that spans two tenants in one query.
Tools
Tool | Access | Purpose |
| Read | List all tenants from the admin DB — your entry point for a |
| Read | List tables in a tenant's database |
| Read | Column names, types, nullability, defaults |
| Read | Approximate row counts per table |
| Read | Run |
| Read | Run |
| Write |
|
| Schema |
|
Read, write, and schema operations are split into separate tools on purpose — you can disable an entire category (e.g. remove write access) by commenting out one tool registration.
Requirements
Node.js 18+
An admin PostgreSQL database with a
"Tenant"table (see below)Tenant databases reachable from the machine running the MCP client
Admin "Tenant" table
CREATE TABLE IF NOT EXISTS "Tenant" (
id TEXT PRIMARY KEY,
"dbHost" TEXT NOT NULL,
"dbName" TEXT NOT NULL,
"dbUsername" TEXT NOT NULL,
"dbPassword" TEXT NOT NULL
);Register a tenant:
INSERT INTO "Tenant" (id, "dbHost", "dbName", "dbUsername", "dbPassword")
VALUES ('tenant-001', 'db.example.com', 'my_tenant_db', 'db_user', 'db_password');Setup
git clone https://github.com/RISHAB-SIKKA/PostgreSQL-MCP-Server.git
cd PostgreSQL-MCP-Server
npm install
npm run buildQuick smoke test — the process should stay running:
export ADMIN_DATABASE_URL="postgresql://USER:PASSWORD@HOST:5432/ADMIN_DB?sslmode=require"
node build/index.js
# → Multi-tenant Postgres MCP server running (stdio).Press Ctrl+C to stop.
Connect to an MCP client
Cursor
Add to ~/.cursor/mcp.json (or a project-level .cursor/mcp.json):
{
"mcpServers": {
"postgres-db": {
"command": "node",
"args": ["/absolute/path/to/PostgreSQL-MCP-Server/build/index.js"],
"env": {
"ADMIN_DATABASE_URL": "postgresql://USER:PASSWORD@HOST:5432/ADMIN_DB?sslmode=require",
"DB_PORT": "5432",
"DATABASE_SCHEMA": "public",
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
}
}
}
}Open Customize → MCPs, confirm postgres-db shows as connected, then ask in Agent chat: "List all tenants."
Claude Desktop
Add to claude_desktop_config.json:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"postgres-db": {
"command": "node",
"args": ["/absolute/path/to/PostgreSQL-MCP-Server/build/index.js"],
"env": {
"ADMIN_DATABASE_URL": "postgresql://USER:PASSWORD@HOST:5432/ADMIN_DB?sslmode=require",
"DB_PORT": "5432",
"DATABASE_SCHEMA": "public"
}
}
}
}Environment variables
Variable | Required | Default | Notes |
| Yes | — | Connection string for the admin database |
| Recommended |
| Port used for all tenant connections — set this to match your tenants |
| No |
|
|
| Sometimes | — | Set to |
Port tip: Tenant host, username, and password come from the
"Tenant"table, but the port always comes fromDB_PORT. If your tenants listen on a non-default port (e.g.1186), setDB_PORTaccordingly — it applies to every tenant connection.
Example prompts
"List all tenants."
"Show tables for tenant
tenant-001.""Describe the
userstable for that tenant.""Run a read-only query counting rows created this month."
"Which tenant has the most registered users?"
Typical flow: list_tenants → list_tables / describe_table → query
Project layout
src/index.ts # MCP server + tool definitions
build/ # tsc output (gitignored)
package.json
tsconfig.jsonSecurity notes
queryandadmin_queryare gated toSELECT/WITHonly;executerefusesUPDATE/DELETEwithout aWHEREclause. These checks catch statement type, not injected SQL inside a statement — always pass values via$1, $2…params rather than string-concatenating them intosql.Tenant credentials (
dbPassword) are stored in plaintext in the"Tenant"table. Consider encrypting at rest or moving to a secrets manager for production use.NODE_TLS_REJECT_UNAUTHORIZED=0disables certificate verification — fine for local dev against self-signed/managed hosts, but should never ship to production.execute_ddlhas no confirmation step. If you don't need schema changes from the agent, comment out that tool registration.
License
ISC
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
- dataOAuthco.thinair
Read-only PostgreSQL, MySQL, SQL Server access via MCP — 24 dialect-aware hosted tools.
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to interact with PostgreSQL databases, providing tools for querying, table listing, schema exploration, and multi-environment management with write protection and schema scoping.1MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI assistants to execute SQL queries and inspect PostgreSQL database schemas via MCP tools.-
- AlicenseNot gradedqualityCmaintenanceA read-only natural-language database agent that exposes PostgreSQL schema-discovery and SELECT tools via MCP, enabling users to query databases in plain English.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to securely interact with PostgreSQL databases through a standardized MCP interface, supporting SQL queries, schema inspection, and database management.MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/RISHAB-SIKKA/PostgreSQL-MCP-Server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server