Claude Marketplaces
SkillsMCP serversMarketplacesDigestTools
Submit

This week in Claude

Every Monday: Claude Code, Agent SDK, MCP, and the Anthropic platform moves worth your time.

Skills by category
Frontend DevelopmentBackend & APIsTesting & QASecurityDevOps & CI/CDGit & Pull RequestsDocumentationCode Review & QualityAI & Agent BuildingSkill Development
MCP servers by category
Sales & MarketingWeb & Browser AutomationDatabasesAI & LLM ToolsCloud & InfrastructureCommunication & MessagingDeveloper ToolsDesign & CreativeDocuments & KnowledgeSearch & Web Crawling
Marketplaces by category
AI Agents & OrchestrationLLM IntegrationDevelopment ToolsFrontend & UIBackend & APIsDatabasesTesting & Code QualityDevOps & CloudSecurity & ComplianceGit & Version Control
Claude Marketplaces

An independent directory of skills, plugins and MCP servers for Claude Code. Not affiliated with Anthropic.

Browse

  • Skills
  • MCP servers
  • Marketplaces
  • Weekly digest
  • Skill index
  • MCP index
  • Marketplace index

Site

  • About
  • Tools
  • Submit
  • Feedback
  • Privacy
  • llms.txt
  • Plugins reference

Maker

  • Snug
  • Agent Caffeine
  • knobs
  • Wax
  • Vectoys
  • mertduzgun.com
Crafted at
MCP servers/Databases
edelciomolina avatar

Postgres MCP

edelciomolina/postgres-mcp

A PostgreSQL MCP server that keeps database credentials out of your config files by reading them from .env at runtime. It maps any variable names you want through MCP_KEY_* environment variables, so you can use DATABASE_URL from Supabase or DB_HOST from Railway without changing your existing setup. Ships read-only by default with introspection tools only. Write operations like pg_manage_schema or pg_manage_indexes require explicit opt-in via tool= arguments and a POSTGRES_MCP_ALLOW_WRITE flag. Works via npx without installation, which makes it fast to try against a staging database or add to a team project without package.json changes.

GitHub stars
5
last updated
Jun 7, 2026
View on GitHubSave

Sponsors

SnugThe clipboard manager you and your agent can use, safelyAgent CaffeineClose your lid, come back to finished workWaxBlock anything with supervision, without erasing your iPhoneOpen StepsSponsoredFree and open-source skills that make AI coding agents easier to understand, verify, and control.

Configuration

MCP_KEY_HOST

Name of the .env variable that holds the database host

MCP_KEY_PORT

Name of the .env variable that holds the database port

MCP_KEY_NAME

Name of the .env variable that holds the database name

MCP_KEY_USER

Name of the .env variable that holds the database user

MCP_KEY_PASS

Name of the .env variable that holds the database password

MCP_KEY_SSLMODE

Name of the .env variable that holds the SSL mode (e.g. require)

Readme

English | ๐ŸŒ Portuguรชs

Postgres MCP Icon

Postgres MCP

๐Ÿ”Œ Native MCP server for PostgreSQL - reads credentials from .env at runtime with flexible key mapping, configurable tool selection, and read-only mode by default.

npm version license CI

โœจ What it does

Most LLMs interact with databases by guessing - assuming table names, inventing column names, and writing queries that may fail or expose sensitive data. Postgres MCP solves this by giving the LLM a structured, safe interface to actually understand the database before touching it.

Built with @modelcontextprotocol/sdk and pg, it provides:

  • ๐Ÿง  Semantic knowledge graph - the LLM gets a complete map of schemas, tables, columns, foreign keys, inferred relations, risk levels, and business domains - built from the real schema, not invented
  • ๐Ÿ›ก๏ธ Read-only by default - no writes, no DDL, no arbitrary SQL unless you explicitly opt in; pg_classify_query_risk lets the LLM check a query's safety before running it
  • ๐Ÿ” Runtime credential resolution - credentials are read from .env at startup; nothing sensitive lives in mcp.json
  • ๐ŸŽฏ Explicit tool selection - every tool is opt-in via tool=<name> args, so the LLM only sees what you choose to expose

๐Ÿ“‹ Requirements

  • โš™๏ธ Node.js >= 18
  • ๐Ÿ“„ A .env file with database credentials (anywhere in the project tree - see .env Discovery)

๐Ÿš€ Installation

There are two ways to use this package. Choose the one that best fits your workflow.

Option 1 - No installation (via npx, recommended for quick start)

No installation needed. npx downloads and runs the package on demand. Add -y as the first argument to skip the confirmation prompt.

{
  "servers": {
    "Postgres Tools": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@edelciomolina/postgres-mcp"
      ],
      "env": {
        "MCP_KEY_HOST":    "DB_HOST",
        "MCP_KEY_PORT":    "DB_PORT",
        "MCP_KEY_NAME":    "DB_NAME",
        "MCP_KEY_SSLMODE": "DB_SSLMODE",
        "MCP_KEY_USER":    "DB_USER",
        "MCP_KEY_PASS":    "DB_PASS"
      }
    }
  }
}

This starts the server with the default read-only tool set - no tool= arguments needed. To enable write-capable tools, see Write-capable tools.

๐Ÿ’ก Using Supabase, Neon, Railway or another platform that only provides a connection string? Use MCP_KEY_URL pointing to DATABASE_URL (or whatever variable name the platform uses). The server will prioritize the URL and ignore the individual variables. See Connection via URL.


Option 2 - Install via VS Code (MCP extension marketplace)

VS Code supports discovering and installing MCP servers directly in the editor, without using the terminal.

  1. Open the Command Palette (Cmd+Shift+P on Mac / Ctrl+Shift+P on Windows/Linux)
  2. Run MCP: Add Server
  3. Choose "Browse MCP Servers" (or "From registry", depending on your VS Code version)
  4. Search for postgres-mcp or edelciomolina
  5. Select Postgres MCP and follow the instructions - VS Code will add the entry to your mcp.json automatically

๐Ÿ’ก You can also open the MCP Servers panel via Copilot chat icon โ†’ Manage MCP Servers to browse, enable, or disable servers at any time.

After installing, edit the generated entry in .vscode/mcp.json to add your tool= arguments and env key mappings as shown in the Usage section below.


๐Ÿš€ Usage in VS Code (mcp.json)

Read-only (default - no tool= arguments needed):

{
  "servers": {
    "Postgres Tools": {
      "type": "stdio",
      "command": "npx",
      "args": ["@edelciomolina/postgres-mcp"],
      "env": {
        "MCP_KEY_HOST":    "DB_HOST",
        "MCP_KEY_PORT":    "DB_PORT",
        "MCP_KEY_NAME":    "DB_NAME",
        "MCP_KEY_SSLMODE": "DB_SSLMODE",
        "MCP_KEY_USER":    "DB_USER",
        "MCP_KEY_PASS":    "DB_PASS"
      }
    }
  }
}

With write tools (explicit opt-in required):

{
  "servers": {
    "Postgres Tools": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "@edelciomolina/postgres-mcp",
        "tool=pg_manage_schema",
        "tool=pg_manage_indexes"
      ],
      "env": {
        "POSTGRES_MCP_ALLOW_WRITE": "true",
        "MCP_KEY_HOST":    "DB_HOST",
        "MCP_KEY_PORT":    "DB_PORT",
        "MCP_KEY_NAME":    "DB_NAME",
        "MCP_KEY_SSLMODE": "DB_SSLMODE",
        "MCP_KEY_USER":    "DB_USER",
        "MCP_KEY_PASS":    "DB_PASS"
      }
    }
  }
}

โš ๏ธ Write-capable tools require POSTGRES_MCP_ALLOW_WRITE=true in env. Without it, the server exits at startup.

The corresponding .env file at the root of your project:

DB_HOST=db.your-project.supabase.co
DB_PORT=5432
DB_NAME=postgres
DB_SSLMODE=require
DB_USER=readonly_user
DB_PASS=your_password

โš™๏ธ How mcp.json configuration works

๐Ÿ—๏ธ env - credential key mapping

The env block does not contain the actual credentials. It maps each MCP_KEY_* to the variable name in your .env file.

Key in envPoints to .env variableExample value
MCP_KEY_URLDATABASE_URLpostgresql://user:pass@host:5432/db?sslmode=require
MCP_KEY_HOSTDB_HOSTdb.example.supabase.co
MCP_KEY_PORTDB_PORT5432
MCP_KEY_NAMEDB_NAMEpostgres
MCP_KEY_SSLMODEDB_SSLMODErequire
MCP_KEY_USERDB_USERreadonly_user
MCP_KEY_PASSDB_PASSsecret

Priority: when MCP_KEY_URL (or DATABASE_URL) is present, the server uses the URL directly and ignores the individual credential keys.

This indirection lets you use any variable name in your .env - useful when sharing a .env across multiple services with different naming conventions.

๐Ÿ”ง args - tool selection via tool= prefix

Each enabled MCP tool is declared as a separate argument in the format tool=<name>:

"args": [
  "-y",
  "@edelciomolina/postgres-mcp",
  "tool=pg_manage_schema",
  "tool=pg_manage_indexes"
]

This makes the tool list explicit and auditable directly in mcp.json - no hidden configuration files. ๐Ÿ”


๐Ÿ”— Connection via URL (DATABASE_URL)

In addition to individual credentials, you can provide a full connection string - the standard format on platforms like Supabase, Neon, and Railway.

.env:

DATABASE_URL=postgresql://user:password@host:5432/database?sslmode=require

mcp.json:

{
  "servers": {
    "Postgres Tools": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@edelciomolina/postgres-mcp"],
      "env": {
        "MCP_KEY_URL": "DATABASE_URL"
      }
    }
  }
}

The variable mapped by MCP_KEY_URL has priority over the other keys (MCP_KEY_HOST, MCP_KEY_PORT, etc.). If the URL is present, the other variables are ignored.

If the platform uses a different name (e.g. DB_URL), just adjust the mapping:

"MCP_KEY_URL": "DB_URL"

๐Ÿ›ก๏ธ Why read-only is the default

If you omit all tool= arguments, the server starts with a curated read-only set - all tools that can retrieve, analyze, or explain data, but nothing that can modify it.

โœ… Included in defaults (read-only):

pg_execute_query       pg_manage_query        pg_inspect_schema
pg_get_setup_instructions                     pg_analyze_database
pg_monitor_database                           pg_debug_database
pg_inspect_database_graph                     pg_describe_table_semantics
pg_find_related_tables                        pg_classify_query_risk

๐Ÿ’ก pg_execute_query rejects INSERT, UPDATE, DELETE, DDL, ANALYZE, VACUUM, EXPLAIN ANALYZE and other write/maintenance commands before the database is queried.

๐Ÿ’ก pg_inspect_schema provides read-only schema introspection (get_info, get_enums). For DDL operations, use pg_manage_schema with explicit opt-in.

โš ๏ธ Excluded from defaults - require tool= argument AND POSTGRES_MCP_ALLOW_WRITE=true:

ToolOperations
pg_manage_schemaCREATE TABLE, ALTER TABLE, CREATE TYPE
pg_manage_indexesCREATE INDEX, DROP INDEX, REINDEX
pg_manage_constraintsADD CONSTRAINT, DROP CONSTRAINT
pg_manage_functionsCREATE FUNCTION, DROP FUNCTION
pg_manage_triggersCREATE TRIGGER, DROP TRIGGER, enable/disable
pg_manage_rlsENABLE/DISABLE RLS, CREATE/ALTER/DROP POLICY
pg_manage_usersCREATE/DROP/ALTER USER, GRANT, REVOKE
pg_execute_mutationINSERT / UPDATE / DELETE / UPSERT
pg_execute_sqlArbitrary SQL with transaction support

๐Ÿ“ .env file discovery

The server resolves the .env file in this order:

  1. env-file=<path> argument - explicit path relative to cwd; takes priority over everything
  2. Upward search - starting from cwd, searches each parent directory until a .env is found or the filesystem root is reached

If no .env is found, the server exits with a clear error message.

Monorepos and subfolders

When VS Code starts the MCP process, cwd is typically the workspace root. If your .env is in a subfolder (e.g. functions/.env), use env-file= to point to it explicitly:

{
  "servers": {
    "Postgres Tools": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@edelciomolina/postgres-mcp",
        "env-file=functions/.env"
      ],
      "env": {
        "MCP_KEY_HOST":    "DB_HOST",
        "MCP_KEY_PORT":    "DB_PORT",
        "MCP_KEY_NAME":    "DB_NAME",
        "MCP_KEY_SSLMODE": "DB_SSLMODE",
        "MCP_KEY_USER":    "DB_USER",
        "MCP_KEY_PASS":    "DB_PASS"
      }
    }
  }
}

๐Ÿ’ก The upward search behavior handles the common case automatically. Use env-file= when you need explicit control (CI, monorepos, Docker bind-mounts).


๐Ÿงฐ Available tools

Read-only (enabled by default)

ToolDescription
pg_execute_querySELECT / COUNT / EXISTS with write and multi-statement guards
pg_manage_queryEXPLAIN plans, slow query analysis, pg_stat_statements
pg_inspect_schemaSchema info and ENUM types (read-only introspection)
pg_get_setup_instructionsSetup instructions per platform
pg_analyze_databasePerformance, configuration, and storage analysis
pg_monitor_databaseReal-time monitoring of connections, queries, locks, and replication
pg_debug_databaseDiagnose connections, locks, performance, and replication
pg_inspect_database_graphBuild a full knowledge graph of the database: schemas, tables, columns, FKs, indexes, inferred relations, and business domains
pg_describe_table_semanticsDescribe a table with semantic context: risk level, column roles, sensitive columns, and related tables
pg_find_related_tablesFind tables related to a given table via explicit FKs and inferred naming patterns, with path explanation
pg_classify_query_riskClassify query risk (safe / warning / review / blocked) without executing it

Write-capable (opt-in via tool= argument + POSTGRES_MCP_ALLOW_WRITE=true)

ToolDescription
pg_manage_schemaSchema info, create/alter tables, manage ENUMs
pg_manage_indexesList, create, drop, reindex, analyze index usage
pg_manage_constraintsList, create, and drop constraints and foreign keys
pg_manage_functionsList, create, and drop functions and procedures
pg_manage_triggersList, create, drop, enable/disable triggers
pg_manage_rlsRow-Level Security policies
pg_manage_usersUser permissions, create/drop/alter users, grant/revoke
pg_execute_mutationINSERT / UPDATE / DELETE / UPSERT with parameterized queries
pg_execute_sqlArbitrary SQL execution with optional transaction support

๐Ÿง  Semantic Layer

The four pg_*_graph / pg_*_semantics / pg_*_risk tools build an in-memory knowledge graph of your database at runtime. This gives the LLM a structured map - schemas, tables, columns, foreign keys, inferred relations, risk levels, and business domains - without executing any query against your data.

All inferred fields (column semantic roles, table probable types, inferred relations) are clearly tagged so the LLM knows to treat them as hints, not schema facts.

Optional configuration (mcp-config.json)

Place a mcp-config.json file beside your .env to tune the semantic layer and security limits. All fields are optional - omitting the file applies safe defaults.

{
  "security": {
    "defaultLimit": 100,
    "maxLimit": 1000,
    "blockedSchemas": ["pg_catalog", "information_schema"],
    "blockedTables": [],
    "requireLimit": true
  },
  "semanticLayer": {
    "enabled": true,
    "inferRelationsWithoutForeignKeys": true,
    "inferBusinessEntities": true,
    "sensitiveKeywords": ["password", "secret", "token", "api_key", "ssn", "hash"]
  }
}

๐Ÿ—๏ธ Architecture

For a detailed view of the communication flow between the MCP client, the proxy, and PostgreSQL - including the full sequence diagram - see ARCHITECT.md.


๐Ÿ“„ License

MIT ยฉ Edelcio Molina

Details

Repository
github.com/edelciomolina/postgres-mcp
Category
Databases
Package
@edelciomolina/postgres-mcp
Transport
STDIO
Registry
MCP registry, active

Related Databases MCP servers

View all
1planetscale avatarPlanetScaleplanetscale/mcp-serverConnect to PlanetScale databases, branches, schema, query insights, and execute SQL0stars
2marcelo-ochoa avatarPostgresmarcelo-ochoa/serversMCP server for interacting with PostgreSQL databases0stars
3afgong avatarAfgong Sqlite Mcp Serverafgong/sqlite-mcp-serverExplore your Messages SQLite database to browse tables and inspect schemas with ease. Run flexibleโ€ฆ0stars
4bluwork avatarMongo Scout Mcpbluwork/mongo-scout-mcpScout your MongoDB databases with AI - safety features, live monitoring, and data quality0stars
5bluwork avatarPostgres Scout Mcpbluwork/postgres-scout-mcpScout your PostgreSQL databases with AI - safety features, monitoring, and data quality0stars
6hove avatarRead Only Mysql Mcp Servercapital.hove/read-only-mysql-mcp-serverMCP server for read-only MySQL database queries in Claude Desktop0stars