About
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
- Clone the repository:
git clone <repository-url>
cd mcp-server-postgres-poc
- Install dependencies:
npm install
- 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 ..
- Configure your database connection by creating a
.envfile:
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
- Build the project:
npm run build
- 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 executeparams(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
Weather Data Queries
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 JavaScriptnpm run dev- Run in development mode with tsxnpm run watch- Run in watch mode for developmentnpm 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
Installing Postgres Poc
This server has no published package — it is built from source. Open the repository and follow its README.
▸ github.com/AMVijay/mcp-server-postgres-pocFAQ
Is Postgres Poc MCP free?
Yes, Postgres Poc MCP is free — one-click install via Unyly at no cost.
Does Postgres Poc need an API key?
Yes, it requires environment variables: DB_HOST, DB_NAME, DB_PASSWORD, DB_PORT, DB_SSL, DB_USER. Unyly injects them into the config during install.
Is Postgres Poc hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install Postgres Poc in Claude Desktop, Claude Code or Cursor?
Open Postgres Poc on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
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
by wenb1n-devPostgres Server
This server enables interaction with PostgreSQL databases through the Model Context Protocol, optimized for the AWS Bedrock AgentCore Runtime. It provides tools
by madhurprashPostgres
Query your database in natural language
by AnthropicPostgreSQL
Read-only database access with schema inspection.
by modelcontextprotocolRedis
Interact with Redis key-value stores.
by modelcontextprotocolSQLite
Database interaction and business intelligence capabilities.
by modelcontextprotocolmxcp
Open-source framework for building enterprise-grade MCP servers using just YAML, SQL, and Python, with built-in auth, monitoring, ETL and policy enforcement.
by raw-labstadas-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
by tadas-githubjulien040/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
by julien040drakonkat/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.
by drakonkatCompare Postgres Poc with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All data MCPs
