postgres-explorer
# 🐘 Postgres-Explorer MCP Server
Servidor MCP que permite a **Claude Code** explorar y consultar una base de datos PostgreSQL de forma segura (solo lectura).
## ✅ Requisitos
- 🐍 Python >= 3.12
- 🗄️ PostgreSQL accesible
- 🐳 Docker (opcional)
## 🔐 Variables de entorno
```env
DB_HOST=localhost
DB_NAME=name_example
DB_USER=user_example
DB_PASSWORD=password_example
DB_PORT=5432
```
## ⚙️ Configuración para Claude Code
Agrega esto a tu `.mcp.json` en la raíz del proyecto:
### 🐳 Opción 1 — Docker (recomendado)
Primero construye la imagen desde la raíz del proyecto:
```bash
docker build -t mi-mcp-postgres .
```
Luego agrega esto a tu `.mcp.json`:
```json
{
"mcpServers": {
"postgres-explorer": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--network",
"host",
"--env-file",
"/ruta/absoluta/hacia/tu/proyecto/.env",
"mi-mcp-postgres"
]
}
}
}
```
o a tu `opencode.json`:
```json
{
"mcp": {
"postgres-explorer": {
"type": "local",
"command": [
"docker",
"run",
"-i",
"--rm",
"--network",
"host",
"--env-file",
"/ruta/absoluta/hacia/tu/proyecto/.env",
"mi-mcp-postgres"
]
}
}
}
```
### ⚡ Opción 2 — Python directo
```json
{
"mcpServers": {
"postgres-explorer": {
"command": "uv",
"args": ["run", "python", "main.py"]
}
}
}
```
## 🛠️ Herramientas disponibles
| Herramienta | Descripción |
|------------------|------------------------------------------------------------------|
| `get_schema` | 📋 Lista todas las tablas y sus columnas del esquema `public` |
| `execute_query` | 🔍 Ejecuta una consulta `SELECT` y devuelve resultados |
> 🔒 **Seguridad:** solo permite `SELECT`. Conexiones en modo **read-only**.
TDQS
Scored across 2 tools
The two tools have clearly distinct purposes: execute_query handles arbitrary SELECT queries, while get_schema retrieves metadata about tables and columns. No overlap or ambiguity exists.
Both tools follow a consistent verb_noun pattern (execute_query, get_schema) using snake_case, making the naming predictable and clear.
With only 2 tools, the server feels minimal for a 'PostgreSQL explorer'. Typical exploration would benefit from additional tools like describe_table, list_schemas, or view_details, making 2 tools insufficient for a well-scoped exploration surface.
The server covers basic schema browsing and arbitrary read queries, but lacks more granular tools (e.g., specific table details, constraint info, index listing). Users cannot easily explore beyond the public schema or get metadata about individual objects without writing SQL.