Zh Word Counter

by yoqu

249 downloads
Not rated
GitHub

Description

# MCP Word Counter - 中文字数统计服务 一个基于 Model Context Protocol (MCP) 的中文字数统计服务,支持智能统计中文、英文、全角和半角字符。 ## 功能特性 - ✅ **智能字符识别**:准确识别中文汉字、英文字符、全角和半角字符 - ✅ **多文件支持**:同时统计多个文件的字数 - ✅ **详细统计**:提供每种字符类型的详细统计信息 - ✅ **智能计算**:按照指定规则计算字数并向上取整 - ✅ **错误处理**:友好的错误提示和异常处理 ## 字数计算规则 | 字符类型 | 计算权重 | 示例…

About

# MCP Word Counter - 中文字数统计服务 一个基于 Model Context Protocol (MCP) 的中文字数统计服务,支持智能统计中文、英文、全角和半角字符。 ## 功能特性 - ✅ **智能字符识别**:准确识别中文汉字、英文字符、全角和半角字符 - ✅ **多文件支持**:同时统计多个文件的字数 - ✅ **详细统计**:提供每种字符类型的详细统计信息 - ✅ **智能计算**:按照指定规则计算字数并向上取整 - ✅ **错误处理**:友好的错误提示和异常处理 ## 字数计算规则 | 字符类型 | 计算权重 | 示例 | |---------|---------|------| | 中文汉字 |…

Details

Author
yoqu
Downloads
249
Categories
Other

- Smart character recognition (Chinese, English, full‑half width)
- Multi‑file support with a single call
- Detailed per‑character‑type statistics
- Weighted calculation with rounding up
- Friendly error handling and prompts

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Zh Word Counter
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install via npx mcp-word-counter or npm install -g mcp-word-counter. Configure the MCP client with the correct command and no environment variables. Invoke the count_words tool with a filePaths array (e.g., { "filePaths": ["./example.txt"] }) to count words in one or more text files.

count_words

统计文件中的中文字数。支持单个或多个文件路径。计算规则:汉字=1,英文字符=0.5,全角字符=1,半角字符=0.5,结果向上取整。

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "zh word counter": {
            "word-counter": {
                "command": "npx",
                "args": [
                    "@yoqulin/mcp-word-counter@latest"
                ]
            }
        }
    }
}

McpServers

{
    "word-counter": {
        "command": "npx",
        "args": [
            "@yoqulin/mcp-word-counter@latest"
        ]
    }
}

MCP Word Counter - 中文字数统计服务

一个基于 Model Context Protocol (MCP) 的中文字数统计服务,支持智能统计中文、英文、全角和半角字符。

功能特性

- ✅ 智能字符识别:准确识别中文汉字、英文字符、全角和半角字符
- ✅ 多文件支持:同时统计多个文件的字数
- ✅ 详细统计:提供每种字符类型的详细统计信息
- ✅ 智能计算:按照指定规则计算字数并向上取整
- ✅ 错误处理:友好的错误提示和异常处理

字数计算规则

| 字符类型 | 计算权重 | 示例 |
|---------|---------|------|
| 中文汉字 | 1.0 | 中、文、汉、字 |
| 英文字符 | 0.5 | a-z, A-Z |
| 全角字符 | 1.0 | !、(、) |
| 半角字符 | 0.5 | !、(、) |

注意:最终字数会向上取整。例如:3.2 → 4,5.7 → 6

安装与配置

方法一:使用 npx(推荐)

直接使用 npx 安装和配置,无需手动下载:

npx mcp-word-counter

在你的 MCP 客户端配置文件中添加:

{
  "mcpServers": {
    "word-counter": {
      "command": "npx",
      "args": ["mcp-word-counter"],
      "env": {}
    }
  }
}

方法二:全局安装

npm install -g mcp-word-counter

配置 MCP 客户端:

{
  "mcpServers": {
    "word-counter": {
      "command": "mcp-word-counter",
      "env": {}
    }
  }
}

方法三:本地开发

1. 克隆项目并安装依赖:

git clone https://github.com/yourusername/mcp-word-counter.git
cd mcp-word-counter
npm install

2. 构建项目:

npm run build

3. 配置 MCP 客户端:

{
  "mcpServers": {
    "word-counter": {
      "command": "node",
      "args": ["path/to/mcp-word-counter/dist/index.js"],
      "env": {}
    }
  }
}

使用方法

在 MCP 客户端中使用

调用 count_words 工具:

{
  "name": "count_words",
  "arguments": {
    "filePaths": ["./example.txt", "./document.md"]
  }
}

支持的文件格式

- 纯文本文件 (.txt)
- Markdown 文件 (.md)
- JavaScript/TypeScript 文件 (.js, .ts)
- JSON 文件 (.json)
- 其他任何文本格式文件

输出示例

文件: ./example.txt
总字数: 156
详细统计:
  - 汉字: 120
  - 英文字符: 45
  - 全角字符: 8
  - 半角字符: 12
  - 其他字符: 3
  - 原始字数: 155.50

文件: ./document.md
总字数: 89
详细统计:
- 汉字: 78
- 英文字符: 20
- 全角字符: 2
- 半角字符: 5
- 其他字符: 1
- 原始字数: 88.50

总计字数: 245

开发

项目结构

mcp-word-counter/
├── src/
│   ├── index.ts          # MCP 服务器主文件
│   ├── word-counter.ts   # 字数统计核心逻辑
│   └── types.ts          # 类型定义
├── dist/                 # 编译输出目录
├── package.json
├── tsconfig.json
└── README.md

开发模式

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.