Skip to content

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.

Credentials

你可以在 此处 中找到此节点的身份验证信息。

¥You can find authentication information for this node here.

MCP 服务器触发节点的工作原理#

¥How the MCP Server Trigger node works

MCP 服务器触发器节点充当 MCP 客户端访问 n8n 的入口点。它通过公开一个 URL 来运行,MCP 客户端可以通过该 URL 访问 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 服务器触发器节点仅连接并执行 tool 节点。客户端可以列出可用工具并调用单个工具来执行工作。

¥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.

Server-Sent Events (SSE) and streamable HTTP support

MCP 服务器触发节点支持 服务器发送事件(SSE)(一种基于 HTTP 的长生命周期传输协议)和 可流式传输的 HTTP,用于客户端和服务器之间的连接。它目前不支持 标准输入/输出 (stdio) 传输。

¥The MCP Server Trigger node supports both Server-Sent Events (SSE), a long-lived transport built on top of HTTP, and streamable HTTP for connections between clients and the server. It currently doesn't support standard input/output (stdio) transport.

节点参数#

¥Node parameters

使用这些参数来配置你的节点。

¥Use these parameters to configure your node.

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 会在工作流中显示数据。

¥Test: n8n registers a test MCP URL when you select Listen for Test Event or Execute workflow, if the workflow isn't active. When you call the MCP URL, n8n displays the data in the workflow.

  • 生产:激活工作流时,n8n 会注册一个生产环境 MCP URL。使用生产环境 URL 时,n8n 不会在工作流中显示数据。你仍然可以查看生产环境执行的工作流数据:在工作流中选择“执行”选项卡,然后选择要查看的工作流执行。

¥Production: n8n registers a production MCP URL when you activate the workflow. When using the production URL, n8n doesn't display the data in the workflow. You can still view workflow data for a production execution: select the Executions tab in the workflow, then select the workflow execution you want to view.

验证#

¥Authentication

你可以要求连接到你的 MCP URL 的客户端进行身份验证。选择以下身份验证方法:

¥You can require authentication for clients connecting to your MCP URL. Choose from these authentication methods:

  • Bearer 身份验证

¥Bearer auth

  • 标头身份验证

¥Header auth

有关设置每种凭据类型的更多信息,请参阅 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

Template widget placeholder.

与 Claude Desktop 集成#

¥Integrating with Claude Desktop

你可以通过运行网关将 SSE 消息代理到基于标准 I/O 的服务器,从而从 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
{
  "mcpServers": {
    "n8n": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "<MCP_URL>",
        "--header",
        "Authorization: Bearer ${AUTH_TOKEN}"
      ],
      "env": {
        "AUTH_TOKEN": "<MCP_BEARER_TOKEN>"
      }
    }
  }
}

务必将 <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 服务器触发器节点将按预期工作。

¥If you use queue mode with a single webhook replica, the MCP Server Trigger node works as expected.

  • 如果你运行多个 Webhook 副本,则需要将所有 /mcp* 请求路由到单个专用 Webhook 副本。创建一个单独的副本集,其中包含一个用于 MCP 请求的 Webhook 容器。之后,请更新入口或负载均衡器配置,将所有 /mcp* 流量定向到该实例。

¥If you run multiple webhook replicas, you need to route all /mcp* requests to a single, dedicated webhook replica. Create a separate replica set with one webhook container for MCP requests. Afterward, update your ingress or load balancer configuration to direct all /mcp* traffic to that instance.

Caution when running with multiple webhook replicas

如果你运行的 MCP 服务器触发节点具有多个 Webhook 副本,并且没有将所有 /mcp* 请求路由到单个专用 Webhook 副本,则你的 SSE 和可流式 HTTP 连接将频繁中断或无法可靠地传递事件。

¥If you run an MCP Server Trigger node with multiple webhook replicas and don't route all /mcp* requests to a single, dedicated webhook replica, your SSE and streamable HTTP connections will frequently break or fail to reliably deliver events.

相关资源#

¥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
location /mcp/ {
    proxy_http_version          1.1;
    proxy_buffering             off;
    gzip                        off;
    chunked_transfer_encoding   off;

    proxy_set_header            Connection '';

    # The rest of your proxy headers and settings
    # . . .
}