一个MCP(模型上下文协议)服务器,可以将调用链接到其他MCP工具,通过允许顺序执行工具并传递结果来减少令牌使用量。 设计用于解决https://github.com/modelcontextprotocol/specification/issues/215
类似JSON路径的步骤函数:
CHAIN_RESULT占位符将一个工具的结果作为另一个工具的输入inputPath和outputPath过滤和提取特定数据此服务器实现了以下MCP工具:
mcp_chain - 将多个MCP服务器链接在一起chainable_tools - 发现所有MCP服务器中的工具,以便可以使用mcp_chain工具discover_tools - 重新发现所有MCP服务器中的工具# 安装
npm install @thirdstrandstudio/mcp-tool-chainer
# 或直接使用npx
npx -y @thirdstrandstudio/mcp-tool-chainer
# 克隆仓库
git clone https://github.com/thirdstrandstudio/mMCP-tool-chainer.git
cd mcp-tool-chainer
# 安装依赖
npm install
# 构建包
npm run build
确保它是最后一个运行的MCP,否则它将不得不重新进行发现。
在你的claude_desktop_config.json或mcp.json中添加以下内容:
{
"mcpServers": {
"mcp_tool_chainer": {
"command": "npx",
"args": ["-y", "@thirdstrandstudio/mcp-tool-chainer", "`claude_desktop_config.json`或`mcp.json`"],
"env": {}
}
}
}
{
"mcpServers": {
"mcp_tool_chainer": {
"command": "node",
"args": ["/path/to/mcp-tool-chainer/dist/index.js", "`claude_desktop_config.json`或`mcp.json`"],
"env": {}
}
}
}
将/path/to/mcp-tool-chainer替换为你实际的仓库路径。
// 获取网页,然后使用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\"}"
}
]
});
// 获取网页,使用XPath提取特定内容,然后从结果中提取部分内容
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", // 仅从先前输出中提取第一个结果的标题
"outputPath": "$.snippets[*].text" // 仅从搜索结果中提取文本片段
},
{
"toolName": "another_tool",
"toolArgs": "{\"content\": CHAIN_RESULT}"
}
]
});
MCP工具链现在支持AWS Step Functions风格的InputPath和OutputPath功能:
这些功能仅在输入/输出是有效的JSON时才起作用。如果JsonPath提取失败,则使用原始输入/输出。
有关JsonPath语法参考,请参阅JsonPath语法。
# 安装依赖
npm install
# 启动服务器
node dist/index.js config.json
# 列出可用工具
node dist/index.js config.json discover_tools
此MCP服务器根据MIT许可证发布。