npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tom-echo-mcp

v1.0.2

Published

一个支持多线程的 MCP Echo 服务器

Readme

Tom Echo MCP 服务器

一个支持多线程的 MCP (Model Context Protocol) Echo 服务器,用于演示基本的 MCP 工具功能和多线程处理。

功能特性

  • 提供一个 echo 工具,返回接收到的任何消息
  • 支持多线程处理,使用 worker pool 提高并发性能
  • 可配置工作线程数量
  • 基于 TypeScript 开发

安装

npm install

构建

npm run build

使用方法

方式1:使用 npx 运行(推荐)

使用默认配置(4个工作线程):

npx tom-echo-mcp

配置线程数量:

WORKER_THREADS=8 npx tom-echo-mcp

方式2:直接运行命令

如果已经通过 npm link 安装:

tom-echo-mcp

配置线程数量:

WORKER_THREADS=8 tom-echo-mcp

方式3:通过 npm 脚本

在项目目录中:

npm start

在 MCP 客户端中配置

在你的 MCP 客户端配置文件中添加(使用 npx,推荐):

{
  "mcpServers": {
    "tom-echo": {
      "command": "npx",
      "args": ["tom-echo-mcp"],
      "env": {
        "WORKER_THREADS": "8"
      }
    }
  }
}

或者直接使用命令名:

{
  "mcpServers": {
    "tom-echo": {
      "command": "tom-echo-mcp",
      "env": {
        "WORKER_THREADS": "8"
      }
    }
  }
}

API

echo 工具

回显输入的消息内容(瞬时操作)。

参数:

  • message (string, 必需): 要回显的消息内容

返回:

  • 返回与输入相同的消息内容

示例:

{
  "name": "echo",
  "arguments": {
    "message": "Hello, World!"
  }
}

返回:Hello, World!

echo_with_delay 工具

回显输入的消息,但会模拟 CPU 密集型操作(用于测试多线程性能)。

参数:

  • message (string, 必需): 要回显的消息内容
  • delay (number, 可选): 模拟处理延迟的毫秒数(默认 1000ms)

返回:

  • 返回消息及处理耗时信息

示例:

{
  "name": "echo_with_delay",
  "arguments": {
    "message": "测试消息",
    "delay": 2000
  }
}

返回:[处理耗时: 2001ms] 测试消息

技术栈

  • @modelcontextprotocol/sdk: MCP 协议实现
  • workerpool: Node.js 工作线程池管理
  • TypeScript: 类型安全的开发体验

性能测试

运行性能测试来查看多线程的优势:

npm run test:performance

测试结果示例

处理 5 个并发请求(每个耗时 1 秒):

  • 1 个线程: 5032ms(串行处理)
  • 4 个线程: 2024ms(加速 2.49x,性能提升 59.8%)
  • 8 个线程: 1034ms(加速 4.87x,性能提升 79.5%)

为什么简单的 echo 看不出差异?

对于简单的 echo 操作:

  • ✅ 操作几乎是瞬时完成(微秒级)
  • ❌ Worker 线程的序列化开销(毫秒级)可能比操作本身还大
  • 💡 结论:简单操作不需要多线程,反而会降低性能

对于复杂操作(如 echo_with_delay 模拟的场景):

  • ✅ 操作耗时长(如加密、压缩、复杂计算)
  • ✅ 多个请求可以并行处理
  • ✅ 线程开销相对操作时间可忽略不计
  • 💡 结论:多线程能显著提升并发处理能力

架构说明

本项目使用 workerpool 库实现多线程支持:

  1. 主线程运行 MCP 服务器,处理请求和响应
  2. Worker 线程池处理实际的 echo 操作
  3. 请求会自动分配到空闲的 worker 线程
  4. 支持动态配置线程数量,适应不同的负载需求

何时使用多线程?

适合使用多线程的场景:

  • CPU 密集型操作(加密、压缩、图像处理、复杂计算)
  • 需要处理大量并发请求
  • 单个操作耗时较长(> 10ms)

不适合使用多线程的场景:

  • 简单的字符串操作
  • 瞬时完成的操作(< 1ms)
  • 低并发场景

许可证

MIT