在 n8n 中搭建 MCP 服务器:Google Calendar 与自定义函数双服务示例
导入模板 → 配置两个 MCP 服务端(Google Calendar 工具 + 自定义函数子工作流)→ 在 AI Agent 中通过 MCP Client 调用 → 使用聊天触发器交互
- 给谁
- 已在 n8n 1.88.0+ 中运行工作流、希望用 MCP 协议扩展 AI Agent 工具链的运营者
- 你会得到
- 得到一个同时暴露 Google Calendar 操作(查/增/改/删日程)和自定义函数(大小写转换、随机用户数据、获取笑话)的 MCP 服务端,AI Agent 通过 MCP Client 自动发现与调用这些工具
- 你需要
- n8n · MCP Trigger · MCP Client · Google Calendar · Sub-workflow
硬约束
前置条件:n8n 1.88.0 或更高版本;n8n 实例可被外部/内部访问以生成 MCP Production URL。需要 Google Calendar OAuth 凭证(n8n Cloud 用户可直接在 UI 中配置)。自定义函数部分无需额外凭证。导入模板后,按节点内 sticky note 说明激活工作流并复制 MCP Trigger 的 Production URL 到对应 MCP Client。
他们做了什么
作者 Solomon 在 n8n 模板库发布了一个官方模板,展示如何用 n8n 原生节点同时搭建两个 MCP Server(Google Calendar 工具集 + 自定义函数集),并通过 MCP Client 让 AI Agent 统一调用。模板包含 33 个节点,核心为:AI Agent(gpt-4o)← 两个 MCP Client ← 两个 MCP Trigger ← 各自工具集。Google Calendar 侧提供查/增/改/删四个操作;自定义函数侧通过子工作流实现大小写转换、随机用户数据生成、随机笑话获取。
效果如何
作者报告该模板在 n8n 1.88.0+ 上运行,使用 gpt-4o 可稳定处理 calendar 请求;4o-mini 在 calendar 场景下表现不佳(author_report)。模板已被查看超过 73,000 次。
值得知道
1. MCP Client 的 sseEndpoint 使用占位域名 n8n.yourdomain,必须替换为实际可访问地址,否则 Agent 无法连接工具。 2. Google Calendar 工具需要有效的 OAuth 凭证;n8n Cloud 用户配置较简单,自托管用户需按官方视频完成凭证设置。 3. 自定义函数子工作流与主工作流共用同一 workflow ID({{ $workflow.id }}),通过「When Executed by Another Workflow」触发;若复制为独立工作流需调整 workflowId。 4. 作者仅测试了 gpt-4o,4o-mini 的兼容性未充分验证。 5. 本站未实测导入运行,reproduction=not_tested;生产使用前建议先在隔离环境验证凭证与 URL 连通性。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- 导入后按各需鉴权节点绑定你自己的凭证;本附件不含原作者密钥。
需要替换的配置
- 源模板来自 n8n 公开库 #3514(约 33 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-25
步骤
导入模板并理解架构
从 n8n 模板库导入「Build an MCP server with Google Calendar and custom functions」。整体架构:左侧为 AI Agent 对话入口(Chat Trigger + AI Agent + OpenAI 4o + Simple Memory),中间为两个 MCP Client(Calendar MCP / My Functions),右侧为两个 MCP Trigger 服务端(Google Calendar MCP / My Functions Server)及其下属工具节点。
激活工作流并获取 MCP 服务端 URL
激活(Activate)当前工作流。进入两个 MCP Trigger 节点(Google Calendar MCP、My Functions Server),分别复制其 Production URL(格式通常为 https://your-n8n-domain/mcp/{path}/sse)。这些 URL 将用于下一步的 MCP Client 配置。
搭建指导 · 来源原文。MCP Trigger 节点旁的 Sticky Note;操作指引
## Activate the workflow to make the MCP Trigger work In order to make the MCP server available, you need to activate the workflow. Then copy the Production URL of the MCP Trigger and paste it in the corresponding MCP Client tool.
配置 MCP Client 端点
打开 Calendar MCP 与 My Functions 两个 MCP Client 节点,将上一步复制的对应 Production URL 粘贴到 sseEndpoint 字段。来源模板中使用占位地址 https://n8n.yourdomain/mcp/my-calendar/sse 与 https://n8n.yourdomain/mcp/my-functions/sse,需替换为你的实际域名与路径。
搭建指导 · 来源原文。MCP Client 节点旁的 Sticky Note;配置指引
## MCP Clients For every tool here you need to obtain he corresponding Production URL from the MCP Triggers on the right 👉
配置 Google Calendar 凭证与工具参数
Google Calendar MCP 服务端下挂四个 Google Calendar Tool 节点:SearchEvent(查询)、CreateEvent(创建)、UpdateEvent(更新)、DeleteEvent(删除)。每个节点需配置 Google Calendar 凭证(OAuth)。calendar 字段默认使用 [email protected],需替换为实际日历 ID。各工具的参数使用 $fromAI() 由 AI Agent 自动填充,无需手动固定。
搭建指导 · 来源原文。Google Calendar 工具区域 Sticky Note;凭证配置指引
## 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.
检查自定义函数子工作流
My Functions Server 通过 MCP Trigger 暴露三个 toolWorkflow 节点:Convert Text(大小写转换)、Generate random user data(随机用户数据)、Random Jokes(获取笑话)。这些工具实际调用同一工作流内的子工作流段:由「When Executed by Another Workflow」触发,经 Switch 节点按 function_name 路由到对应处理分支(uppercase / lowercase / random_user_data / joke)。子工作流接收 payload 参数并返回结果。无需修改即可使用。
搭建指导 · 来源原文。子工作流区域 Sticky Note;架构说明
## The My Functions MCP calls this sub-workflow every time. A subworkflow is a separate workflow that can be called by other workflows and is able to receive parameters. Learn more about sub-workflows **[here](https://docs.n8n.io/flow-logic/subworkflows/)**
配置 AI Agent 与模型
AI Agent 节点使用 OpenAI 4o(gpt-4o)作为语言模型,System Message 为:'=You are a helpful assistant.\nCurrent datetime is {{ $now.toString() }}'。Simple Memory 提供对话上下文记忆。Chat Trigger 为默认聊天入口。作者备注:4o-mini 在处理 calendar 请求时表现不佳,4o 更稳定;若使用 4o-mini 需进一步测试。
运行提示词 · 来源原文。AI Agent 节点的 systemMessage 字段
=You are a helpful assistant. Current datetime is {{ $now.toString() }}搭建指导 · 来源原文。OpenAI 4o 节点旁 Sticky Note;模型选择说明
## 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.
测试运行
【首次测试安全】发送下列示例前,请改用专用测试日历(调整 calendar 字段),或先断开 CreateEvent / UpdateEvent / DeleteEvent,确认工具调用无误后再接真实日历。通过 Chat Trigger 发送示例请求验证两端 MCP 服务。自定义函数示例:'Use your tools to convert this text to lower case: EXAMPLE TeXt'、'Generate 5 random user data'、'Please obtain 3 jokes'。Calendar 示例:'What is my schedule for next week?'、'I have a meeting with John tomorrow at 2pm. Please add it to my Calendar.'、'Cancel my meeting with John, tomorrow.'。观察 AI Agent 是否正确调用对应工具并返回结果。
运行提示词 · 来源原文。Chat Trigger 区域 Sticky Note;测试示例列表
# Try these example requests with the AI Agent ### My Functions MCP 1. Use your tools to convert this text to lower case: `EXAMPLE TeXt` 2. Use your tools to convert this text to upper case: `example TeXt` 3. Generate 5 random user data, please. 4. Please obtain 3 jokes. ### Calendar MCP 5. What is my schedule for next week? 6. I have a meeting with John tomorrow at 2pm. Please add it to my Calendar. 7. Adjust the time of my meeting with John tomorrow from 2pm to 4pm, please. 8. Cancel my meeting with John, tomorrow.
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限
这一段是提示词,页面不会在这里插入广告。
你是一个 n8n 工作流搭建助手。用户希望复现「Build an MCP server with Google Calendar and custom functions」模板。请按以下顺序协助: 1. 确认用户 n8n 版本 ≥ 1.88.0 且实例可被访问以生成 Production URL。 2. 指导导入模板并识别三大区域:AI Agent(左)、MCP Clients(中)、MCP Servers(右)。 3. 协助激活工作流,获取两个 MCP Trigger 的 Production URL,并填入对应 MCP Client 的 sseEndpoint。 4. 提醒配置 Google Calendar OAuth 凭证,替换 calendar 字段为真实日历 ID。 5. 说明自定义函数子工作流的 Switch 路由逻辑,确认无需修改。 6. 提供 8 条测试示例供用户验证。若调用失败,检查 URL 可达性、凭证有效期、模型额度。
粘贴此提示词到 AI 对话以获取分步搭建指导。需要准备:n8n 1.88.0+ 实例、Google Calendar OAuth 凭证、可访问的 n8n 域名。
来源
Build an MCP server with Google Calendar and custom functions · solomon · n8n.io · 2025-04-10
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。