关于 Mcp_tool_chainer
MCP Tool Chainer 是一个 MCP 服务,可按顺序调用其他 MCP 工具并在步骤之间传递结果。它面向需要组合多个工具调用、希望减少 LLM 往返与 token 消耗的用户,并支持使用 JsonPath 筛选输入与输出。
主要功能
- 01按顺序链式调用多个 MCP 工具
- 02使用 CHAIN_RESULT 占位符传递上一步结果
- 03通过 inputPath 与 outputPath 应用 JsonPath 提取数据
- 04从已配置的 MCP 服务自动发现工具
适用场景
- 01将网页抓取结果直接交给 XPath 工具处理,无需返回 LLM
- 02对工具输出做 JsonPath 提取后再传入下一步
- 03组合多个工具形成单次调用的数据处理流程
MCP 相关
该服务本身是 MCP 服务,通过 mcp_chain、chainable_tools 和 discover_tools 等工具对外提供链式调用能力,并连接并发现其他已配置的 MCP 服务中的工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
MCP Tool Chainer
一个 MCP(Model Context Protocol)服务,可串联调用其他 MCP 工具,通过按顺序执行工具并传递结果来减少 token 用量。 旨在解决 https://github.com/modelcontextprotocol/specification/issues/215 中的问题。
类似步骤函数的 JSON 路径:
功能
- 按顺序串联多个 MCP 工具
- 使用
CHAIN_RESULT占位符,将一个工具的结果作为另一个工具的输入 - 使用
inputPath和outputPath参数,通过 JsonPath 筛选并提取特定数据 - 自动发现已配置 MCP 服务中的工具
- 与单独调用工具相比,显著减少 token 用量
工具
此服务实现了以下 MCP 工具:
mcp_chain- 串联多个 MCP 服务chainable_tools- 发现所有 MCP 服务中的工具,以便使用 mcp_chain 工具discover_tools- 重新发现所有 MCP 服务中的工具
安装
先决条件
- Node.js(v16 或更高版本)
- npm
从 npm 安装
# Install
npm install @thirdstrandstudio/mcp-tool-chainer
# Or use with npx directly
npx -y @thirdstrandstudio/mcp-tool-chainer
从源代码安装
# Clone the repository
git clone https://github.com/thirdstrandstudio/mcp-tool-chainer.git
cd mcp-tool-chainer
# Install dependencies
npm install
# Build the package
npm run build
与 Claude Desktop、Cursor 等配合使用
确保它是最后运行的 MCP,否则必须重新运行发现。
将以下内容添加到 claude_desktop_config.json 或 mcp.json:
如果从 npm 全局安装
{
"mcpServers": {
"mcp_tool_chainer": {
"command": "npx",
"args": ["-y", "@thirdstrandstudio/mcp-tool-chainer", "`claude_desktop_config.json` or `mcp.json`"],
"env": {}
}
}
}
如果从源代码安装
{
"mcpServers": {
"mcp_tool_chainer": {
"command": "node",
"args": ["/path/to/mcp-tool-chainer/dist/index.js", "`claude_desktop_config.json` or `mcp.json`"],
"env": {}
}
}
}
将 /path/to/mcp-tool-chainer 替换为你的仓库实际路径。
示例
串联 Browser 和 XPath 工具
// Fetch a webpage and then extract specific content with XPath
const result = await callTool("mcp_chain", {
"mcpPath": [
{
"toolName": "mcp_browser_mcp_fetch_url",
"toolArgs": "{\"url\": \"https://example.com\"}"
},
{
"toolName": "mcp_xpath_xpath",
"toolArgs": "{\"xml\": CHAIN_RESULT, \"query\": \"//h1\"}"
}
]
});
使用带有 InputPath 和 OutputPath 的 JsonPath
// Fetch a webpage, extract specific content with XPath, then extract part of the result
const result = await callTool("mcp_chain", {
"mcpPath": [
{
"toolName": "mcp_fetch_fetch",
"toolArgs": "{\"url\": \"https://api.example.com/data\"}"
},
{
"toolName": "web_search",
"toolArgs": "{\"search_term\": CHAIN_RESULT}",
"inputPath": "$.results[0].title", // Extract only the first result's title from previous output
"outputPath": "$.snippets[*].text" // Extract only the text snippets from the search results
},
{
"toolName": "another_tool",
"toolArgs": "{\"content\": CHAIN_RESULT}"
}
]
});
JsonPath 支持
MCP Tool Chainer 现已支持 AWS Step Functions 风格的 InputPath 和 OutputPath 功能:
- inputPath:JsonPath 表达式,用于在将输入传递给工具之前提取特定部分
- outputPath:JsonPath 表达式,用于提取输出的特定部分并传递给下一个工具
这些功能仅在输入/输出为有效 JSON 时生效。如果 JsonPath 提取失败,则使用原始输入/输出。
JsonPath 语法参考请参阅 JsonPath 语法。
优势
- 减少 token 用量:通过串联工具,无需将大量中间结果发送回大模型
- 简化工作流:通过一次工具调用创建复杂的数据处理管道
- 提升性能:减少大模型与工具之间的往返次数,从而降低延迟
- 精确控制数据流:使用 JsonPath 表达式仅提取所需数据
开发
# Install dependencies
npm install
# Start the server
node dist/index.js config.json
# List available tools
node dist/index.js config.json discover_tools
许可证
此 MCP 服务基于 MIT 许可证授权。
由 Third Strand Studio 创建
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。