#!/usr/bin/env bash
# ==============================================================================
# MCPConfigForge Deterministic Installer : PostgreSQL Official MCP Server (@modelcontextprotocol/server-postgres)
# Generated by https://neatjar.com/mcp-forge/mcp-config/postgres
# ==============================================================================
set -euo pipefail

echo "[1/3] Writing Cursor MCP configuration (.cursor/mcp.json)..."
mkdir -p .cursor
cat << 'EOF_CURSOR' > .cursor/mcp.json
{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://readonly_user:password@localhost:5432/production_db"
      ],
      "env": {
        "PGSSLMODE": "require"
      }
    }
  }
}
EOF_CURSOR

echo "[2/3] Writing VS Code Copilot MCP configuration (.vscode/mcp.json)..."
mkdir -p .vscode
cat << 'EOF_VSCODE' > .vscode/mcp.json
{
  "servers": {
    "postgres": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://readonly_user:password@localhost:5432/production_db"
      ],
      "env": {
        "PGSSLMODE": "require"
      }
    }
  }
}
EOF_VSCODE

echo "[3/3] Claude Code CLI registration command ready:"
echo "  claude mcp add postgres -e PGSSLMODE="require" -- npx -y @modelcontextprotocol/server-postgres postgresql://readonly_user:password@localhost:5432/production_db"
echo "Done! Verify your server at https://neatjar.com/mcp-forge/mcp-config/postgres"
