How to Connect n8n to a Custom MCP Server for Powerful AI Agents
n8n 2.15 natively supports MCP servers. By connecting your custom MCP server to an n8n AI Agent, you get an agent that accesses your proprietary data with n8n's reliability. Complete tutorial.
How to Connect n8n to a Custom MCP Server for Powerful AI Agents
You have an MCP server exposing your proprietary data. You have n8n to orchestrate your workflows. The combination of the two creates something remarkable: an AI agent that can act on your internal systems with precision and reliability impossible with cloud-only solutions.
This tutorial covers the n8n + MCP integration, from initial configuration to advanced patterns like persistent memory and production monitoring.
Why Connect n8n to MCP?
n8n is excellent for orchestrating predictable action sequences. But when actions depend on context — "which client is most urgent to follow up today?", "what's the best response to this email based on history?" — AI agents with access to your data via MCP are infinitely more relevant.
The n8n + MCP combination gives you:
- n8n's robust orchestration (triggers, retry, queue management)
- LLM contextual reasoning with access to your proprietary data via MCP
- Complete traceability of each action (n8n logs + MCP logs)
- Data sovereignty if you use n8n self-hosted + local MCP server
Basic Setup: n8n → MCP Tool
In n8n, the MCP Tool node (available since n8n 2.15) allows the AI Agent to directly call your MCP server. Configuration:
- In your workflow, add an AI Agent node
- In the AI Agent tools, add an MCP Tool node
- Configure your MCP server URL and authentication
- The rest is automatic: the agent discovers available tools and decides which ones to use
For an MCP server exposed via HTTP with Bearer authentication:
{
"serverUrl": "https://your-mcp.com/mcp",
"headers": {
"Authorization": "Bearer YOUR_SECRET_TOKEN"
}
}
Sample Workflow: Commercial Agent with CRM Access via MCP
Here's a complete n8n workflow that processes incoming prospect emails with an AI agent connected to your CRM via MCP:
Incoming email (Gmail trigger)
↓
Extract sender's email
↓
AI Agent (Claude Sonnet)
Tools: [MCP Tool connected to your CRM]
Instructions: "You receive an email from a prospect.
1. Use get_client to check if this contact exists in the CRM
2. If yes, retrieve their history and pipeline status
3. If not, note this is a new prospect
4. Generate a personalized response based on context"
↓
Send response via Gmail
↓
MCP Tool: update_client (log the exchange)
This workflow automatically handles prospect responses taking into account their CRM history, without a human having to look up the information.
Error Handling and Retry Logic
A production system must anticipate that your MCP server may be temporarily unavailable. In n8n, configure:
- Retry on error: enabled in MCP Tool node options
- Max retry count: 3
- Wait between tries: 2 seconds (progressive backoff)
For intelligent fallback when MCP is unavailable, add an IF node that checks if the response contains a connection error, and redirects to a fallback route (Slack notification, manual ticket creation) rather than failing the entire chain.
Advanced Pattern: Agents with Persistent Memory
One of the limits of classic AI agents is their lack of memory between sessions. By combining n8n + MCP + PostgreSQL, you create an agent that remembers.
In your MCP server, expose two additional tools:
// Tool 1: Save to memory
{
name: "remember",
description: "Saves important information for future interactions",
inputSchema: {
type: "object",
properties: {
key: { type: "string" },
value: { type: "string" },
context: { type: "string" } // client email, order ID, etc.
},
required: ["key", "value"]
}
}
// Tool 2: Retrieve from memory
{
name: "recall",
description: "Retrieves memorized information about a given context",
inputSchema: {
type: "object",
properties: {
context: { type: "string" }
},
required: ["context"]
}
}
With this architecture, your n8n agents can maintain context across sessions, offering a radically more personalized experience.
Monitoring Your MCP Server in Production
An MCP server without monitoring is a server that fails silently. Add a health endpoint:
app.get('/health', async (req, res) => {
const health = {
status: 'ok',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
memory: process.memoryUsage(),
};
res.json(health);
});
Then create a monitoring n8n workflow that pings your MCP server every 5 minutes. If the health check fails, an immediate Slack alert is sent.
Complete Example: Commercial Agent with Memory and MCP
Here's the complete architecture of a commercial agent BOVO Digital deployed for a SaaS client:
- Incoming email from a prospect
- n8n AI Agent with MCP access to tools: get_contact, recall (history), check_pipeline, enrich_contact
- The agent generates a personalized response taking into account profile, previous exchanges, funnel stage
- The agent chooses the action: direct response, demo proposal, or escalation to human commercial
- remember(context=email, key="last_contact", value=exchange summary)
Results measured over 3 months:
- Response time to new prospects: from 4h to 8 minutes
- Demo booking rate: +28% (better personalization)
- Commercial workload: -40% on incoming contacts
The Most Useful MCP Patterns in Production
Pattern 1: Read-only MCP for decisions The agent consults your data via MCP to make a decision (which response to send, which lead to prioritize) but all modifications go through n8n with optional human validation.
Pattern 2: Bidirectional MCP for complete automations The agent both reads and writes via MCP. Ideal for cases where the complete loop (read → decide → act → remember) can be fully automated.
Pattern 3: MCP as single source of truth Instead of configuring separate connections in n8n for each system (HubSpot, Notion, Slack, PostgreSQL), a single MCP server centralizes all access. The n8n agent has only one connection point.
Do you want to set up this n8n + MCP architecture for your workflows? BOVO Digital designs and deploys AI agents connected to your proprietary systems.
Tags

Vicentia Bonou
Full Stack Developer & Web/Mobile Specialist. Committed to transforming your ideas into intuitive applications and custom websites.
