Command Palette

Search for a command to run...

UnylyUnyly
Весь каталог

Postgres Poc

БесплатноНе проверен

MCP server for PostgreSQL - POC

GitHubEmbed

Описание

MCP server for PostgreSQL - POC

README

A Model Context Protocol (MCP) server implementation for querying PostgreSQL databases. This proof of concept demonstrates how to create an MCP server that can interact with PostgreSQL databases, providing a bridge between AI models and structured database content.

Overview

This project showcases the integration of the Model Context Protocol with PostgreSQL databases, enabling AI models to query and interact with database content in a structured and secure manner. The server provides tools for executing SQL queries, listing database schemas, and managing database connections.

Features

  • SQL Query Execution: Execute SELECT queries (read-only operations for security)
  • Schema Introspection: List tables, columns, and database structure

Quick Start

Prerequisites

  • Node.js 22
  • PostgreSQL database
  • TypeScript knowledge

Installation

  1. Clone the repository:
git clone <repository-url>
cd mcp-server-postgres-poc
  1. Install dependencies:
npm install
  1. Set up test data (for testing purposes):
# Start PostgreSQL service
./init_postgres.sh

# Set up sample weather data
cd weather-data-setup
npx tsx setup-weather-data.ts
cd ..
  1. Configure your database connection by creating a .env file:
POSTGRES_USER=your_username
POSTGRES_HOST=localhost
POSTGRES_DATABASE=your_database
POSTGRES_PASSWORD=your_password
POSTGRES_PORT=5432
POSTGRES_MAX_CONNECTIONS=10
POSTGRES_IDLE_TIMEOUT=30000
POSTGRES_CONNECTION_TIMEOUT=10000
  1. Build the project:
npm run build
  1. Start the MCP server:
npm start

Available Tools

The MCP server provides the following tools:

query

Execute SQL queries against the PostgreSQL database.

Parameters:

  • sql (string): The SQL query to execute
  • params (array, optional): Parameters for parameterized queries

list_tables

List all tables in the database.

Parameters:

  • schema (string, optional): Database schema name (default: "public")

describe_table

Get detailed information about a specific table's structure.

Parameters:

  • schema (string, optional): Database schema name (default: "public")
  • table (string): Table name to describe

Sample Data

This POC includes a weather data setup to demonstrate the server's capabilities:

Weather Data

The weather-data-setup/ directory contains:

  • weather.csv: Historical weather data from US weather stations (16,744+ records)
  • setup-weather-data.ts: Script to create and populate the weather database

Test Screenshots

Screenshots of the MCP server in action with weather data:

List Tables Tool List Tables Screenshot
Weather Data Queries Weather Data Queries Screenshot

To set up the sample data:

cd weather-data-setup
npx ts-node setup-weather-data.ts

This creates a weather_data table with fields including temperature, precipitation, wind data, and station information.

Development

Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm run dev - Run in development mode with tsx
  • npm run watch - Run in watch mode for development
  • npm run clean - Clean build artifacts

Project Structure

src/
├── generic-postgres-mcp.ts    # Main MCP server implementation
weather-data-setup/
├── README.md                  # Weather data documentation
├── setup-weather-data.ts      # Database setup script
└── weather.csv               # Sample weather data

Configuration

The server supports the following environment variables:

Variable Default Description
POSTGRES_USER postgres Database username
POSTGRES_HOST localhost Database host
POSTGRES_DATABASE postgres Database name
POSTGRES_PASSWORD (empty) Database password
POSTGRES_PORT 5432 Database port
POSTGRES_MAX_CONNECTIONS 10 Maximum connection pool size
POSTGRES_IDLE_TIMEOUT 30000 Idle connection timeout (ms)
POSTGRES_CONNECTION_TIMEOUT 10000 Connection timeout (ms)

Security Considerations

  • Always use parameterized queries to prevent SQL injection
  • Limit database user permissions to only necessary operations
  • Use connection pooling to manage database resources efficiently
  • Validate and sanitize all input parameters
  • Consider implementing query timeouts for long-running operations

Integration with MCP Clients

This server can be integrated with any MCP-compatible client, such as Claude Desktop or other AI applications that support the Model Context Protocol.

Example MCP client configuration:

{
  "mcpServers": {
    "postgres-server": {
      "command": "node",
      "args": ["/path/to/dist/generic-postgres-mcp.js"],
      "env": {
        "POSTGRES_USER": "your_username",
        "POSTGRES_HOST": "localhost",
        "POSTGRES_DATABASE": "your_database",
        "POSTGRES_PASSWORD": "your_password"
      }
    }
  }
}

Contributing

This is a proof of concept project. Contributions, suggestions, and improvements are welcome! Please feel free to:

  • Report issues
  • Suggest new features
  • Submit pull requests
  • Improve documentation

License

MIT License - see the LICENSE file for details.

Next Steps

This POC demonstrates the basic functionality of an MCP server for PostgreSQL. Potential enhancements include:

  • Advanced query builders and ORM integration
  • Database migration support
  • Multi-database support
  • Enhanced security features
  • Performance monitoring and metrics
  • Streaming query results for large datasets
  • Transaction management

from github.com/AMVijay/mcp-server-postgres-poc

Установка Postgres Poc

У этого сервера нет опубликованного пакета — он собирается из исходников. Открой репозиторий и следуй инструкции в README.

▸ github.com/AMVijay/mcp-server-postgres-poc

FAQ

Postgres Poc MCP бесплатный?

Да, Postgres Poc MCP бесплатный — установка в пару кликов через Unyly без оплаты.

Нужен ли API-ключ для Postgres Poc?

Да, требуются переменные окружения: DB_HOST, DB_NAME, DB_PASSWORD, DB_PORT, DB_SSL, DB_USER. Unyly подставит их в конфиг при установке.

Postgres Poc — hosted или self-hosted?

Self-hosted: сервер запускается локально на твоей машине командой из раздела установки.

Как установить Postgres Poc в Claude Desktop, Claude Code или Cursor?

Открой Postgres Poc на unyly.org, выбери вкладку своего клиента (Claude Desktop, Claude Code, Cursor) и нажми Install — конфиг сгенерируется автоматически, без правки JSON.

Похожие MCP

wenb1n-dev/SmartDB_MCP

A universal database MCP server supporting simultaneous connections to multiple databases. It provides tools for database operations, health analysis, SQL optim

wenb1n-devавтор: wenb1n-dev

Postgres Server

This server enables interaction with PostgreSQL databases through the Model Context Protocol, optimized for the AWS Bedrock AgentCore Runtime. It provides tools

madhurprashавтор: madhurprash

Postgres

Query your database in natural language

Anthropicавтор: Anthropic

PostgreSQL

Read-only database access with schema inspection.

modelcontextprotocolавтор: modelcontextprotocol

Redis

Interact with Redis key-value stores.

modelcontextprotocolавтор: modelcontextprotocol

SQLite

Database interaction and business intelligence capabilities.

modelcontextprotocolавтор: modelcontextprotocol

mxcp

Open-source framework for building enterprise-grade MCP servers using just YAML, SQL, and Python, with built-in auth, monitoring, ETL and policy enforcement.

raw-labsавтор: raw-labs

tadas-github/a2asearch-mcp

MCP server to search 4,800+ MCP servers, AI agents, CLI tools and agent skills. Install: npx -y a2asearch-mcp. Ask Claude: "Find MCP servers for database access

tadas-githubавтор: tadas-github

julien040/anyquery

Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by desi

julien040автор: julien040

drakonkat/wizzy-mcp-tmdb

A MCP server for The Movie Database API that enables AI assistants to search and retrieve movie, TV show, and person information.

drakonkatавтор: drakonkat

Compare Postgres Poc with

Не уверен что выбрать?

Найди свой стек за 60 секунд

Автор?

Embed-бейдж для README

Похожее

Все в категории data