8
n8n 中文网amn8n.com

构建自定义n8n工作流MCP服务器

高级

这是一个Other, AI, IT Ops领域的自动化工作流,包含 46 个节点。主要使用 If, N8n, Set, Redis, Filter 等节点,结合人工智能技术实现智能自动化。 构建自定义n8n工作流MCP服务器

前置要求
  • Redis 服务器连接信息
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "e3ed1048-bad0-4e91-bfb5-aef3e1883de4",
      "name": "简化工作流",
      "type": "n8n-nodes-base.set",
      "position": [
        -1740,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "821226b0-12ad-4d1d-81c3-dfa3c286cce4",
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "629d95d6-2501-4ad4-a5ed-e557237e1cc2",
              "name": "name",
              "type": "string",
              "value": "={{ $json.name }}"
            },
            {
              "id": "30699f7c-98d3-44ee-9749-c5528579f7e6",
              "name": "description",
              "type": "string",
              "value": "={{\n$json.nodes\n  .filter(node => node.type === 'n8n-nodes-base.stickyNote')\n  .filter(node => node.parameters.content.toLowerCase().includes('try it out'))\n  .map(node => node.parameters.content.substr(0,255) + '...')\n  .join('\\n')\n}}"
            },
            {
              "id": "6199c275-1ced-4f72-ba59-cb068db54c1b",
              "name": "parameters",
              "type": "string",
              "value": "={{\n(function(node) {\n  if (!node) return {};\n  const inputs = node.parameters.workflowInputs.values;\n  return {\n    \"type\": \"object\",\n    \"required\": inputs.map(input => input.name),\n    \"properties\": inputs.reduce((acc, input) => ({\n      ...acc,\n      [input.name]: { type: input.type ?? 'string' }\n    }), {})\n  }\n})(\n$json.nodes\n  .filter(node => node.type === 'n8n-nodes-base.executeWorkflowTrigger')\n  .first()\n)\n.toJsonString()\n}}"
            }
          ]
        }
      },
      "executeOnce": false,
      "typeVersion": 3.4
    },
    {
      "id": "a935f5b6-3a35-49e7-870c-87e4daf0ad13",
      "name": "当被其他工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -3060,
        600
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "operation"
            },
            {
              "name": "workflowIds"
            },
            {
              "name": "parameters",
              "type": "object"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "2ff5e521-5288-47a9-af49-55a1bbbfb4f4",
      "name": "运维",
      "type": "n8n-nodes-base.switch",
      "position": [
        -2660,
        560
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Add",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3254a8f9-5fd3-4089-be16-cc3fd20639b8",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').first().json.operation }}",
                    "rightValue": "addWorkflow"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "remove",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a33dd02d-5192-48c9-b569-eafddabd2462",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').first().json.operation }}",
                    "rightValue": "removeWorkflow"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "list",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "2d68dc3f-a213-47f8-8453-1bceae404653",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').first().json.operation }}",
                    "rightValue": "listWorkflows"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "search",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "2146a87e-1a50-4caa-a2ee-f7f6fc2b19c9",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').first().json.operation }}",
                    "rightValue": "searchWorkflows"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "execute",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "98b25a51-2cb5-49af-9609-827245595dc9",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('When Executed by Another Workflow').first().json.operation }}",
                    "rightValue": "executeWorkflow"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "5b78271a-6474-4d87-a344-72f7f63822dc",
      "name": "获取带MCP标签的工作流",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -2400,
        200
      ],
      "parameters": {
        "filters": {
          "tags": "mcp"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "5vELmsVPmK4Bkqkg",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1197d29e-b124-4576-846d-876ad16de6e9",
      "name": "过滤匹配的ID",
      "type": "n8n-nodes-base.filter",
      "position": [
        -2180,
        200
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "90c97733-48de-4402-8388-5d49e3534388",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{\n$json.id\n  ? $('When Executed by Another Workflow').first().json.workflowIds.split(',').includes($json.id)\n  : false\n}}",
              "rightValue": "={{ $json.id }}"
            }
          ]
        }
      },
      "executeOnce": false,
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "81623298-c3e7-4e20-86a9-d2587b302f28",
      "name": "存储在内存中",
      "type": "n8n-nodes-base.redis",
      "position": [
        -1520,
        0
      ],
      "parameters": {
        "key": "mcp_n8n_tools",
        "value": "={{\n($('Get Memory').item.json.data?.parseJson() ?? [])\n  .concat($input.all().map(item => item.json))\n  .toJsonString()\n}}",
        "operation": "set"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "executeOnce": true,
      "typeVersion": 1
    },
    {
      "id": "5ff0ea2f-a2ee-4cc3-bdf9-153ce5973770",
      "name": "添加工具成功",
      "type": "n8n-nodes-base.set",
      "position": [
        -1300,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d921063f-e8ed-44a8-95a0-4402ecde6c5d",
              "name": "=response",
              "type": "string",
              "value": "={{ $('Simplify Workflows').all().length }} tools were added successfully."
            }
          ]
        }
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "1d3169cc-15cd-4296-9e63-bb162322e5e2",
      "name": "添加工具错误",
      "type": "n8n-nodes-base.set",
      "position": [
        -1740,
        200
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8c4e0763-a4ff-4e8a-a992-13e4e12a5685",
              "name": "response",
              "type": "string",
              "value": "Expected Tools matching Ids given, but none found."
            }
          ]
        }
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "6149a950-c1ed-44b4-aee6-3daeabf8ba01",
      "name": "获取内存",
      "type": "n8n-nodes-base.redis",
      "position": [
        -2860,
        600
      ],
      "parameters": {
        "key": "mcp_n8n_tools",
        "options": {},
        "operation": "get",
        "propertyName": "data"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3c538002-45f7-4a2f-9ef4-5aede63235ab",
      "name": "分离输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -2180,
        400
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "d41e48e0-d610-4e18-9942-842419c99c83",
      "name": "过滤匹配的ID",
      "type": "n8n-nodes-base.filter",
      "position": [
        -1960,
        400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d2c149fb-d115-449b-9b74-f3c2f8ff7950",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "leftValue": "={{\n$json.id\n  ? $('Operations').first().json.workflowIds.split(',').includes($json.id)\n  : false\n}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "21d8cdda-bb47-42cd-a056-809a5556b438",
      "name": "存储在内存中1",
      "type": "n8n-nodes-base.redis",
      "position": [
        -1520,
        500
      ],
      "parameters": {
        "key": "mcp_n8n_tools",
        "value": "={{ $input.all().flatMap(item => item.json.data).compact() }}",
        "operation": "set"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "executeOnce": true,
      "typeVersion": 1
    },
    {
      "id": "5a391d0a-ba13-4d54-85fd-eb2f6a935614",
      "name": "移除工具成功",
      "type": "n8n-nodes-base.set",
      "position": [
        -1300,
        400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1368947f-6625-4e2e-ae27-0fcad0a1d12a",
              "name": "response",
              "type": "string",
              "value": "={{ $('When Executed by Another Workflow').first().json.workflowIds.split(',').length }} tool(s) removed successfully."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "65dfecc4-43ba-4518-adbf-9676c5cb1377",
      "name": "转换为JSON",
      "type": "n8n-nodes-base.set",
      "position": [
        -2400,
        400
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bce29a06-cff6-4409-96d2-04cc858a0e98",
              "name": "data",
              "type": "array",
              "value": "={{ $json.data.parseJson() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b8b64fc2-63cf-4b17-9b6d-9d94aec10065",
      "name": "列出工具成功",
      "type": "n8n-nodes-base.set",
      "position": [
        -2400,
        600
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bce29a06-cff6-4409-96d2-04cc858a0e98",
              "name": "response",
              "type": "array",
              "value": "={{\n$json.data\n  ? $json.data.parseJson()\n  : []\n}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d4fd9e74-f040-4b3c-8ce0-371315a0d130",
      "name": "获取带MCP标签的工作流1",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -2180,
        600
      ],
      "parameters": {
        "filters": {
          "tags": "mcp"
        },
        "requestOptions": {}
      },
      "credentials": {
        "n8nApi": {
          "id": "5vELmsVPmK4Bkqkg",
          "name": "n8n account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d58922c4-b721-4228-83cb-0b1d9632bbc6",
      "name": "简化工作流1",
      "type": "n8n-nodes-base.set",
      "position": [
        -1960,
        600
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "821226b0-12ad-4d1d-81c3-dfa3c286cce4",
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "629d95d6-2501-4ad4-a5ed-e557237e1cc2",
              "name": "name",
              "type": "string",
              "value": "={{ $json.name }}"
            },
            {
              "id": "30699f7c-98d3-44ee-9749-c5528579f7e6",
              "name": "description",
              "type": "string",
              "value": "={{\n$json.nodes\n  .filter(node => node.type === 'n8n-nodes-base.stickyNote')\n  .filter(node => node.parameters.content.toLowerCase().includes('try it out'))\n  .map(node => node.parameters.content.substr(0,255) + '...')\n  .join('\\n')\n}}"
            },
            {
              "id": "137221ef-f0a3-4441-bae7-d9d4a22e05b7",
              "name": "parameters",
              "type": "string",
              "value": "={{\n(function(node) {\n  if (!node) return {};\n  const inputs = node.parameters.workflowInputs.values;\n  return {\n    \"type\": \"object\",\n    \"required\": inputs.map(input => input.name),\n    \"properties\": inputs.reduce((acc, input) => ({\n      ...acc,\n      [input.name]: { type: input.type ?? 'string' }\n    }), {})\n  }\n})(\n$json.nodes\n  .filter(node => node.type === 'n8n-nodes-base.executeWorkflowTrigger')\n  .first()\n)\n.toJsonString()\n}}"
            }
          ]
        }
      },
      "executeOnce": false,
      "typeVersion": 3.4
    },
    {
      "id": "b44b1115-5153-4b98-979f-219a32b693de",
      "name": "列出工具成功1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -1740,
        600
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "response"
      },
      "typeVersion": 1
    },
    {
      "id": "e9d9a33c-ebfa-4f74-a4da-fb6b6f6f6df5",
      "name": "获取参数",
      "type": "n8n-nodes-base.set",
      "position": [
        -1920,
        1020
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={{ $('When Executed by Another Workflow').first().json.parameters }}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "c028324a-5c79-4ce9-afd6-097b6f75a74a",
      "name": "执行工具结果",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -1440,
        1020
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "response"
      },
      "typeVersion": 1
    },
    {
      "id": "9eeac3cb-af7e-44c7-8891-6ff4367d0b54",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -3600,
        1040
      ],
      "parameters": {
        "options": {
          "systemMessage": "=You are a helpful assistant who only uses workflows to answer questions and perform tasks.\n* When asked to complete a task, you will assume there is a workflow which you can use. Do not generate custom scripts or raw commands - use a workflow isntead.\n* Only use the available active workflows as listed using the \"listWorkflows\" tool.\n* Workflows returned by \"listWorkflows\" tool are active in the pool and do not need to be added again.\n* Always ask the user before adding workflows to the availble pool.\n* You do not need to confirm each step with the user when executing workflows.\n* When executing the workflow, the required parameters schema for it is listed in the workflow's profile. To get this profile, use the listWokflows tool.\n* If no available workflows are suitable and you are not able to complete the task, simply let the user know.\n* Do not search for workflows in the directory unless the user requests."
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "23601548-7863-403e-a671-267bf592b824",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -3840,
        1040
      ],
      "webhookId": "86a50552-8058-4896-bd7e-ab95eba073ce",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "54ed210d-e1b8-4bd7-85e4-88678111a45e",
      "name": "MCP客户端",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        -3360,
        1240
      ],
      "parameters": {
        "sseEndpoint": "=<Production URL of MCP Server>"
      },
      "typeVersion": 1
    },
    {
      "id": "c612da64-9cc1-4601-a987-cd2023fd1863",
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -3500,
        1240
      ],
      "parameters": {
        "contextWindowLength": 30
      },
      "typeVersion": 1.3
    },
    {
      "id": "77a9fd22-c31c-49e4-9d5f-af572b137925",
      "name": "转换为JSON1",
      "type": "n8n-nodes-base.set",
      "position": [
        -2360,
        1120
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bce29a06-cff6-4409-96d2-04cc858a0e98",
              "name": "data",
              "type": "array",
              "value": "={{ $json.data.parseJson() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3377aa25-4190-4bdc-be20-b4e324212060",
      "name": "有可用工作流吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        -2140,
        1120
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9c9df00b-b090-4773-8012-1824b4eeb13f",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{\n$json.data.find(d => d.id === $('When Executed by Another Workflow').item.json.workflowIds)\n}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "92b1bb21-d739-47f0-a278-92ffa5a10cbf",
      "name": "执行工具错误",
      "type": "n8n-nodes-base.set",
      "position": [
        -1920,
        1220
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "2fa3e311-e836-42f4-922a-fae19d8e0267",
              "name": "response",
              "type": "string",
              "value": "=Expected workflow to be available but not yet added. You can only use workflows which have been added to the available pool. Use the listWorkflows tool to see available workflows."
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "529e35e0-cf11-405a-9011-e6f7f2122a4e",
      "name": "工作流存在吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1960,
        200
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "15aef770-639e-4df0-900f-29013ccd00c4",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ba278834-c774-4a3d-8ebc-f64ac77317c2",
      "name": "N8N工作流MCP服务器",
      "type": "@n8n/n8n-nodes-langchain.mcpTrigger",
      "position": [
        -3720,
        240
      ],
      "webhookId": "4625bcf4-0dd9-4562-a70f-6fee41f6f12d",
      "parameters": {
        "path": "4625bcf4-0dd9-4562-a70f-6fee41f6f12d"
      },
      "typeVersion": 1
    },
    {
      "id": "ed940612-4772-4377-afe2-5484a8978665",
      "name": "添加工作流",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -3800,
        460
      ],
      "parameters": {
        "name": "addWorkflow",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "通过ID将一个或多个工作流添加到代理的可用工作流池中。您可以通过调用listTool工具获取工作流列表。",
        "workflowInputs": {
          "value": {
            "operation": "addWorkflow",
            "parameters": "null",
            "workflowIds": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('workflowIds', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "workflowIds",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflowIds",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "parameters",
              "type": "object",
              "display": true,
              "required": false,
              "displayName": "parameters",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "e7d5096c-3545-43fd-aa1f-495dc041ccce",
      "name": "移除工作流",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -3700,
        560
      ],
      "parameters": {
        "name": "removeWorkflow",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "通过ID从代理的可用工作流池中移除一个或多个工作流。",
        "workflowInputs": {
          "value": {
            "operation": "removeWorkflow",
            "parameters": "null",
            "workflowIds": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('workflowIds', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "workflowIds",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflowIds",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "parameters",
              "type": "object",
              "display": true,
              "required": false,
              "displayName": "parameters",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "c20b63dc-e768-4529-a08c-5370853fc4c9",
      "name": "列出工作流",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -3580,
        660
      ],
      "parameters": {
        "name": "listTool",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "列出代理的可用工作流池中的工作流。",
        "workflowInputs": {
          "value": {
            "operation": "listWorkflows",
            "parameters": "null",
            "workflowIds": "null"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "workflowIds",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflowIds",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "parameters",
              "type": "object",
              "display": true,
              "required": false,
              "displayName": "parameters",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "88fb8a1e-2f4c-4ff1-8be9-0f7afee2dd4d",
      "name": "搜索工作流",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -3460,
        560
      ],
      "parameters": {
        "name": "searchTool",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "返回所有可以添加到代理可用工作流池中的工作流。",
        "workflowInputs": {
          "value": {
            "operation": "searchWorkflows",
            "parameters": "null",
            "workflowIds": "null"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "workflowIds",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflowIds",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "parameters",
              "type": "object",
              "display": true,
              "required": false,
              "displayName": "parameters",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "c643c007-de89-4d94-9739-aeb2032c792f",
      "name": "执行工作流",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -3340,
        460
      ],
      "parameters": {
        "name": "executeTool",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "执行已添加到代理可用工作流池中的工作流。",
        "workflowInputs": {
          "value": {
            "operation": "executeWorkflow",
            "parameters": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters', ``, 'string') }}",
            "workflowIds": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('workflowIds', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "workflowIds",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "workflowIds",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "parameters",
              "type": "object",
              "display": true,
              "required": false,
              "displayName": "parameters",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "4f1c1559-8d50-48b1-94f2-542e0bb4d494",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3920,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 740,
        "content": "## 1. 添加MCP服务器触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "54d61491-04dc-4263-96e0-67827842ca07",
      "name": "使用穿透变量执行工作流",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        -1660,
        1020
      ],
      "parameters": {
        "options": {
          "waitForSubWorkflow": true
        },
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Executed by Another Workflow').first().json.workflowIds }}"
        },
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "executeOnce": false,
      "typeVersion": 1.2
    },
    {
      "id": "1042884f-a44c-4757-9ff9-3a5cc81058f2",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2600,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 740,
        "height": 300,
        "content": "## 2. 动态管理\"可用\"工作流列表"
      },
      "typeVersion": 1
    },
    {
      "id": "903ead44-3eab-4606-aa4e-e66378bb5f7e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2420,
        820
      ],
      "parameters": {
        "color": 7,
        "width": 1160,
        "height": 600,
        "content": "## 3. 让代理执行任何N8N工作流"
      },
      "typeVersion": 1
    },
    {
      "id": "194fbcbc-a7bb-41c8-9289-a214b1415386",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -3660,
        1240
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "aee33258-cf30-4cb4-ab58-7bef7ba27b65",
      "name": "是空数组吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1740,
        400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2cd1b233-fb24-45d5-9efd-1db44b817809",
              "operator": {
                "type": "array",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $input.all().flatMap(item => item.json.data).compact() }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b367a25f-e679-4a71-910e-27f1aa686816",
      "name": "删除键",
      "type": "n8n-nodes-base.redis",
      "position": [
        -1520,
        300
      ],
      "parameters": {
        "key": "mcp_n8n_tools",
        "operation": "delete"
      },
      "credentials": {
        "redis": {
          "id": "zU4DA70qSDrZM1El",
          "name": "Redis account (localhost)"
        }
      },
      "executeOnce": true,
      "typeVersion": 1
    },
    {
      "id": "eec527e1-db4d-4294-a076-379ebd9640a9",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3920,
        860
      ],
      "parameters": {
        "color": 7,
        "width": 740,
        "height": 560,
        "content": "## 4. 将任何代理与MCP客户端连接"
      },
      "typeVersion": 1
    },
    {
      "id": "c9b51f36-f9bd-4a60-b195-8da229462331",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2880,
        820
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 400,
        "content": "* **添加工作流**"
      },
      "typeVersion": 1
    },
    {
      "id": "91b2859a-7563-4ebd-ae61-c9a487e18d81",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4600,
        -180
      ],
      "parameters": {
        "width": 600,
        "height": 1440,
        "content": "## 试试看!"
      },
      "typeVersion": 1
    },
    {
      "id": "ec3194d2-90c8-4019-a1b5-576c61e9a8b0",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2600,
        -280
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 120,
        "content": "### 我可以使用多少现有工作流?"
      },
      "typeVersion": 1
    },
    {
      "id": "5f587241-5604-4724-bc01-3c9bc3f7bdc2",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1720,
        1000
      ],
      "parameters": {
        "height": 440,
        "content": "### 🚨 确保此节点不设置输入模式!"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Split Out": {
      "main": [
        [
          {
            "node": "Filter Matching IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Key": {
      "main": [
        [
          {
            "node": "Remove Tool Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Memory": {
      "main": [
        [
          {
            "node": "Operations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MCP Client": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Operations": {
      "main": [
        [
          {
            "node": "Get MCP-tagged Workflows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Convert to JSON",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "listTools Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get MCP-tagged Workflows1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Convert to JSON1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Workflow": {
      "ai_tool": [
        [
          {
            "node": "N8N Workflows MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Get Parameters": {
      "main": [
        [
          {
            "node": "Execute Workflow with PassThrough Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Workflows": {
      "ai_tool": [
        [
          {
            "node": "N8N Workflows MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "RemoveWorkflow": {
      "ai_tool": [
        [
          {
            "node": "N8N Workflows MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Convert to JSON": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ExecuteWorkflow": {
      "ai_tool": [
        [
          {
            "node": "N8N Workflows MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Is Empty Array?": {
      "main": [
        [
          {
            "node": "Delete Key",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Store In Memory1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SearchWorkflows": {
      "ai_tool": [
        [
          {
            "node": "N8N Workflows MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Store In Memory": {
      "main": [
        [
          {
            "node": "AddTool Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to JSON1": {
      "main": [
        [
          {
            "node": "Has Workflow Available?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store In Memory1": {
      "main": [
        [
          {
            "node": "Remove Tool Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Exists?": {
      "main": [
        [
          {
            "node": "Simplify Workflows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AddTool Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simplify Workflows": {
      "main": [
        [
          {
            "node": "Store In Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Matching IDs": {
      "main": [
        [
          {
            "node": "Is Empty Array?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Matching Ids": {
      "main": [
        [
          {
            "node": "Workflow Exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simplify Workflows1": {
      "main": [
        [
          {
            "node": "listTools Success1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Workflow Available?": {
      "main": [
        [
          {
            "node": "Get Parameters",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ExecuteTool Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get MCP-tagged Workflows": {
      "main": [
        [
          {
            "node": "Filter Matching Ids",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get MCP-tagged Workflows1": {
      "main": [
        [
          {
            "node": "Simplify Workflows1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Get Memory",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow with PassThrough Variables": {
      "main": [
        [
          {
            "node": "executeTool Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 其他, 人工智能, IT 运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量46
分类3
节点类型18
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Jimleuk

Jimleuk

@jimleuk

Freelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at hello@jimle.uk LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk

外部链接
在 n8n.io 查看

分享此工作流