postgres-mcp-server
Local MCP server for safe querying and inspecting PostgreSQL databases, with write and maintenance operations disabled by default.
README
postgres-mcp-server
Servidor MCP local para PostgreSQL. Está pensado para OpenCode y clientes MCP por stdio.
Objetivo: consultar e inspeccionar bases PostgreSQL con seguridad. La escritura y el mantenimiento vienen apagados por defecto.
Seguridad rápida
POSTGRES_ENABLE_WRITE=falsepor defecto.POSTGRES_ENABLE_MAINTENANCE=falsepor defecto.- Las consultas de lectura corren en
BEGIN TRANSACTION READ ONLY. - La introspección usa parámetros (
$1,$2), no concatena nombres enviados por el usuario. - Los logs van a
stderr.stdoutqueda reservado para MCP. - Los errores no imprimen contraseñas ni URLs completas con credenciales.
Instalación
npm install
npm run build
Configuración
Variables principales:
| Variable | Default | Uso |
|---|---|---|
POSTGRES_URL o DATABASE_URL |
requerido | URL de conexión PostgreSQL. |
POSTGRES_ENABLE_WRITE |
false |
Habilita INSERT, UPDATE, DELETE, MERGE, COPY. |
POSTGRES_ENABLE_MAINTENANCE |
false |
Habilita DROP, TRUNCATE, ALTER, CREATE, VACUUM, ANALYZE, REINDEX, GRANT, REVOKE. |
PG_STATEMENT_TIMEOUT_MS |
30000 |
Tiempo máximo de sentencia. |
PG_MAX_CONNECTIONS |
10 |
Máximo de conexiones del pool. |
TRANSACTION_TIMEOUT_MS |
60000 |
Tiempo máximo de transacciones pendientes. |
MAX_CONCURRENT_TRANSACTIONS |
5 |
Máximo de transacciones de escritura abiertas. |
También podés pasar la URL como primer argumento del binario.
OpenCode
Ejemplo seguro, sin secretos reales:
"DB_ejemplo": {
"type": "local",
"command": [
"node",
"D:/work/postgres-mcp-server/dist/index.js"
],
"environment": {
"POSTGRES_URL": "postgresql://USER:PASSWORD@HOST:5432/DB_NAME",
"POSTGRES_ENABLE_WRITE": "false",
"POSTGRES_ENABLE_MAINTENANCE": "false",
"PG_STATEMENT_TIMEOUT_MS": "30000"
},
"enabled": true,
"timeout": 60000
}
Si usás paquete instalado:
"command": ["npx", "-y", "postgres-mcp-server"]
Tools MCP
execute_query
Ejecuta SQL de lectura: SELECT, WITH, EXPLAIN, SHOW.
Entrada:
{ "sql": "SELECT now()" }
execute_dml_ddl_dcl_tcl
Ejecuta escritura solo si POSTGRES_ENABLE_WRITE=true. Deja la transacción abierta y devuelve transaction_id.
Entrada:
{ "sql": "UPDATE users SET active = true WHERE id = 1" }
Después llamá a execute_commit o execute_rollback.
execute_commit
Confirma una transacción pendiente.
{ "transaction_id": "tx_..." }
execute_rollback
Revierte una transacción pendiente.
{ "transaction_id": "tx_..." }
execute_maintenance
Ejecuta mantenimiento solo si POSTGRES_ENABLE_MAINTENANCE=true.
list_schemas
Lista esquemas no internos visibles para el usuario conectado.
list_tables
Lista tablas. Acepta filtro opcional:
{ "schema_name": "public" }
describe_table
Describe columnas, índices y constraints.
{ "schema_name": "public", "table_name": "users" }
Desarrollo
npm ci
npm run build
npm test -- --run --coverage
npm run lint
Los tests usan fakes/mocks. No necesitan una base PostgreSQL real.
CI
GitHub Actions ejecuta Node 20 y 22 con cache npm, build, lint y coverage. El mínimo es 85% en líneas, funciones, ramas y statements.
Más documentación
docs/configuracion.mddocs/seguridad-sql.mddocs/desarrollo.md
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.