MCP工具链

一种MCP(模型上下文协议)服务器,将调用链接到其他MCP工具,通过允许顺序执行工具并传递结果来减少令牌使用。 旨在解决
类似JSON路径的Step函数:
特性
- 按顺序将多个MCP工具连接在一起
- 使用以下命令将一个工具的结果作为输入传递给另一个工具
CHAIN_RESULT占位符 - 使用JsonPath过滤和提取特定数据
inputPath和outputPath参数 - 从配置的MCP服务器自动发现工具
- 与单个工具调用相比,令牌使用量最小
工具
此服务器实现了以下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与克劳德桌面、光标等一起使用
确保这是最后一个运行的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 使用存储库的实际路径。
例子
链浏览器和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\"}"
}
]
});使用JsonPath与InputPath和OutputPath
// 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工具链现在支持AWS步骤函数风格的InputPath和OutputPath功能:
- inputPath:JsonPath表达式,用于在传递给工具之前提取输入的特定部分
- 输出路径:JsonPath表达式,用于在传递给下一个工具之前提取输出的特定部分
这些功能仅在输入/输出是有效的JSON时才起作用。如果JsonPath提取失败,则使用原始输入/输出。
有关JsonPath语法参考,请参阅 JsonPath语法.
益处
- 减少令牌使用:通过将工具链接在一起,您可以避免将大型中间结果发送回LLM
- 简化的工作流程:使用单个工具调用创建复杂的数据处理管道
- 改进的性能:通过最大限度地减少LLM和工具之间的往返来减少延迟
- 精确的数据流控制:使用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许可证获得许可。
______________________________________________________________________
由...创建 第三斯特兰德工作室
