Joemon-Jesudas/MCP-knowhub
If you are the rightful owner of MCP-knowhub and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP PostgreSQL Server enables natural language querying of PostgreSQL databases through Claude Desktop, providing both textual answers and automatic visualizations.
MCP PostgreSQL Server - Project Files Summary
This project provides a Model Context Protocol (MCP) server that enables natural language querying of PostgreSQL databases through Claude Desktop. Instead of writing SQL, users can ask questions in plain English and receive both textual answers and automatic visualizations.
📁 Files Created
1. mcp_postgres_server.py
Purpose: Main MCP server implementation with visualization support Description:
- FastMCP server with PostgreSQL integration
- Uses SQLAlchemy for database operations
- Provides 4 tools for database interaction
- Supports natural language query processing
- Automatic chart generation from query results**
- Read-only access (SELECT queries only)
- Connection pooling and error handling
Key Features:
- list_tables(): List all database tables
- describe_table(): Get table schema details
- execute_query(): Run SQL SELECT queries
- generate_visualization(): Create charts from SQL results
NEW Visualization Capabilities:
- Auto-detects best chart type (bar, line, pie, scatter)
- Analyzes data structure (numeric, text, date columns)
- Intelligent chart selection based on query intent
- Returns chart specifications for rendering
2. requirements.txt
Purpose: Python package dependencies Contents:
- fastmcp>=2.2.0
- sqlalchemy>=2.0.0
- psycopg2-binary>=2.9.0
- python-dotenv>=1.0.0
Installation: pip install -r requirements.txt or
uv add -r requirement.txt
3. .env
Purpose: Environment configuration
Variables:
- DB_HOST: PostgreSQL host (default: localhost)
- DB_PORT: PostgreSQL port (default: 5432)
- DB_NAME: Database name
- DB_USER: Database username
- DB_PASSWORD: Database password
4. claude_desktop_config.json
Purpose: Claude Desktop MCP configuration Description: Configuration template for connecting Claude Desktop to the MCP server
Usage:
- Copy contents to Claude's config file:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
- Windows: %APPDATA%\Claude\claude_desktop_config.json
- Update the absolute path to mcp_postgres_server.py
- Update database credentials in env section
- Restart Claude Desktop
Example Questions to Try
- "What tables are in my database?"
- "Describe the customers table"
- "Show me the database schema"
- "How many customers do I have?"
- "What's the total revenue this year?"
- "Show me the latest transactions"
- "List down first 20 records in 'table_name'
- "Who has the highest spend in 2025?"
- "Show monthly sales trend"
- "Compare revenue by region"
- "What's the distribution of customers by city?"
- "Is there a relationship between price and quantity?"
🎉 Summary
Your MCP PostgreSQL server now provides:
✅ Natural language database queries ✅ Automatic SQL generation ✅ Safe, read-only access ✅ Complete schema inspection ✅ Automatic chart generation ✅ Visual insights alongside text
Result: Users can now explore data through both conversation AND visualization!