postgres-mcp
Allows interaction with PostgreSQL databases, providing tools for executing SQL queries, listing tables, and describing table schemas.
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., "@postgres-mcplist all tables in the public schema"
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.
MCP PostgreSQL Server
Un servidor MCP (Model Context Protocol) para PostgreSQL que permite a Cursor y otras herramientas interactuar con bases de datos PostgreSQL a través de HTTP.
Características
✅ Protocolo MCP completo implementado
✅ Conexión a PostgreSQL
✅ Servidor HTTP con Express
✅ Endpoints REST para pruebas directas
✅ Herramientas MCP para consultas SQL
✅ Soporte para esquemas y metadatos
✅ Manejo de errores robusto
Related MCP server: MCP Server for PostgreSQL
Instalación
Clona o descarga este proyecto.
Instala las dependencias:
npm installCopia el archivo de configuración:
cp .env.example .envConfigura las variables de entorno en
.env:
PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_NAME=tu_base_de_datos
DB_USER=tu_usuario
DB_PASSWORD=tu_contraseña
DB_SSL=falseUso
Iniciar el servidor
# Modo desarrollo (con auto-reload)
npm run dev
# Modo producción
npm startEl servidor estará disponible en http://localhost:3000
Endpoints disponibles
Health Check
GET /healthMCP Protocol
POST /mcpEndpoint principal para comunicación MCP.
Consulta directa
POST /query
Content-Type: application/json
{
"query": "SELECT * FROM users LIMIT 10",
"params": []
}Listar tablas
GET /tablesDescribir tabla
GET /tables/:tableNameConfiguración en Cursor
Para usar este servidor MCP en Cursor, agrega la siguiente configuración:
Configuración MCP en Cursor
Crea o edita el archivo de configuración de Cursor (ubicación depende del OS):
macOS: ~/Library/Application Support/Cursor/User/globalStorage/cursor.mcp/config.json
Windows: %APPDATA%\Cursor\User\globalStorage\cursor.mcp\config.json
Linux: ~/.config/Cursor/User/globalStorage/cursor.mcp/config.json
{
"mcpServers": {
"postgres": {
"url": "http://localhost:3000/mcp"
}
}
}También se incluye un archivo cursor-mcp-config.json en el proyecto como ejemplo de configuración.
Herramientas MCP disponibles
postgres_query
Ejecuta consultas SQL en la base de datos.
{
"name": "postgres_query",
"arguments": {
"query": "SELECT * FROM users WHERE id = $1",
"params": ["123"]
}
}postgres_tables
Lista todas las tablas en la base de datos.
{
"name": "postgres_tables",
"arguments": {}
}postgres_schema
Obtiene información del esquema de la base de datos.
{
"name": "postgres_schema",
"arguments": {
"table_name": "users"
}
}postgres_describe_table
Describe la estructura de una tabla específica.
{
"name": "postgres_describe_table",
"arguments": {
"table_name": "users"
}
}Ejemplos de uso
Consulta simple
curl -X POST http://localhost:3000/query \
-H "Content-Type: application/json" \
-d '{"query": "SELECT version()"}'Consulta con parámetros
curl -X POST http://localhost:3000/query \
-H "Content-Type: application/json" \
-d '{"query": "SELECT * FROM users WHERE age > $1", "params": ["25"]}'Solicitud MCP
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "postgres_tables",
"arguments": {}
}
}'Desarrollo
Estructura del proyecto
src/
├── server.js # Servidor HTTP principal
├── mcp-protocol.js # Implementación del protocolo MCP
└── database.js # Conexión y utilidades de PostgreSQL
test/
└── test.js # Tests básicos
.env.example # Ejemplo de variables de entorno
package.json # Dependencias y scripts
README.md # Este archivoAgregar nuevas herramientas
Edita
src/mcp-protocol.jsRegistra la nueva herramienta en
initialize()Implementa el manejador en
handleToolCall()
Requisitos
Node.js 18+
PostgreSQL 12+
npm o yarn
Solución de problemas
Error de conexión a la base de datos
Verifica que PostgreSQL esté ejecutándose
Comprueba las credenciales en
.envAsegúrate de que la base de datos existe
Puerto en uso
Cambia el puerto en
.envconPORT=otro_puerto
Permisos insuficientes
Verifica que el usuario de la base de datos tenga permisos de lectura/escritura
Contribuir
Fork del proyecto
Crea una rama para tu feature
Commit tus cambios
Push a la rama
Abre un Pull Request
Licencia
MIT
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 Servers
- AlicenseBqualityDmaintenanceA server implementing the Model Context Protocol (MCP) for Cursor that allows using a PostgreSQL database as storage for model contexts, enabling secure database exploration and querying.Last updated1037ISC
- Flicense-qualityDmaintenanceA Model Context Protocol server implementation that provides a simple interface to interact with PostgreSQL databases, enabling SQL queries, database operations, and schema management through MCP.Last updated
- AlicenseCqualityDmaintenanceEnables querying PostgreSQL database metadata including table lists and schema information through the MCP protocol. Supports stdio transport for Cursor/IDE integration as well as HTTP transport with health check endpoints.Last updated2MIT
- Alicense-qualityCmaintenanceAn open-source MCP server for PostgreSQL schema introspection and guarded read-only queries. It enables MCP clients to discover schemas, tables, columns, indexes, relationships, and safe queryable data from a configured PostgreSQL database.Last updated30MIT
Related MCP Connectors
MCP server for managing Prisma Postgres.
MCP server for interacting with the Supabase platform
GibsonAI MCP server: manage your databases with natural language
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/jmluque72/postgres-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server