8
n8n 中文网amn8n.com

构建自定义Google Drive MCP服务器

高级

这是一个Building Blocks, AI领域的自动化工作流,包含 17 个节点。主要使用 Set, Switch, GoogleDrive, ExtractFromFile, GoogleDriveTool 等节点,结合人工智能技术实现智能自动化。 构建自定义Google Drive MCP服务器

前置要求
  • Google Drive API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "fb5b682b-5e30-497e-b465-c3369bb3c2e3",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        -20
      ],
      "parameters": {
        "color": 7,
        "width": 680,
        "height": 660,
        "content": "## 1. 设置 MCP 服务器触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "cfc2c7f1-a6ee-42a9-b955-e5bce012b6e1",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 100,
        "content": "### 始终验证您的服务器!"
      },
      "typeVersion": 1
    },
    {
      "id": "79586d35-0582-4da8-91da-5bc8451c2089",
      "name": "当被其他工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        800,
        360
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "operation"
            },
            {
              "name": "folderId"
            },
            {
              "name": "fileId"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "02aee033-58e8-4f33-a18d-b872840e81d8",
      "name": "Google Drive MCP Server",
      "type": "@n8n/n8n-nodes-langchain.mcpTrigger",
      "position": [
        160,
        160
      ],
      "webhookId": "a289c719-fb71-4b08-97c6-79d12645dc7e",
      "parameters": {
        "path": "a289c719-fb71-4b08-97c6-79d12645dc7e"
      },
      "typeVersion": 1
    },
    {
      "id": "e0e50653-d98a-4ad4-a2ed-e1b73332c380",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        680,
        -20
      ],
      "parameters": {
        "color": 7,
        "width": 1340,
        "height": 860,
        "content": "## 2. 通过转换和 AI 处理多种二进制格式"
      },
      "typeVersion": 1
    },
    {
      "id": "6be1ff49-5edc-42d2-87de-09d207ee7733",
      "name": "下载文件1",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1160,
        360
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.fileId }}"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain",
              "slidesToFormat": "application/pdf"
            }
          }
        },
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "yOwz41gMQclOadgu",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "91b0a549-0494-48a1-bdf3-6c2b91409d01",
      "name": "文件类型",
      "type": "n8n-nodes-base.switch",
      "position": [
        1340,
        320
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "pdf",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7b6958ce-d553-4379-a5d6-743f39b342d0",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $binary.data.mimeType }}",
                    "rightValue": "application/pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "csv",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d0816a37-ac06-49e3-8d63-17fcd061e33f",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $binary.data.mimeType }}",
                    "rightValue": "text/csv"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "image",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "589540e1-1439-41e3-ba89-b27f5e936190",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{\n[\n  'image/jpeg',\n  'image/jpg',\n  'image/png',\n  'image/gif'\n].some(mimeType => $binary.data.mimeType === mimeType)\n}}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "audio",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b8fc61a1-6057-4db3-960e-b8ddcbdd0f31",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $binary.data.mimeType }}",
                    "rightValue": "audio"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "video",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "959d65a6-372f-4978-b2d1-f28aa1e372c6",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $binary.data.mimeType }}",
                    "rightValue": "video"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "d88ed202-1121-41db-859d-b31d53d46292",
      "name": "操作",
      "type": "n8n-nodes-base.switch",
      "position": [
        980,
        360
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "ReadFile",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b03bb746-dc4e-469c-b8e6-a34c0aa8d0a6",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.operation }}",
                    "rightValue": "readFile"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "7e8791e6-24c2-441a-8efb-7f4375f2519b",
      "name": "从 PDF 提取内容",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1620,
        80
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "2b33623c-cea4-4a83-80ef-f852b9a3d126",
      "name": "从CSV提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1620,
        260
      ],
      "parameters": {
        "options": {
          "encoding": "utf-8",
          "headerRow": false,
          "relaxQuotes": true,
          "includeEmptyCells": true
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6ca2542d-225e-4a65-b5ce-3edafb11379c",
      "name": "获取 PDF 响应",
      "type": "n8n-nodes-base.set",
      "position": [
        1780,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a481cde3-b8ec-4d97-aa13-4668bd66c24d",
              "name": "response",
              "type": "string",
              "value": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3d1c4aa6-cac1-4957-ab7e-3134368e4b53",
      "name": "获取 CSV 响应",
      "type": "n8n-nodes-base.set",
      "position": [
        1780,
        260
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a481cde3-b8ec-4d97-aa13-4668bd66c24d",
              "name": "response",
              "type": "string",
              "value": "={{\n$input.all()\n  .map(item => item.json.row.map(cell => `\"${cell}\"`).join(','))\n  .join('\\n')\n}}"
            }
          ]
        }
      },
      "executeOnce": true,
      "typeVersion": 3.4
    },
    {
      "id": "141444f9-e937-41f9-ab97-09624646ddba",
      "name": "从 GDrive 读取文件",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        400,
        380
      ],
      "parameters": {
        "name": "ReadFile",
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "description": "调用此工具以下载并读取 Google Drive 中文件的内容",
        "workflowInputs": {
          "value": {
            "fileId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('fileId', ``, 'string') }}",
            "folderId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('folderId', ``, 'string') }}",
            "operation": "readFile"
          },
          "schema": [
            {
              "id": "operation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "operation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "folderId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "folderId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "fileId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "fileId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "b5851527-0b57-447b-ac8c-10408a684862",
      "name": "从 GDrive 搜索文件",
      "type": "n8n-nodes-base.googleDriveTool",
      "position": [
        240,
        380
      ],
      "parameters": {
        "limit": 10,
        "filter": {
          "driveId": {
            "mode": "list",
            "value": "My Drive"
          },
          "whatToSearch": "files"
        },
        "options": {},
        "resource": "fileFolder",
        "queryString": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Search_Query', ``, 'string') }}"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "yOwz41gMQclOadgu",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "98197c91-c7e9-4fbb-a2b1-c16c873fa0a1",
      "name": "分析图像",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1620,
        440
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "resource": "image",
        "inputType": "base64",
        "operation": "analyze"
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "b44a787a-c670-47e1-b87e-d880425ce610",
      "name": "转录音频",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1620,
        620
      ],
      "parameters": {
        "options": {},
        "resource": "audio",
        "operation": "transcribe"
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "1e1a358d-769e-48c9-bf27-6a3cfaaacb14",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -420
      ],
      "parameters": {
        "width": 440,
        "height": 1060,
        "content": "## 试试看!"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "FileType": {
      "main": [
        [
          {
            "node": "Extract from PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from CSV",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Analyse Image",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Transcribe Audio",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Operation": {
      "main": [
        [
          {
            "node": "Download File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File1": {
      "main": [
        [
          {
            "node": "FileType",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from CSV": {
      "main": [
        [
          {
            "node": "Get CSV Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from PDF": {
      "main": [
        [
          {
            "node": "Get PDF Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read File From GDrive": {
      "ai_tool": [
        [
          {
            "node": "Google Drive MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Search Files from Gdrive": {
      "ai_tool": [
        [
          {
            "node": "Google Drive MCP Server",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Operation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 构建模块, 人工智能

需要付费吗?

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

工作流信息
难度等级
高级
节点数量17
分类2
节点类型10
难度说明

适合高级用户,包含 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 查看

分享此工作流