← All N8N workflows
Data & databasesExecute Workflow TriggerMcp TriggerPostgresPostgres ToolSwitch

Always Authenticate Your Server!

Configured with Execute Workflow Trigger, Mcp Trigger, Postgres, Postgres Tool, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
Data storeGetTableSchemaPostgres ToolData storeListTablesPostgres ToolTriggerWhen Executed byAnother WorkflowExecute Workflow TriggerSubworkflowCreateTableRecordsTool WorkflowData storeReadTableRecordPostgresRoutingOperationSwitchData storeUpdateTableRecordPostgresSubworkflowUpdateTableRecordsTool WorkflowData storeCreateTableRecordPostgresSubworkflowReadTableRowsTool WorkflowTriggerPostgreSQL MCP ServerMcp Trigger

Node categories in this workflow

  • Data store
  • Trigger
  • Subworkflow
  • Routing

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
GetTableSchemaData storePostgres ToolexecuteQuery
ListTablesData storePostgres ToolexecuteQuery
When Executed by Another WorkflowTriggerExecute Workflow TriggerSee node parameters
CreateTableRecordsSubworkflowTool WorkflowSee node parameters
ReadTableRecordData storePostgresexecuteQuery
OperationRoutingSwitchSee node parameters
UpdateTableRecordData storePostgresexecuteQuery
UpdateTableRecordsSubworkflowTool WorkflowSee node parameters
CreateTableRecordData storePostgresexecuteQuery
ReadTableRowsSubworkflowTool WorkflowSee node parameters
PostgreSQL MCP ServerTriggerMcp TriggerSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • postgres

Workflow notes

1. Set up an MCP Server Trigger

1. Set up an MCP Server Trigger

Read more about the MCP Server Trigger

2. Keep Secure by Preventing Raw SQL Statements

2. Keep Secure by Preventing Raw SQL Statements

Read more about the PostgreSQL Node

Whilst it may be easier to just let the Agent provide the full raw SQL statement, it may expose you or your organisation to a real security risk where in the worst case, data may be unknowingly leaked or deleted.

Forcing the agent to provide only the parameters of the query means we can guard somewhat against this risk and also allows use of query parameters as best practice against SQL injection attacks.

Try It Out!

Try It Out!

This n8n demonstrates how to build a simple PostgreSQL MCP server to manage your PostgreSQL database such as HR, Payroll, Sale, Inventory and More!

This MCP example is based off an official MCP reference implementation which can be found here -https://github.com/modelcontextprotocol/servers/tree/main/src/postgres

How it works

  • A MCP server trigger is used and connected to 5 tools: 2 postgreSQL and 3 custom workflow.
  • The 2 postgreSQL tools are simple read-only queries and as such, the postgreSQL tool can be simply used.
  • The 3 custom workflow tools are used for select, insert and update queries as these are operations which require a bit more discretion.
  • Whilst it may be easier to allow the agent to use raw SQL queries, we may find it a little safer to just allow for the parameters instead. The custom workflow tool allows us to define this restricted schema for tool input which we'll use to construct the SQL statement ourselves.
  • All 3 custom workflow tools trigger the same "Execute workflow" trigger in this very template which has a switch to route the operation to the correct handler.
  • Finally, we use our standard PostgreSQL node to handle select, insert and update operations. The responses are then sent back to the the MCP client.

How to use

  • This PostgreSQL MCP server allows any compatible MCP client to manage a PostgreSQL database by supporting select, create and update operations. You will need to have a database available before you can use this server.
  • Connect your MCP client by following the n8n guidelines here - https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.mcptrigger/#integrating-with-claude-desktop
  • Try the following queries in your MCP client:
    • "Please help me check if Alex has an entry in the users table. If not, please help me create a record for her."
    • "What was the top selling product in the last week?"
    • "How many high priority support tickets are still open this morning?"

Requirements

  • PostgreSQL for database. This can be an external database such as Supabase or one you can host internally.
  • MCP Client or Agent for usage such as Claude Desktop - https://claude.ai/download

Customising this workflow

  • If the scope of schemas or tables is too open, try restrict it so the MCP serves a specific purpose for business operations. eg. Confine the querying and editing to HR only tables before providing access to people in that department.
  • Remember to set the MCP server to require credentials before going to production and sharing this MCP server with others!
Always Authenticate Your Server!

Always Authenticate Your Server!

Before going to production, it's always advised to enable authentication on your MCP server trigger.

Always Authenticate Your Server!

Always Authenticate Your Server!

Purpose and structure

This folder contains the Always Authenticate Your Server! workflow. Its executable nodes use executeWorkflowTrigger, mcpTrigger, postgres, postgresTool, switch, toolWorkflow. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

When Executed by Another Workflow, PostgreSQL MCP Server

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Stickynote/0873_Stickynote_Postgrestool_Create_Triggered.json MIT; preserve source notices.

More in Data & databases