ADK 的 n8n MCP 工具¶
Supported in ADKPythonTypeScript
n8n MCP 服务器 将你的 ADK 智能体连接到 n8n,这是一个可扩展的工作流自动化工具。此集成允许你的智能体安全地连接到 n8n 实例,直接从自然语言界面搜索、检查和触发工作流。
替代方案:工作流级 MCP 服务器
本页上的配置指南涵盖了 实例级 MCP 访问,它将你的智能体连接到已启用工作流的中心枢纽。 或者,你可以使用 MCP Server Trigger 节点 使 单个工作流 充当其自己的独立 MCP 服务器。如果你想制定特定的服务器行为或公开隔离到一个工作流的工具,此方法很有用。
使用场景¶
-
执行复杂工作流:直接从你的智能体触发在 n8n 中定义的多步业务流程,利用可靠的分支逻辑、循环和错误处理来确保一致性。
-
连接到外部应用:通过 n8n 访问预构建的集成,而无需为每个服务编写自定义工具,消除了管理 API 身份验证、标头或样板代码的需要。
-
数据处理:将复杂的数据转换任务卸载到 n8n 工作流,例如将自然语言转换为 API 调用或抓取并总结网页,利用自定义 Python 或 JavaScript 节点进行精确的数据整理。
前置条件¶
- 一个活跃的 n8n 实例
- 在设置中启用了 MCP 访问
- 一个有效的 MCP 访问令牌
有关详细的设置说明,请参阅 n8n MCP 文档。
与智能体一起使用¶
from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters
N8N_INSTANCE_URL = "https://localhost:5678"
N8N_MCP_TOKEN = "YOUR_N8N_MCP_TOKEN"
root_agent = Agent(
model="gemini-2.5-pro",
name="n8n_agent",
instruction="Help users manage and execute workflows in n8n",
tools=[
McpToolset(
connection_params=StdioConnectionParams(
server_params=StdioServerParameters(
command="npx",
args=[
"-y",
"supergateway",
"--streamableHttp",
f"{N8N_INSTANCE_URL}/mcp-server/http",
"--header",
f"authorization:Bearer {N8N_MCP_TOKEN}"
]
),
timeout=300,
),
)
],
)
from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPServerParams
N8N_INSTANCE_URL = "https://localhost:5678"
N8N_MCP_TOKEN = "YOUR_N8N_MCP_TOKEN"
root_agent = Agent(
model="gemini-2.5-pro",
name="n8n_agent",
instruction="Help users manage and execute workflows in n8n",
tools=[
McpToolset(
connection_params=StreamableHTTPServerParams(
url=f"{N8N_INSTANCE_URL}/mcp-server/http",
headers={
"Authorization": f"Bearer {N8N_MCP_TOKEN}",
},
),
)
],
)
import { LlmAgent, MCPToolset } from "@google/adk";
const N8N_INSTANCE_URL = "https://localhost:5678";
const N8N_MCP_TOKEN = "YOUR_N8N_MCP_TOKEN";
const rootAgent = new LlmAgent({
model: "gemini-2.5-pro",
name: "n8n_agent",
instruction: "Help users manage and execute workflows in n8n",
tools: [
new MCPToolset({
type: "StdioConnectionParams",
serverParams: {
command: "npx",
args: [
"-y",
"supergateway",
"--streamableHttp",
`${N8N_INSTANCE_URL}/mcp-server/http`,
"--header",
`authorization:Bearer ${N8N_MCP_TOKEN}`,
],
},
}),
],
});
export { rootAgent };
import { LlmAgent, MCPToolset } from "@google/adk";
const N8N_INSTANCE_URL = "https://localhost:5678";
const N8N_MCP_TOKEN = "YOUR_N8N_MCP_TOKEN";
const rootAgent = new LlmAgent({
model: "gemini-2.5-pro",
name: "n8n_agent",
instruction: "Help users manage and execute workflows in n8n",
tools: [
new MCPToolset({
type: "StreamableHTTPConnectionParams",
url: `${N8N_INSTANCE_URL}/mcp-server/http`,
header: {
Authorization: `Bearer ${N8N_MCP_TOKEN}`,
},
}),
],
});
export { rootAgent };
可用工具¶
| 工具 | 描述 |
|---|---|
search_workflows |
搜索可用的工作流 |
execute_workflow |
执行特定工作流 |
get_workflow_details |
检索工作流的元数据和架构信息 |
配置¶
要使工作流可供你的智能体访问,它们必须满足以下标准:
-
处于活跃状态:工作流必须在 n8n 中激活。
-
支持的触发器:包含 Webhook、Schedule、Chat 或 Form 触发器节点。
-
已启用 MCP:你必须在工作流设置中切换“在 MCP 中可用”或从工作流卡片菜单中选择“启用 MCP 访问”。