AP

ahmedmustahid/postgres-mcp-server

Developer tools

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

31 stars 16 forks Качество 56 Тренд 0

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

Обзор

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

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

Сервер протокола Model Context Protocol (MCP), который обеспечивает передачу HTTP и Stdio для взаимодействия с базами данных PostgreSQL. Этот сервер предоставляет ресурсы и инструменты базы данных с помощью обоих методов транспортировки, что обеспечивает гибкую интеграцию в различных средах.

Особенности

Двойная транспортная поддержка: HTTP (StreamableHTTPServerTransport) и Stdio (StdioServerTransport) Ресурсы базы данных: таблицы списков и информация о схемах Query Tool: выполнение запросов SQL только для чтения Государственные сессии: HTTP транспорт поддерживает управление сессиями ** Поддержка докеров**: контейнерное развертывание для обоих видов транспорта Производство готово: изящное отключение, обработка ошибок и регистрация

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

Настройка среды

Учетные данные базы данных должны быть переданы как:

  1. Любые переменные среды

  2. или в рабочем каталоге (каталоге, где будет выполняться команда npx): Создайте файл .env (пакет использует dotenv)

###Беги с помощью npx

  1. Скачать node.js и npm отсюда 2.Проверь пакет. По умолчанию он будет работать с потоковым http на порту 3000:

  2. Для стиотранспорта:

Настройка среды

Шаблон Copy Environment

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

README

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

MCP PostgreSQL Server (Stateful and Dual Transport)

A Model Context Protocol (MCP) server that provides both HTTP and Stdio transports for interacting with PostgreSQL databases. This server exposes database resources and tools through both transport methods, allowing for flexible integration in different environments.

Features

  • Dual Transport Support: Both HTTP (StreamableHTTPServerTransport) and Stdio (StdioServerTransport)
  • Database Resources: List tables and retrieve schema information
  • Query Tool: Execute read-only SQL queries
  • Stateful Sessions: HTTP transport supports session management
  • Docker Support: Containerized deployments for both transports
  • Production Ready: Graceful shutdown, error handling, and logging

Quick Start

Environment Setup

The database credentials must be passed as:

  1. Either environment variables
# PostgreSQL Database Connection String
export POSTGRES_URL=your_connection_string

# PostgreSQL Database Configuration if POSTGRES_URL is not provided
export POSTGRES_USERNAME=your_username
export POSTGRES_PASSWORD=your_password
export POSTGRES_HOST=localhost
export POSTGRES_PORT=5432 # this is the default
export POSTGRES_DATABASE=your_database

# HTTP Server Configuration
# Following are the default values
export PORT=3000
export HOST=0.0.0.0

# CORS Configuration (comma-separated list of allowed origins)
# Following are the default values
export CORS_ORIGIN=http://localhost:8080,http://localhost:3000

# Environment
# Following are the default values
export NODE_ENV=development

  1. Or in the working directory (directory where npx command will be run): create a .env file (the package uses dotenv package)
# .env.example
# PostgreSQL Database Configuration
POSTGRES_USERNAME=your_username
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhost
POSTGRES_DATABASE=your_database

# HTTP Server Configuration
PORT=3000
HOST=0.0.0.0

# CORS Configuration (comma-separated list of allowed origins)
CORS_ORIGIN=http://localhost:8080,http://localhost:3000

# Environment
NODE_ENV=development

Run using npx

  1. Download node.js and npm from here
  2. Run the package. By default, it will run streamable http on port 3000:
npx @ahmedmustahid/postgres-mcp-server
# or npx @ahmedmustahid/postgres-mcp-server --port 3000 --verbose
  1. For stdio transport:
npx @ahmedmustahid/postgres-mcp-server stdio
# npx @ahmedmustahid/postgres-mcp-server stdio --verbose

Environment Setup

Copy environment template

cp .env.example .env

Edit your database credentials

nano .env

Podman(or Docker) Usage

  1. Install podman from here
  2. Install uv from here
  3. Install podman compose package: uv add podman-compose (or uv sync to sync packages in pyproject.toml)
Открыть полный README на GitHub

Установка

npx @ahmedmustahid/postgres-mcp-server stdio
Новичок в MCP? Начните с руководства на mcpskill.org →

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

{ "mcpServers": { "postgres-mcp-server": { "command": "npx", "args": [ "@ahmedmustahid/postgres-mcp-server", "stdio" ], "env": { "POSTGRES_USERNAME": "your-username", "POSTGRES_PASSWORD": "your-password", "POSTGRES_HOST": "hostname", "POSTGRES_DATABASE": "database-name" } } } }