dog-64
MCP Serverdog-64public

mcp pg

用于将 Cursor 连接到 PostgreSQL 的简单 MCP 服务器,纯 Bash + psql 实现,无需依赖。

Repository Info

0
Stars
0
Forks
0
Watchers
0
Issues
Shell
Language
-
License

About This Server

用于将 Cursor 连接到 PostgreSQL 的简单 MCP 服务器,纯 Bash + psql 实现,无需依赖。

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

MCP PostgreSQL для Cursor

Simple MCP server for connecting Cursor to PostgreSQL. Pure bash + psql implementation, no dependencies.

Quick Start

  1. Setup:
cp env.example .env
# Edit .env with your PostgreSQL credentials
  1. Add to Cursor:
{
  "mcpServers": {
    "postgres": {
      "command": "/Users/dog/Sites/mcp-pg/run_mcp.sh"
    }
  }
}

Path must be absolute.

Usage

Database switching functionality!

You can work with any database by simply specifying its name in your request.

Example commands in Cursor:

  • "what's the biggest table in DB o3?"
  • "what databases are available on current connection?"
  • "show table owners in db1"
  • "execute in insales database: SELECT count(*) FROM users"
  • "switch to metabase DB and show tables"

Cursor automatically understands which database to work with from your request!

Configuration

Each connection is configured separately with its own access rights:

# Local connection (development)
DB_LOCAL_HOST=localhost
DB_LOCAL_PORT=5432
DB_LOCAL_NAME=postgres
DB_LOCAL_USER=postgres
DB_LOCAL_READONLY=false  # full access for development

# Docker connection (testing)
DB_DOCKER_HOST=0.0.0.0
DB_DOCKER_PORT=15432
DB_DOCKER_NAME=insales_dev
DB_DOCKER_USER=postgres
DB_DOCKER_PASSWORD=password
DB_DOCKER_READONLY=true  # read-only for safety

# Production connection (live server)
DB_PROD_HOST=your-prod-server.com
DB_PROD_PORT=5432
DB_PROD_NAME=production_db
DB_PROD_USER=postgres
DB_PROD_PASSWORD=your-password
DB_PROD_READONLY=true  # read-only for safety

Features

  • SQL query execution (with configurable security)
  • READONLY mode for safe production access
  • Connection checking to different servers
  • Database switching without restart
  • Multiple connections (local, docker, prod)

Troubleshooting

If Cursor shows "client closed" status:

  1. Test manually:
echo '{"method":"tools/list","id":1}' | ./mcp_postgres
  1. Check psql is installed:
which psql
  1. Check paths in Cursor settings - must be absolute

  2. Check logs - View / Output - MCP output

  3. Restart Cursor after configuration changes

  4. After changing .env file always restart Cursor - otherwise LLM will see outdated security modes in MCP tool descriptions

No dependencies, just bash + psql!


Русское описание

Простой MCP сервер для подключения Cursor к PostgreSQL. Работает на чистом bash + psql.

Быстрый старт

  1. Настройка:
cp env.example .env
# Отредактируйте .env с вашими данными PostgreSQL
  1. Добавьте в Cursor:
{
  "mcpServers": {
    "postgres": {
      "command": "/Users/dog/Sites/mcp-pg/run_mcp.sh"
    }
  }
}

путь должен быть абсолютными

Использование

Теперь можете работать с любой базой данных, просто указав её название в запросе.

Примеры команд в Cursor:

  • "какая самая большая таблица в БД o3?"
  • "какие БД есть на текущем соединении?"
  • "покажи владельцев таблиц в db1"
  • "выполни в базе insales: SELECT count(*) FROM users"
  • "переключись на БД metabase и покажи таблицы"

Cursor автоматически поймёт из вашего запроса, с какой базой работать!

Конфигурация

Каждое подключение настраивается отдельно с собственными правами доступа:

# Локальное подключение (разработка)
DB_LOCAL_HOST=localhost
DB_LOCAL_PORT=5432
DB_LOCAL_NAME=postgres
DB_LOCAL_USER=postgres
DB_LOCAL_PASSWORD=password
DB_LOCAL_READONLY=false  # полный доступ для разработки

# Docker подключение (тестирование)
DB_DOCKER_HOST=0.0.0.0
DB_DOCKER_PORT=15432
DB_DOCKER_NAME=insales_dev
DB_DOCKER_USER=postgres
DB_DOCKER_PASSWORD=password
DB_DOCKER_READONLY=true  # только чтение для безопасности

# Продакшен подключение (боевой сервер)
DB_PROD_HOST=your-prod-server.com
DB_PROD_PORT=5432
DB_PROD_NAME=production_db
DB_PROD_USER=postgres
DB_PROD_PASSWORD=your-password
DB_PROD_READONLY=true  # только чтение для безопасности

Возможности

  • Выполнение SQL запросов (с настраиваемой безопасностью)
  • READONLY режим для безопасного доступа к продакшену
  • Проверка подключений к разным серверам
  • Переключение между базами данных без перезапуска
  • Множественные подключения (local, docker, prod)

Устранение проблем

Если в Cursor статус "client closed":

  1. Проверьте работу вручную:
echo '{"method":"tools/list","id":1}' | ./mcp_postgres
  1. Проверьте, что psql установлен:
which psql
  1. Проверьте пути в настройках Cursor - они должны быть абсолютными

  2. Смотрите лог - View / Output - MCP output

  3. Перезапустите Cursor после изменения конфигурации

  4. После изменения .env файла обязательно перезапустите Cursor - иначе LLM будет видеть устаревшие режимы безопасности в описаниях MCP инструментов

Никаких зависимостей, только bash + psql!

Quick Start

1

Clone the repository

git clone https://github.com/dog-64/mcp-pg
2

Install dependencies

cd mcp-pg
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownerdog-64
Repomcp-pg
LanguageShell
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation