[n8n template] Conversational PostgreSQL Agent (Multi-KPI, Secure, Visual-Free)
π§ Conversational PostgreSQL Agent (Multi-KPI, Secure, Visual-Free)
Enable AI-driven conversations with your PostgreSQL database using a secure and visual-free agent powered by n8nβs Model Context Protocol (MCP). This template allows users to ask multiple KPIs in a single message, returning consolidated insights β more efficient than the original Conversing with Data template.
------------------------------------------------------------
π Why This Template
Unlike the Conversing with Data workflow, which handles one KPI per message, this version:
- β Supports multi-KPI questions
- β Returns structured, human-readable reports
- β Uses fewer AI calls, making it faster and cheaper
- β Avoids raw SQL execution for enhanced security
π² Estimated cost per full multi-request run: ~$0.01
This template is optimized for efficiency. Each message can return 2β4 KPIs (You can change the MaxIteration of the Agent to make it more, it is currently set up at 30 iterations) using a single Claude 3.5 Haiku session and DeepSeek-based SQL generation β balancing speed, reasoning, and affordability.
------------------------------------------------------------
π¬ Sample Use Case
User:
βCan you show product performance, revenue trends, and top 5 customers?β
Agent:
- Uses ListTables and GetTableSchema
- Generates three SQL queries using get_query_and_data
- Returns:
Product Performance
1. High-Waist Jeans β 10 units, $1,027 revenue
2. Denim Jacket β 10 units, $783 revenue
Sales Trends
- Peak Month: January 2024 β 32 units, $2,378
- Average Monthly Units: 10β16
Customer Insights
1. Bob Brown β $1,520 spent
2. Diana Wilson β $925 spent
All from one natural prompt.
------------------------------------------------------------
πΌοΈ Real-World Interaction Screenshot
Paste your real image here once uploaded:
------------------------------------------------------------
π§° Whatβs Inside
- Build_your_own_PostgreSQL_MCP_server_No_visuals_.json β MCP agent logic
- checkdatabase.json β SQL generation and formatting utility workflow
- Usage instructions
- Screenshot placeholder
- Model setup guide
These must be uploaded into your n8n instance to function.
------------------------------------------------------------
π€ Model Selection Recommendations
1. Claude 3.5 Haiku (Anthropic)
Use this for the MCP agent. Itβs ideal because Claude is built by Anthropic, the creators of MCP. It performs well in reasoning and tool calls and is budget-friendly.
2. DeepSeek
Used in the subworkflow to convert text into SQL. Itβs one of the cheapest LLMs today and reliable for structured output like SQL.
This combo delivers powerful performance while keeping your cost low.
------------------------------------------------------------
π Security Benefits
- No raw SQL from the LLM
- Uses parameterized execution
- Outputs clean, human-readable summaries
- Ready for safe integration into apps and tools
------------------------------------------------------------
π§ͺ Try This Prompt
βShow me the top 5 products by units sold and revenue, total monthly sales trend, and top 5 customers by spending.β
What youβll get:
- Multiple validated queries
- Live schema handling
- One combined, readable result
------------------------------------------------------------
π How to Use
1. Upload both JSON files to your n8n instance
2. Set up your PostgreSQL credentials
3. Assign Claude 3.5 Haiku to the main MCP agent
4. Assign DeepSeek to the subworkflow
5. Connect your chatbot or UI to the /mcp/... endpoint and test
------------------------------------------------------------
π Customization Ideas
- Swap models with OpenAI, Gemini, Mistral, etc.
- Add Notion, Slack, or Google Sheets export
- Use Switch nodes to control access by user role
- Deploy it into your internal app or external chatbot
------------------------------------------------------------
π¦ What You Get
- Full MCP-ready agent workflow (no visuals required)
- Utility workflow for natural language β SQL
- Real use case tested
- Optional MaxIteration tweaks (default = 30)
------------------------------------------------------------
π Comparison: Conversing with Data vs This Workflow
- Multi-KPI Questions: Conversing β / This β
- Secure Query Execution: Both β
- Output Style: Conversing = JSON-heavy β οΈ / This = Clean language β
- Cost: Conversing = very low β / This = still cheap (~$0.01) β
- Endpoint Ready: Conversing β / This β
Prefer a lighter and cheaper option with chart support?
Try the original template I used for 3 months at just $0.80:
------------------------------------------------------------
π More From This Creator
If you're working on customer feedback or social listening:
Try: Customer Feedback Analysis with AI, QuickChart & HTML Report Generator
- Auto-analyze sentiment
- Detect trends
- Generate a full report
- Export as email-ready