返回市场
MCP工具链器

MCP工具链器

作者:thirdstrandstudio55 星标更新:2025-08-05

项目介绍

MCP 工具链

访问 Third Strand Studio

一个MCP(模型上下文协议)服务器,可以将调用链接到其他MCP工具,通过允许顺序执行工具并传递结果来减少令牌使用量。 设计用于解决https://github.com/modelcontextprotocol/specification/issues/215

image

类似JSON路径的步骤函数:

image

特性

  • 将多个MCP工具按顺序链接在一起
  • 使用CHAIN_RESULT占位符将一个工具的结果作为另一个工具的输入
  • 使用JsonPath参数inputPathoutputPath过滤和提取特定数据
  • 自动从配置的MCP服务器中发现工具
  • 相比单独调用工具,使用最少的令牌

工具

此服务器实现了以下MCP工具:

  1. mcp_chain - 将多个MCP服务器链接在一起
  2. chainable_tools - 发现所有MCP服务器中的工具,以便可以使用mcp_chain工具
  3. discover_tools - 重新发现所有MCP服务器中的工具

安装

预备条件

  • Node.js(v16或更高版本)
  • npm

从npm安装

# 安装
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

在Claude Desktop、Cursor等上使用

确保它是最后一个运行的MCP,否则它将不得不重新进行发现。

在你的claude_desktop_config.jsonmcp.json中添加以下内容:

如果全局安装了npm

{
  "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替换为你实际的仓库路径。

image

示例

链接浏览器和XPath工具

// 获取网页,然后使用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

// 获取网页,使用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}"
    }
  ]
});

JsonPath支持

MCP工具链现在支持AWS Step Functions风格的InputPath和OutputPath功能:

  • inputPath:在传递给工具之前,使用JsonPath表达式提取输入的特定部分
  • outputPath:在传递给下一个工具之前,使用JsonPath表达式提取输出的特定部分

这些功能仅在输入/输出是有效的JSON时才起作用。如果JsonPath提取失败,则使用原始输入/输出。

有关JsonPath语法参考,请参阅JsonPath语法

优点

  • 减少令牌使用:通过链接工具,避免将大型中间结果发送回LLM
  • 简化工作流程:使用单个工具调用创建复杂的处理管道
  • 提高性能:通过最小化LLM和工具之间的往返次数来减少延迟
  • 精确的数据流控制:使用JsonPath表达式仅提取所需的数据

开发

# 安装依赖
npm install

# 启动服务器
node dist/index.js config.json

# 列出可用工具
node dist/index.js config.json discover_tools

许可证

此MCP服务器根据MIT许可证发布。


Third Strand Studio创建