Build an MCP Server with Google Calendar

工作流概述

这是一个包含23个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "5opbTWPZRN05bYdz",
  "meta": {
    "instanceId": "2ca62dfdbee183085041310c6198e97a69dbf85e4843e42c21169e2f5e3db806",
    "templateCredsSetupCompleted": true
  },
  "name": "Build an MCP Server with Google Calendar",
  "tags": [],
  "nodes": [
    {
      "id": "4be79e3f-3e83-4432-b23f-4e4e9cac171b",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -800
      ],
      "parameters": {
        "color": 2,
        "width": 2720,
        "height": 140,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "439a0233-c8ec-4ea5-8630-0f6e62c76bef",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        520,
        -780
      ],
      "parameters": {
        "color": 2,
        "width": 960,
        "height": 80,
        "content": "# Learn How to Build a MCP Server with Google Calendar"
      },
      "typeVersion": 1
    },
    {
      "id": "08996f0a-4a2d-438f-a8d7-aca78968d33f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -600
      ],
      "parameters": {
        "color": 7,
        "width": 620,
        "height": 280,
        "content": "# Introduce

This tutorial focuses on guiding users through the process of deploying MCP service with Google Calendar. By following this step - by - step guide, you'll be able to leverage the powerful features of MCP Server with Google Calendar, such as creating, reading, updating, and deleting events."
      },
      "typeVersion": 1
    },
    {
      "id": "0f866ad6-d1af-4732-be64-8c97af7e55ac",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -240
      ],
      "parameters": {
        "color": 6,
        "width": 620,
        "height": 760,
        "content": "# Author
![SunGuannan](https://avatars.githubusercontent.com/u/176571840?v=4)
### SunGuannan
Freelance consultant from China, specializing in automations and data analysis. I work with select clients, addressing their toughest projects.

For business inquiries, email me at sguann2023@gmail.com.
"
      },
      "typeVersion": 1
    },
    {
      "id": "4e2cdec7-8d04-40a7-9270-0f408ebf2efb",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -600
      ],
      "parameters": {
        "color": 5,
        "width": 620,
        "content": "## Step1: Google Calendar tools require credentials
If you don't have your Google Credentials set up in n8n yet, watch [this](https://www.youtube.com/watch?v=3Ai1EPznlAc) video to learn how to do it.

If you are using n8n Cloud plans, it's very intuitive to setup and you may not even need the tutorial."
      },
      "typeVersion": 1
    },
    {
      "id": "0a3941f5-959f-499c-b5a6-b2b66b203b1e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -420
      ],
      "parameters": {
        "color": 5,
        "width": 620,
        "height": 220,
        "content": "## Step 2: Create MCP Server Trigger and activate
Log in to n8n and create a new workflow. On the new workflow page, click “Add First Step” to open a searchable menu of nodes and triggers. 

Type “MCP Server Trigger” in the search bar and select it from the results to start your workflow. 

This sets up how n8n receives events from the MCP Server, laying the groundwork for integrating Google Calendar into your automation. "
      },
      "typeVersion": 1
    },
    {
      "id": "42800020-7ed3-4419-9847-d2a751aa3071",
      "name": "SearchEvent",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        400,
        260
      ],
      "parameters": {
        "limit": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Limit', ``, 'number') }}",
        "options": {},
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Before', ``, 'string') }}",
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('After', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "sguann2023@gmail.com",
          "cachedResultName": "sguann2023@gmail.com"
        },
        "operation": "getAll"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "Wi0S7gZu9R8zFjTC",
          "name": "Google Calendar account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "5d2bce57-f77d-4fd1-9342-d81107a6009d",
      "name": "CreateEvent",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        520,
        260
      ],
      "parameters": {
        "end": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End', ``, 'string') }}",
        "start": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "sguann2023@gmail.com",
          "cachedResultName": "sguann2023@gmail.com"
        },
        "additionalFields": {
          "summary": "={{ $fromAI(\"event_title\", \"The event title\", \"string\") }}",
          "description": "={{ $fromAI(\"event_description\", \"The event description\", \"string\") }}"
        }
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "Wi0S7gZu9R8zFjTC",
          "name": "Google Calendar account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "dbebec9c-fecc-4154-ba77-cfbb519ba40a",
      "name": "UpdateEvent",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        640,
        260
      ],
      "parameters": {
        "eventId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Event_ID', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "sguann2023@gmail.com",
          "cachedResultName": "sguann2023@gmail.com"
        },
        "operation": "update",
        "updateFields": {
          "end": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End', ``, 'string') }}",
          "start": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start', ``, 'string') }}",
          "summary": "={{ $fromAI(\"event_title\", \"The event title\", \"string\") }}",
          "description": "={{ $fromAI(\"event_description\", \"The event description\", \"string\") }}"
        }
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "Wi0S7gZu9R8zFjTC",
          "name": "Google Calendar account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "24ef1fd5-29dc-4208-a33b-5337307d01e0",
      "name": "DeleteEvent",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        760,
        260
      ],
      "parameters": {
        "eventId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Event_ID', ``, 'string') }}",
        "options": {},
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "sguann2023@gmail.com",
          "cachedResultName": "sguann2023@gmail.com"
        },
        "operation": "delete"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "Wi0S7gZu9R8zFjTC",
          "name": "Google Calendar account"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ec4aa55d-c6ee-4990-9c51-6ee1892600dd",
      "name": "Google Calendar MCP",
      "type": "@n8n/n8n-nodes-langchain.mcpTrigger",
      "position": [
        400,
        60
      ],
      "webhookId": "f9d9d5ea-6f83-42c8-ae50-ee6c71789bca",
      "parameters": {
        "path": "my-calendar"
      },
      "typeVersion": 1
    },
    {
      "id": "7e49bc5e-c3c1-47b3-8a0a-8f3b91ad954b",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -180
      ],
      "parameters": {
        "color": 5,
        "width": 620,
        "height": 600,
        "content": "## Step 3: Incorporate Google Calendar Tools
After creating the MCP Server Trigger, rename it to \"Google Calendar MCP \" for clarity. 

Click \"Tools\" and type \"Google Calendar\" in the search bar to find tools for various Google Calendar operations. 

You can add multiple tools, each for a specific task. For example, \"Get Many\" retrieves multiple events, \"Create\" makes new ones, \"Update\" modifies existing events, and \"Delete\" removes them. Use these tools to build customized, efficient workflows for your Google Calendar data. "
      },
      "typeVersion": 1
    },
    {
      "id": "6a86eb61-0e1f-4de1-a77f-0470fe1cd3ec",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        440
      ],
      "parameters": {
        "color": 5,
        "width": 620,
        "height": 580,
        "content": "## Step 4: Copy Your MCP Server Trigger URL and Activate Your Workflow
Double - click on the \"Google Calendar MCP\" node. On the node detail page, you'll locate the production URL, which might look something like \"https://xxx/mcp/my - calendar/sse\". Make sure to copy this URL as it will be used later in your workflow setup.

After obtaining the URL, save the workflow. Then, check the \"Inactive\" button to activate the trigger. 
![Inactive](https://1.gravatar.com/userimage/264834967/9a4d54537ef20427192f47fd8e413814?size=256)
![Active](https://1.gravatar.com/userimage/264834967/01bf3678cce04b3428586c908beb9954?size=256)
Once activated, your workflow will start listening for events from the MCP Server, enabling seamless integration with the Google Calendar service."
      },
      "typeVersion": 1
    },
    {
      "id": "aed25c42-78e1-4984-8831-768e2bbe6888",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        -600
      ],
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 140,
        "content": "## Step 5: Create a New Workflow for AI Agent
At this stage, you're required to create a new workflow. Once the new workflow interface is open, click on the \"Add First Step\" option. In the list of available nodes and triggers that appears, search for and select the \"on Chat Message\" option to add it to your workflow. This sets the initial trigger for your AI-Agent-related workflow."
      },
      "typeVersion": 1
    },
    {
      "id": "214dbba6-dffe-4c43-8c14-77babd52107f",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        -440
      ],
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 1060,
        "content": "## Step 6: Add AI Agent Node
After successfully creating the Chat Messages Trigger, you can proceed to add an \"AI Agent\" node right after it. Double - click on this newly added \"AI Agent\" node to open its configuration panel.

In the configuration, you'll need to add a specific option. Under the System Message field, enter the following text: \"You are a helpful assistant. Current datetime is {{ $now.toString() }}\". This message provides the AI with the current date and time, which can be useful for context in various interactions.

Next, select an appropriate Large Language Model (LLM) from the available options. This model will be responsible for handling the chat and delivering events.

To enable continuous and context - aware conversations, add memory to the Agent. This allows the AI Agent to remember previous interactions, providing a more seamless and engaging chat experience.

Finally, search for and add the \"MCP Client\" tool. In the SSE Endpoint section of the \"MCP Client\" configuration, paste the URL that you copied in Step 4. This step connects the AI Agent workflow to the MCP Server, enabling data flow and interaction between the two. "
      },
      "typeVersion": 1
    },
    {
      "id": "7ba10d96-e1cc-456d-9174-c848524466dd",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1220,
        20
      ],
      "parameters": {
        "options": {
          "systemMessage": "=You are a helpful assistant.
Current datetime is {{ $now.toString() }}"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "2d577167-74d2-4966-8c39-79477787ed68",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1020,
        20
      ],
      "webhookId": "7b02318f-1c6b-4f2a-9a4f-b17fa69ea680",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "0c5f70f5-5156-42f1-90ab-1f294f2fa2d9",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1320,
        240
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "cf747bc2-9c08-4f8f-9408-135e17ef0d3d",
      "name": "Calendar MCP",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        1440,
        240
      ],
      "parameters": {
        "sseEndpoint": "https://xxx.app.n8n.cloud/mcp/my-calendar/sse"
      },
      "typeVersion": 1
    },
    {
      "id": "8891a5de-e35f-4367-bfb7-0e54ce4452be",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1020,
        360
      ],
      "parameters": {
        "color": 7,
        "height": 240,
        "content": "## Why model 4o? 👆
After testing 4o-mini it had some difficulties handling the calendar requests, while the 4o model handled it with ease.

Depending on your prompt and tools, 4o-mini might be able to work well too, but it requires further testing."
      },
      "typeVersion": 1
    },
    {
      "id": "f5d9ddb5-5957-4d22-8d85-a1c08eb813d8",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1620,
        -600
      ],
      "parameters": {
        "color": 6,
        "width": 740,
        "height": 520,
        "content": "# Let's Try!

![create](https://0.gravatar.com/userimage/264834967/5dfab90301432c344990fafb166546e1?size=256)

![create-finish](https://0.gravatar.com/userimage/264834967/7126b569dd9868c056f9ad3a23be2a25?size=256)"
      },
      "typeVersion": 1
    },
    {
      "id": "31b467cd-1d70-4c05-ae14-9f9e455cd55c",
      "name": "gpt-4o",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1180,
        240
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "40ZaiQQN82bPTck0",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "007f0f3f-e7ca-4ea8-acba-cfde3bd8d1dd",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1620,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 740,
        "height": 80,
        "content": "# Enjoy It! 😊 😊 😊 "
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c99542aa-af94-4e26-b255-473a26e0a962",
  "connections": {
    "gpt-4o": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "CreateEvent": {
      "ai_tool": [
        [
          {
            "node": "Google Calendar MCP",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "DeleteEvent": {
      "ai_tool": [
        [
          {
            "node": "Google Calendar MCP",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "SearchEvent": {
      "ai_tool": [
        [
          {
            "node": "Google Calendar MCP",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "UpdateEvent": {
      "ai_tool": [
        [
          {
            "node": "Google Calendar MCP",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calendar MCP": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Stickynote
  • Googlecalendartool
  • @N8N/N8N Nodes Langchain.Mcptrigger
  • @N8N/N8N Nodes Langchain.Agent
  • @N8N/N8N Nodes Langchain.Chattrigger

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作