PostgreSQL MCP Server is a Model Context Protocol (MCP) server that provides secure, read-only access to PostgreSQL databases for AI assistants and other MCP clients. It enables intelligent database analysis, querying, and schema exploration through a standardized interface.
git clone https://github.com/likhon-developer/file-mcp.git cd file-mcp npm install cp .env.example .env.local
Edit .env.local with your DATABASE_URL, then run:
npm run dev
DATABASE_URL=postgresql://username:password@hostname:port/database
Add the following configuration to your MCP client:
Location: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
{
"mcpServers": {
"postgresql": {
"url": "https://file-mcp.vercel.app/api/mcp"
}
}
}Execute read-only SQL queries against the database
query(string) (required) - The SQL query to executelimit(number) (optional) - Maximum rows to return (default: 100, max: 1000)SELECT * FROM users WHERE created_at > '2024-01-01' LIMIT 10Get detailed information about a specific table
tableName(string) (required) - Name of the table to analyzeusersGenerate common data analysis queries for a table
tableName(string) (required) - Name of the table to analyzeanalysisType(enum) (required) - Type of analysis: summary, distribution, nulls, duplicates, trendsusers, summarySearch for tables and columns matching a pattern
pattern(string) (required) - Search patternsearchType(enum) (optional) - What to search: tables, columns, both (default)user, bothComplete database schema with all tables and columns in JSON format
postgresql://database-schemaType: application/jsonSimple list of all tables in the database
postgresql://table-listType: text/plainOnly SELECT, WITH, EXPLAIN, SHOW, and DESCRIBE queries are allowed
Advanced query validation and parameter sanitization
Comprehensive validation of table names and user inputs
Secure error messages that don't expose sensitive information
The following SQL operations are automatically blocked:
INSERT, UPDATE, DELETE, DROP, CREATE, ALTER, TRUNCATESELECT * FROM users WHERE created_at > '2024-01-01' LIMIT 10;
SELECT status, COUNT(*) FROM orders GROUP BY status;
SELECT product_name, SUM(quantity) as total_sold FROM order_items GROUP BY product_name ORDER BY total_sold DESC LIMIT 5;
Get basic statistics about any table
Use analyze_data tool with analysisType: 'summary'Analyze value distributions in columns
Use analyze_data tool with analysisType: 'distribution'Find missing data patterns
Use analyze_data tool with analysisType: 'nulls'Analyze time-based patterns
Use analyze_data tool with analysisType: 'trends'