Integrations
Manages configuration through environment variables using .env files for storing database credentials, server settings, and security parameters.
Supports repository cloning for installation and source code management during development.
Provides example code for API interaction, allowing clients to execute queries and interact with analysis templates.
MCP PostgreSQL Server
A Model-Controller-Provider (MCP) server that:
- Connects to a PostgreSQL database
- Exposes table schemas as resources
- Provides tools for running read-only SQL queries
- Includes prompts for common data analysis tasks
Features
- Schema Exploration: Browse database schemas, tables, and columns
- Read-only Query Execution: Safely run SQL queries against your database
- Data Analysis Prompts: Pre-built SQL templates for common analysis tasks
- Data Visualization: Generate data for visualization
- Relationship Exploration: Visualize table relationships and foreign keys
- API Documentation: Auto-generated OpenAPI specification
Architecture
This application follows the Model-Controller-Provider (MCP) pattern:
- Model Layer: Direct interaction with the database
- Provider Layer: Business logic and data processing
- Controller Layer: API endpoints and request handling
Security Features
- Read-only query validation
- SQL injection protection
- Rate limiting
- Parameterized queries
- Authentication support
- CORS configuration
Installation
- Clone the repository:
- Install dependencies:
- Create a
.env
file based on the.env.template
: - Update the
.env
file with your PostgreSQL database credentials. - Start the server:
Configuration
All configuration is managed through environment variables:
- Server: Port, environment, CORS settings
- Database: Connection details, pool settings
- Security: JWT settings, rate limiting
- Query: Execution limits, result size limits
API Endpoints
Schema Endpoints
GET /api/schemas
- List all schemasGET /api/schemas/:schema/tables
- List tables in a schemaGET /api/schemas/:schema/tables/:table
- Get table schema detailsGET /api/schemas/:schema/relationships
- Get table relationshipsGET /api/structure
- Get complete database structureGET /api/search?q=term
- Search tables and columns
Query Endpoints
POST /api/query
- Execute a SQL queryPOST /api/query/explain
- Get query execution planGET /api/schemas/:schema/tables/:table/sample
- Get sample dataGET /api/schemas/:schema/tables/:table/stats
- Get table statistics
Analysis Prompt Endpoints
GET /api/prompts
- List analysis prompt templatesGET /api/prompts/:templateId
- Get prompt template detailsPOST /api/prompts/:templateId/generate
- Generate SQL from templateGET /api/schemas/:schema/tables/:table/analysis/suggest
- Get analysis suggestions
Example Queries
Basic Table Query
Using Analysis Prompts
Development
- Run in development mode:
npm run dev
- Run tests:
npm test
- Lint code:
npm run lint
License
MIT
You must be authenticated.
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A server that connects to PostgreSQL databases and provides tools for safely exploring schemas, running read-only SQL queries, and performing data analysis with pre-built templates.
Related Resources
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.Last updated a day ago119,91742,199JavaScriptMIT License
- AsecurityAlicenseAqualityFacilitates management and optimization of PostgreSQL databases, offering analysis, setup guidance, and debugging, while ensuring secure and efficient database operations.Last updated 20 days ago34TypeScriptAGPL 3.0
- -securityFlicense-qualityProvides read-only access to PostgreSQL databases, enabling users to inspect database schemas and execute read-only queries through a Model Context Protocol server.Last updated 2 months ago3JavaScript
- -securityFlicense-qualityA server that allows AI models to interact with PostgreSQL databases through a standardized protocol, providing database schema information and SQL query execution capabilities.Last updated 2 months agoJavaScript