PostgreSQL MCP Server
Provides secure, read-only access to PostgreSQL databases for schema inspection and data querying. It enables users to list tables, describe structures, and execute SELECT statements while strictly blocking destructive operations.
README
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides read-only access to PostgreSQL databases.
Features
- Read-only operations: Query data safely without risk of modifications
- Schema inspection: Explore database structure, tables, and columns
- Query execution: Run SELECT statements and view results
- Connection management: Secure connection handling with proper cleanup
Installation
-
Clone this repository
-
Install dependencies:
npm install -
Build the project:
npm run build -
Configure your database connection (see Configuration section below)
Configuration
Create a .env file in the root directory with your PostgreSQL connection details:
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=your_database
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password
POSTGRES_SSL=false
Usage
Running the Server
npm start
Available Tools
The MCP server provides the following tools:
- postgres_query - Execute SELECT queries
- postgres_describe_table - Get table structure and column information
- postgres_list_tables - List all tables in the database
- postgres_list_schemas - List all schemas in the database
Example MCP Client Configuration
Add this to your MCP client configuration (e.g., ~/.config/claude-desktop/mcp.json):
{
"servers": {
"postgresql": {
"command": "node",
"args": ["path/to/mcp/server/start-server.cjs"],
"type": "stdio"
}
}
}
This configuration automatically loads environment variables from your project's .env file, keeping sensitive credentials out of the MCP configuration.
Security
This server operates in read-only mode only. It:
- Only allows SELECT statements
- Blocks INSERT, UPDATE, DELETE, DROP, CREATE, ALTER operations
- Uses parameterized queries to prevent SQL injection
- Validates all queries before execution
Testing
Quick Test
# Run complete test suite (includes security testing)
npm run test:complete
# or
./test.sh
Test Environment
The project includes a comprehensive test environment with:
- PostgreSQL 15.13 in Docker
- Realistic e-commerce test data (74 records across 6 tables)
- Security validation tests
- Automated setup and cleanup
See test/README.md for detailed testing documentation.
Development
# Development mode (rebuild and run)
npm run dev
# Build only (required after code changes)
npm run build
# Test database connection
npm run test-connection
# Test security features
npm run test-mcp-security
Note: You only need to run npm run build when you modify the TypeScript source code. For normal usage with different database credentials, just update your .env file.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.