MCP 服务器触发节点(MCP Server Trigger node)#
使用 MCP 服务器触发节点,使 n8n 能够作为 模型上下文协议 (MCP) 服务器运行,从而让 MCP 客户端可以使用 n8n 工具和工作流。
🌐 Use the MCP Server Trigger node to allow n8n to act as a Model Context Protocol (MCP) server, making n8n tools and workflows available to MCP clients.
凭证
你可以在这里找到该节点的认证信息。
MCP 服务器触发节点的工作原理(How the MCP Server Trigger node works)#
MCP 服务器触发节点作为 MCP 客户端进入 n8n 的入口。它的工作方式是通过提供一个 URL,让 MCP 客户端可以与之交互以访问 n8n 工具。
🌐 The MCP Server Trigger node acts as an entry point into n8n for MCP clients. It operates by exposing a URL that MCP clients can interact with to access n8n tools.
与传统的触发节点不同,传统节点会响应事件并将其输出传递给下一个连接节点,MCP服务器触发节点仅连接并执行工具节点。客户端可以列出可用的工具,并调用单个工具来执行任务。
🌐 Unlike conventional trigger nodes, which respond to events and pass their output to the next connected node, the MCP Server Trigger node only connects to and executes tool nodes. Clients can list the available tools and call individual tools to perform work.
你可以通过将 n8n 工作流与 自定义 n8n 工作流工具 节点关联来向客户公开它们。
🌐 You can expose n8n workflows to clients by attaching them with the Custom n8n Workflow Tool node.
服务器发送事件(SSE)和可流式 HTTP 支持
MCP 服务器触发节点支持基于 HTTP 构建的长连接传输的服务器发送事件 (SSE)以及客户端与服务器之间的可流式 HTTP 连接。目前它不支持标准输入/输出 (stdio) 传输。
节点参数(Node parameters)#
使用这些参数来配置你的节点。
🌐 Use these parameters to configure your node.
MCP 网址(MCP URL)#
MCP 服务器触发节点有两个 MCP URL:测试和生产。n8n 会在节点面板顶部显示这些 URL。
🌐 The MCP Server Trigger node has two MCP URLs: test and production. n8n displays the URLs at the top of the node panel.
选择 测试 URL 或 生产 URL 来切换 n8n 显示的 URL。
🌐 Select Test URL or Production URL to toggle which URL n8n displays.
- 测试:当你选择 监听测试事件 或 执行工作流 时,如果工作流未激活,n8n 会注册一个测试 MCP URL。当你调用该 MCP URL 时,n8n 会在工作流中显示数据。
- 生产环境:当你发布工作流时,n8n 会注册一个生产 MCP URL。使用生产 URL 时,n8n 不会在工作流中显示数据。你仍然可以查看生产执行的工作流数据:在工作流中选择 执行 标签,然后选择你想查看的工作流执行。
验证(Authentication)#
您可以要求连接到您的 MCP URL 的客户端进行身份验证。可以从以下身份验证方法中进行选择:
🌐 You can require authentication for clients connecting to your MCP URL. Choose from these authentication methods:
- Bearer 身份验证
- 标头身份验证
有关设置每种凭据类型的更多信息,请参阅HTTP 请求凭据。
🌐 Refer to the HTTP request credentials for more information on setting up each credential type.
路径(Path)#
默认情况下,此字段包含一个随机生成的 MCP URL 路径,以避免与其他 MCP 服务器触发器节点冲突。
🌐 By default, this field contains a randomly generated MCP URL path, to avoid conflicts with other MCP Server Trigger nodes.
你可以手动指定 URL 路径,包括添加路由参数。例如,如果你使用 n8n 来原型化一个 API 并希望端点 URL 保持一致,可能需要这样做。
🌐 You can manually specify a URL path, including adding route parameters. For example, you may need to do this if you use n8n to prototype an API and want consistent endpoint URLs.
模板和示例(Templates and examples)#
与 Claude Desktop 集成(Integrating with Claude Desktop)#
你可以通过运行网关将 SSE 消息代理到基于 stdio 的服务器,从 Claude Desktop 连接到 MCP 服务器触发节点。
🌐 You can connect to the MCP Server Trigger node from Claude Desktop by running a gateway to proxy SSE messages to stdio-based servers.
为此,请将以下内容添加到你的 Claude Desktop 配置中:
🌐 To do so, add the following to your Claude Desktop configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
请确保将 <MCP_URL> 和 <MCP_BEARER_TOKEN> 占位符替换为来自你的 MCP 服务器触发器节点参数和凭据的值。
🌐 Be sure to replace the <MCP_URL> and <MCP_BEARER_TOKEN> placeholders with the values from your MCP Server Trigger node parameters and credentials.
局限性(Limitations)#
正在配置带有 webhook 副本的 MCP 服务器触发节点(Configuring the MCP Server Trigger node with webhook replicas)#
MCP 服务器触发节点依赖于服务器发送事件 (SSE) 或可流式 HTTP,这要求同一个服务器实例处理持久连接。根据你的 webhook 处理器 配置,在 队列模式 下运行 n8n 时可能会出现问题:
🌐 The MCP Server Trigger node relies on Server-Sent Events (SSE) or streamable HTTP, which require the same server instance to handle persistent connections. This can cause problems when running n8n in queue mode depending on your webhook processor configuration:
- 如果你在 单个 webhook 副本 下使用队列模式,MCP 服务器触发节点将按预期工作。
- 如果你运行多个 webhook 副本,你需要将所有
/mcp*请求路由到单个专用的 webhook 副本。为 MCP 请求创建一个仅包含一个 webhook 容器的单独副本集。之后,更新你的入口或负载均衡器配置,将所有/mcp*流量引导到该实例。
在运行多个 webhook 副本时请注意
如果你在运行 MCP 服务器触发节点时使用了多个 webhook 副本,并且没有将所有 /mcp* 请求路由到单个专用的 webhook 副本,你的 SSE 和可流式 HTTP 连接将经常中断或无法可靠地传送事件。
相关资源(Related resources)#
n8n 还提供了一个 MCP 客户端工具 节点,允许您将 n8n AI 代理连接到外部工具。
🌐 n8n also provides an MCP Client Tool node that allows you to connect your n8n AI agents to external tools.
有关协议、服务器和客户端的更多详细信息,请参阅 MCP 文档 和 MCP 规范。
🌐 Refer to the MCP documentation and MCP specification for more details about the protocol, servers, and clients.
常见问题(Common issues)#
以下是一些与 MCP 服务器触发器节点相关的常见错误和问题,以及解决或故障排除步骤。
🌐 Here are some common errors and issues with the MCP Server Trigger node and steps to resolve or troubleshoot them.
运行带反向代理的 MCP 服务器触发器节点(Running the MCP Server Trigger node with a reverse proxy)#
当 n8n 运行在 nginx 等反向代理之后时,如果 MCP 端点未配置为 SSE 或可流式 HTTP,则可能会遇到问题。
🌐 When running n8n behind a reverse proxy like nginx, you may experience problems if the MCP endpoint isn't configured for SSE or streamable HTTP.
具体来说,你需要为该端点禁用代理缓冲。你可能还需要调整的其他项目包括禁用 gzip 压缩(n8n 自行处理此项)、禁用分块传输编码,以及将 Connection 设置为空字符串以从转发的头信息中移除它。在 MCP 端点中显式禁用这些设置可以确保它们不会从 nginx 配置的其他地方继承。
🌐 Specifically, you need to disable proxy buffering for the endpoint. Other items you might want to adjust include disabling gzip compression (n8n handles this itself), disabling chunked transfer encoding, and setting the Connection to an empty string to remove it from the forwarded headers. Explicitly disabling these in the MCP endpoint ensures they're not inherited from other places in your nginx configuration.
使用这些设置处理 MCP 流量的 nginx location 块示例可能如下所示:
🌐 An example nginx location block for serving MCP traffic with these settings may look like this:
1 2 3 4 5 6 7 8 9 10 11 | |