Give Claude Control of Your n8n Workflows with MCP
One of the most powerful things you can do with n8n's MCP support is let AI agents manage n8n itself. Not just trigger workflows, but actually read, create, and modify them programmatically.
This is the foundation for self-healing automation systems, AI-assisted workflow development, and meta-automation patterns where your workflows can evolve themselves.
Here's how to set it up.
The Architecture
flowchart LR
A[Claude / AI Agent] -->|MCP Protocol| B[n8n MCP Server]
B --> C[List Workflows]
B --> D[Get Workflow]
B --> E[Create Workflow]
B --> F[Update Workflow]
C --> G[n8n REST API]
D --> G
E --> G
F --> G
style A fill:#e1f5fe
style B fill:#fff3e0
style G fill:#c8e6c9
The setup consists of:
- An MCP Server Trigger node that exposes your tools to AI agents
- Tool nodes that wrap the n8n REST API endpoints
- The n8n API itself, which handles the actual CRUD operations
Setting Up the MCP Server
First, create a new workflow with an MCP Server Trigger node. This is the entry point that AI agents will connect to.
The trigger automatically generates an SSE endpoint URL like:
https://your-n8n-instance.com/mcp/your-webhook-id/sse
This URL is what you'll add to Claude Desktop, the Claude web app, or any MCP-compatible client.
The Four Workflow Management Tools
1. List Workflows
The simplest tool—returns all workflows with their IDs, names, and active status.
Node Type: Code Tool (@n8n/n8n-nodes-langchain.toolCode)
const apiKey = 'your-n8n-api-key';
const res = await this.helpers.httpRequest({
method: 'GET',
url: 'https://your-n8n-instance.com/api/v1/workflows?limit=100',
headers: { 'X-N8N-API-KEY': apiKey },
json: true
});
const workflows = res.data.map(w => ({
id: w.id,
name: w.name,
active: w.active
}));
return JSON.stringify(workflows, null, 2);
Why a Code Tool? The n8n API returns a lot of data per workflow. By using a Code Tool, we can filter down to just the essential fields, making it easier for the AI to work with.
2. Get Workflow
Retrieves the full workflow definition including all nodes and connections.
Node Type: HTTP Request Tool (n8n-nodes-base.httpRequestTool)
Configuration:
- Method:
GET - URL:
https://your-n8n-instance.com/api/v1/workflows/{{ $fromAI('ID', 'The workflow ID to retrieve', 'string') }} - Headers:
X-N8N-API-KEY: your-api-key
The $fromAI() function is key here—it tells the MCP system that this parameter should come from the AI agent, with a description to help the AI understand what to provide.
3. Create Workflow
Creates a new workflow from a JSON definition.
Node Type: HTTP Request Tool
Configuration:
- Method:
POST - URL:
https://your-n8n-instance.com/api/v1/workflows - Headers:
X-N8N-API-KEY: your-api-key - Body:
{{ $fromAI('Body', 'JSON workflow payload with name, nodes, connections, settings', 'string') }}
The n8n API requires these minimum fields:
name- Workflow namenodes- Array of node definitionsconnections- Object defining how nodes connectsettings- Workflow settings object
4. Update Workflow
Updates an existing workflow by ID.
Node Type: HTTP Request Tool
Configuration:
- Method:
PUT - URL:
https://your-n8n-instance.com/api/v1/workflows/{{ $fromAI('ID', 'workflow id', 'string') }} - Headers:
X-N8N-API-KEY: your-api-key - Body:
{{ $fromAI('Body', 'JSON workflow update payload', 'string') }}
Important: The PUT endpoint requires the complete workflow definition, not just the fields you want to change. Always GET the workflow first, modify what you need, then PUT the entire object back.
Connecting the Tools
All four tools connect to the MCP Server Trigger via the ai_tool connection type:
flowchart TD
A[MCP Server Trigger]
B[List Workflows] -->|ai_tool| A
C[Get Workflow] -->|ai_tool| A
D[Create Workflow] -->|ai_tool| A
E[Update Workflow] -->|ai_tool| A
style A fill:#fff3e0
In the n8n UI, drag from each tool's output to the MCP Server Trigger. The connection type will automatically be set to ai_tool.
The $fromAI() Function
This is the magic that makes MCP tools work. The syntax is:
$fromAI('parameterName', 'description for the AI', 'type')
Types supported:
'string'- Text values'number'- Numeric values'boolean'- True/false'json'- Complex objects (but see the gotcha below)
Gotcha with JSON types: When using 'json' as the type with a raw body, the MCP schema generation can fail to properly type the parameter. Instead of:
// This can cause schema validation issues
body: $fromAI('body', 'JSON object', 'json')
Use structured JSON with individual typed fields:
// This generates proper typed schemas
jsonBody: `={
"name": "{{ $fromAI('name', 'Workflow name', 'string') }}",
"active": {{ $fromAI('active', 'Active status', 'boolean') }}
}`
Getting Your n8n API Key
- Go to your n8n instance
- Click your user icon → Settings
- Navigate to API → API Keys
- Create a new API key with appropriate permissions
Store this securely—anyone with this key can manage your workflows.
Adding to Claude
Once your MCP workflow is active, add the server to Claude:
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"n8n-workflows": {
"url": "https://your-n8n-instance.com/mcp/your-webhook-id/sse"
}
}
}
Claude Web App: Go to Settings → Connectors → Add MCP Server and paste your SSE URL.
What You Can Do With This
With these four tools, an AI agent can:
Audit your automation: "List all my workflows and tell me which ones are inactive"
Debug issues: "Get the workflow called 'Customer Sync' and check if the API endpoint is correct"
Make fixes: "Update the HTTP node in workflow X to use the new API URL"
Build new workflows: "Create a simple workflow that triggers every hour and sends a Slack message"
Self-healing automation: Combine with error handling to let AI agents fix broken workflows automatically (see our self-healing workflows article)
Security Considerations
Giving AI agents write access to your workflows is powerful but requires care:
- Use a dedicated API key with minimal permissions
- Consider read-only first - start with just List and Get until you trust the setup
- Log everything - the n8n execution log captures all API calls
- Test in staging - don't let AI agents modify production workflows until you've validated the patterns
Next Steps
This is the foundation. From here you can:
- Add execution management (trigger workflows, check status)
- Build self-healing systems that fix broken workflows
- Create AI-assisted workflow development tools
- Implement approval flows for AI-suggested changes
The n8n API has many more endpoints—credentials, executions, users—that you can expose through MCP as your needs grow.
This post was published using the exact MCP setup described above. Meta.