PostgreSQL MCP Server

by assadnasser

155 downloads
Not rated
GitHub

Description

# PostgreSQL MCP Server A Model Context Protocol (MCP) server that allows users to connect to PostgreSQL databases. This server exposes resources, tools, and prompts for interacting with PostgreSQL databases through the MCP protocol. ## Overview This MCP server allows external…

About

# PostgreSQL MCP Server A Model Context Protocol (MCP) server that allows users to connect to PostgreSQL databases. This server exposes resources, tools, and prompts for interacting with PostgreSQL databases through the MCP protocol. ## Overview This MCP server allows external applications to share database…

Details

Author
assadnasser
Downloads
155
Categories
Database

- Secure PostgreSQL connections with connection pooling and SSL
- SQL query execution with parameter binding and history tracking
- Schema exploration: list tables, describe columns, keys, indexes
- Database analytics: size, activity, and query performance stats
- API rate limiting and CORS support for security
- Graceful shutdown handling and Redis-backed storage option

Clone the repository, install dependencies (npm install), copy the .env.example to .env, configure environment variables (e.g., PGHOST, PGUSER, PGPASSWORD), and start the development server with npm run dev. Connect via the SSE endpoint at /sse and use the provided tools and prompts to interact with your PostgreSQL database.

PostgreSQL MCP Server

A Model Context Protocol (MCP) server that allows users to connect to PostgreSQL databases. This server exposes resources, tools, and prompts for interacting with PostgreSQL databases through the MCP protocol.

Overview

This MCP server allows external applications to share database credentials with the server via POST requests to an SSE (Server-Sent Events) endpoint. The server then establishes a connection to the specified PostgreSQL database and provides various ways to interact with it.

Architecture

The server follows a modular architecture with clear separation of concerns:

- Server Core - Handles MCP protocol implementation and coordination
- Resources - Provide data and metadata about database entities
- Tools - Implement database operations and actions
- Prompts - Define natural language interface templates

The code is organized into these main directories:

src/
├── resources/   # Database schema, table structure, query history resources
├── tools/       # Database operations (queries, connections, table management)
├── prompts/     # Natural language templates for database operations
├── server.ts    # Main MCP server implementation and configuration
├── database.ts  # Database connection and query handling
└── query-history.ts # Query history tracking and storage

Features

- Database Connections
- Secure PostgreSQL connections with connection pooling
- SSL support for encrypted connections
- Connection validation

- Query Execution
- SQL query execution with parameter binding
- Query history tracking
- Statistics collection

- Schema Management
- Table listing and description
- Column metadata with types, constraints, and descriptions
- Primary key, foreign key, and index information

- Database Analytics
- Database size information
- Current database activity monitoring
- Query performance tracking

- Security
- API rate limiting
- CORS support and secure headers

- Server Features
- Graceful shutdown handling
- Cross-origin resource sharing (CORS) support

Installation

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.