Skip to main content

PostgreSQL conversational agent with Claude & DeepSeek (Multi-KPI, Secure)

Workflow preview

Workflow preview
100%
PostgreSQL conversational agent with Claude & DeepSeek (Multi-KPI, Secure) preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Conversational PostgreSQL Agent 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 all...

Best for

  • Engineering automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.postgrestool, n8n-nodes-base.executeworkflowtrigger, @n8n/n8n-nodes-langchain.toolworkflow, n8n-nodes-base.postgres, n8n-nodes-base.switch, n8n-nodes-base.stickynote, @n8n/n8n-nodes-langchain.mcptrigger, @n8n/n8n-nodes-langchain.chattrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by hippolyte-hu.

Original n8n.io source

1.1 Workflow description

Title
PostgreSQL conversational agent with Claude & DeepSeek (Multi-KPI, Secure)
Workflow name
PostgreSQL conversational agent with Claude & DeepSeek (Multi-KPI, Secure)

🧠 Conversational PostgreSQL Agent

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


🧰 What’s Inside

Node Purpose
MCP Server Trigger Receives user queries via /mcp/...
AI Agent + Memory Understands and plans multi-step queries
Think Tool Breaks down the user’s question into structured goals
get_query_and_data Generates SQL securely from natural language
ListTables, GetSchema AI tools to explore DB safely
Read/Insert/Update Tools Execute structured operations (never raw SQL)
checkdatabase Subflow Validates SQL, formats response as clean text

🤖 Model Selection Recommendations

This template uses two types of models, selected for cost-performance balance and role alignment:

1. Claude 3.5 Haiku (Anthropic) – for the MCP Agent
The main conversational agent uses Claude 3.5 Haiku, ideal for MCP because it was built by Anthropic — the creators of the MCP standard. It’s fast, affordable, and performs excellently in tool-calling and reasoning tasks.

2. DeepSeek – for the SQL subworkflow
The subworkflow that turns natural language into SQL uses DeepSeek. It’s one of the most affordable and performant models available today for structured outputs like SQL, making it a perfect fit for utility logic.

✅ This setup provides top-tier reasoning + low-cost execution.


🔐 Security Benefits

  • No raw SQL accepted from the user or LLM
  • All queries are parameterized
  • Schema is dynamically retrieved
  • Final output is clean, safe, and human-readable

🧪 Try a Prompt

> “Show me the top 5 products by units sold and revenue, total monthly sales trend, and top 5 customers by spending.”

In one message, the agent will:

  • Generate and run multiple queries
  • Use the schema to validate logic
  • Return a single, comprehensive answer

🛠 How to Use

  1. 📥 Upload both workflow files into your n8n instance:
    • Build_your_own_PostgreSQL_MCP_server_No_visuals_.json
    • checkdatabase.json
  2. 🔐 Set up PostgreSQL credentials (e.g. “Postgres account 3”)
  3. 🧠 Confirm model setup:
    • Claude 3.5 Haiku for the main agent
    • DeepSeek for the subflow
  4. 🌐 Use the /mcp/... URL from the MCP Server Trigger to connect your frontend or chatbot
  5. 🗣 Ask questions naturally — the agent takes care of planning, querying, and formatting

🔄 Customization Ideas

  • Swap Claude or DeepSeek for OpenAI, Mistral, Gemini, etc.
  • Export insights to Slack, Notion, or Google Sheets
  • Add Switch nodes to control access to specific tables
  • Integrate with any front-end app, internal dashboard, or bot

📦 What's Included

  • Build_your_own_PostgreSQL_MCP_server_No_visuals_.json – MCP agent logic
  • checkdatabase.json – SQL generation and formatting utility workflow

📝 These must be uploaded into your n8n workspace for the template to function.


📊 Comparison: Conversing with Data vs This Workflow

Feature Conversing with Data This Workflow
Handles multi-KPI questions ❌ No ✅ Yes
Secure query execution ✅ Yes ✅ Yes
Structured response ⚠️ JSON / raw ✅ Clean natural language
Cost-efficiency ⚠️ More calls ✅ Optimized with fewer calls
Endpoint support ❌ Manual interaction ✅ MCP-ready (/mcp/...)

🔗 Prefer something more lightweight and cost-sensitive?
Try the original Conversing with Data template (single KPI + chart support):
Conversing with Data: Transforming Text into SQL Queries and Visual Curves

> I used this version for over 3 months and only spent $0.80 total, making it a great entry point if you're just getting started or on a limited budget.


📚 More from the Same Creator

Looking for a different kind of AI reporting workflow?

Explore:
Customer Feedback Analysis with AI, QuickChart & HTML Report Generator
→ Automatically analyze customer input and generate full reports with insights and charts.
Customer Feedback Analysis with AI, QuickChart & HTML Report Generator

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - GetTableSchema

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.6

Block 2 - ListTables

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.6

Block 3 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 4 - CreateTableRecords

Type / Role
@n8n/n8n-nodes-langchain.toolWorkflow - toolWorkflow
Config choices
Version 2.1

Block 5 - ReadTableRecord

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 6 - Operation

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 7 - UpdateTableRecord

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 8 - UpdateTableRecords

Type / Role
@n8n/n8n-nodes-langchain.toolWorkflow - toolWorkflow
Config choices
Version 2.1

Block 9 - CreateTableRecord

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - PostgreSQL MCP Server

Type / Role
@n8n/n8n-nodes-langchain.mcpTrigger - mcpTrigger
Config choices
Version 1

Block 12 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 13 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 14 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 15 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 16 - MCP Client

Type / Role
@n8n/n8n-nodes-langchain.mcpClientTool - mcpClientTool
Config choices
Version 1

Block 17 - Anthropic Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatAnthropic - lmChatAnthropic
Config choices
Version 1.3

Block 18 - Think

Type / Role
@n8n/n8n-nodes-langchain.toolThink - toolThink
Config choices
Version 1

Block 19 - get table details

Type / Role
@n8n/n8n-nodes-langchain.toolWorkflow - toolWorkflow
Config choices
Version 2.1

Block 20 - ReadTableRows

Type / Role
@n8n/n8n-nodes-langchain.toolWorkflow - toolWorkflow
Config choices
Version 2.1

Block 21 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow PostgreSQL conversational agent with Claude & DeepSeek (Multi-KPI, Secure)
Complexity advanced
Nodes 21
Categories Engineering, AI RAG
Author hippolyte-hu
Published 06 May 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/3892/3892.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does PostgreSQL conversational agent with Claude & DeepSeek (Multi-KPI, Secure) do?

Conversational PostgreSQL Agent 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 all...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI RAG use case.