EP

ericzakariasson/pg-mcp-server

Developer tools

Эта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал

179 stars 13 forks Качество 74 Тренд 25MIT

ericzakariasson/pg-mcp-server — это кандидат на MCP-сервер, импортированный из https://github.com/ericzakariasson/pg-mcp-server.

Обзор

ericzakariasson/pg-mcp-server — это кандидат на MCP-сервер, импортированный из https://github.com/ericzakariasson/pg-mcp-server.

Обзор (машинный перевод)

Сервер Model Context Protocol для баз данных PostgreSQL. Позволяет LLM запрашивать и анализировать базы данных PostgreSQL через управляемый интерфейс.

https://github.com/user-attachments/assets/6571c20c-91c9-4a6e-8332-13b587b79fbf

Установка

Добавьте в настройки вашего клиента MCP:

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

  • DATABASE_URL - Строка соединения PostgreSQL (обязательно)
  • DANGEROUSLY_ALLOW_WRITE_OPS - Включить запись (по умолчанию: false)
  • DEBUG - Включить логирование отладки (по умолчанию: false)
  • PG_SSL_ROOT_CERT - Необязательный путь к TLS CA-пакету (например, глобальный AWS RDS bundle)

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

Транспорты

  • Стандартный транспорт — stdio. Переключитесь на HTTP с флагом --transport.
  • Режим HTTP обслуживает конечную точку MCP Streamable HTTP в адресе /mcp на PORT (по умолчанию [3000).
  • Клиенты, поддерживающие Streamable HTTP, должны подключаться к http://localhost:3000/mcp.

Команды запуска:

Инструменты

  • query - Выполнение SQL-запросов

Ресурсы

  • postgres://tables - Перечислить все таблицы
  • postgres://table/{schema}/{table} - Получить схему таблицы и данные выборок

Примеры подсказок

Вот пример запроса, чтобы проверить, работает ли ваш MCP-сервер:

Анализ данных и тетради

Эта страница переведена автоматически. Технические детали смотрите в оригинале.

README

Показан фрагмент оригинального README. Открыть оригинал.

Postgres MCP Server

A Model Context Protocol server for PostgreSQL databases. Enables LLMs to query and analyze PostgreSQL databases through a controlled interface.

https://github.com/user-attachments/assets/6571c20c-91c9-4a6e-8332-13b587b79fbf

Installation

Add to your MCP client settings:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["--yes", "pg-mcp-server", "--transport", "stdio"],
      "env": {
        "DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres"
      }
    }
  }
}

Configuration

  • DATABASE_URL - PostgreSQL connection string (required)
  • DANGEROUSLY_ALLOW_WRITE_OPS - Enable writes (default: false)
  • DEBUG - Enable debug logging (default: false)
  • PG_SSL_ROOT_CERT - Optional path to a TLS CA bundle (e.g., AWS RDS global bundle)

Usage

Transports

  • Default transport is stdio. Switch to HTTP with the --transport flag.
  • HTTP mode serves the MCP Streamable HTTP endpoint at /mcp on PORT (default 3000).
  • Clients that support Streamable HTTP should connect to http://localhost:3000/mcp.

Start commands:

# stdio transport (default, via installed CLI)
pg-mcp-server --transport=stdio

# http transport
pg-mcp-server --transport=http

Tools

  • query - Execute SQL queries
    { "sql": "SELECT * FROM users WHERE active = true LIMIT 10" }
    

Resources

  • postgres://tables - List all tables
  • postgres://table/{schema}/{table} - Get table schema and sample data

Example Prompts

Here’s an example prompt to test if your MCP server is working:

Show me the first 5 users from the database

Data Analysis & Notebooks

For data analysis and exploration, I’ve added a Cursor rule for using the MCP server together with notebooks in .cursor/rules/notebooks.mdc:

Quick Start with Docker

# Start PostgreSQL with sample data
bun run db:start

# Test with MCP Inspector
bun run inspector

# Stop PostgreSQL
bun run db:stop

Sample tables included: users, products, orders, order_items

Development

# Clone and install
git clone https://github.com/ericzakariasson/pg-mcp-server.git
cd pg-mcp-server
bun install

# Run (stdio transport)
bun run index.ts -- --transport=stdio
DEBUG=true bun run index.ts -- --transport=stdio

# Run (http transport)
bun run index.ts -- --transport=http
DEBUG=true bun run index.ts -- --transport=http
bun test                      # Run tests

Use local build in MCP client settings:

bun run build:js
{
  "mcpServers": {
    "postgres": {
      "command": "node",
Открыть полный README на GitHub

Установка

npx --yes pg-mcp-server --transport stdio
Новичок в MCP? Начните с руководства на mcpskill.org →

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

{ "mcpServers": { "postgres": { "command": "npx", "args": ["--yes", "pg-mcp-server", "--transport", "stdio"], "env": { "DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/postgres" } } } }