MCP工具链 - 工具链解决方案

MCP工具链 - 工具链解决方案

一个用于串联多个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/mcp-tool-chainer.git
cd mcp-tool-chainer
npm install
npm run build

配置

将以下内容添加到 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 为实际路径。

示例

串联浏览器和 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\"}"
    }
  ]
});

开发

npm install
node dist/index.js config.json