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

@koinunopochi/word-count

v0.1.0

Published

MCP サーバー: テキストまたはファイルの文字数をカウントするツール

Readme

@koinunopochi/word-count

テキストまたはファイルの文字数・単語数・行数をカウントする Model Context Protocol (MCP) サーバーです。

インストール

npm install -g @koinunopochi/word-count

または、npx で直接実行:

npx @koinunopochi/word-count

機能

ツール: word-count

テキストまたはファイルの文字数(サロゲートペア対応)・単語数・行数を返します。

パラメータ

  • text (string, optional): 直接カウントするテキスト
  • path (string, optional): 文字数を数える対象ファイルへの相対または絶対パス
  • encoding (string, optional): ファイル読込時の文字エンコーディング
    • デフォルト: utf8
    • 対応エンコーディング: utf8, utf16le, latin1, base64, hex, ascii, binary, ucs2 など

textpath のいずれか一つを指定する必要があります。

レスポンス

テキスト直接入力の場合:

{
  "content": [
    {
      "type": "text",
      "text": "ソース: 入力テキスト\n文字数: 100\n単語数: 20\n行数: 3"
    }
  ],
  "metadata": {
    "source": "入力テキスト",
    "characters": 100,
    "words": 20,
    "lines": 3
  }
}

ファイル入力の場合:

{
  "content": [
    {
      "type": "text",
      "text": "ソース: /path/to/file.txt\n文字数: 1234\n単語数: 200\n行数: 50"
    }
  ],
  "metadata": {
    "source": "/path/to/file.txt",
    "characters": 1234,
    "words": 200,
    "lines": 50,
    "encoding": "utf8"
  }
}

使用例

MCP クライアントからの使用

MCP 対応クライアントで以下のように設定:

{
  "mcpServers": {
    "word-count": {
      "command": "npx",
      "args": ["@koinunopochi/word-count"]
    }
  }
}

API使用例

テキスト直接入力:

{
  "tool": "word-count",
  "arguments": {
    "text": "これはサンプルテキストです。\n文字数をカウントします。"
  }
}

ファイル指定:

{
  "tool": "word-count",
  "arguments": {
    "path": "./document.txt",
    "encoding": "utf8"
  }
}

開発

# ソースからビルド
npm run build

# 開発モード(ファイル監視)
npm run dev

# クリーンビルド
npm run clean && npm run build

技術仕様

  • Node.js: 18.18 以上
  • TypeScript: 5.3 以上
  • MCP SDK: @modelcontextprotocol/sdk
  • スキーマ検証: zod

特徴

  • サロゲートペア対応の正確な文字数カウント(絵文字も1文字として正しくカウント)
  • テキスト直接入力とファイル読み込みの両方に対応
  • 文字数・単語数・行数の同時カウント
  • 複数のエンコーディングに対応
  • TypeScript による型安全性
  • エラーメッセージの日本語対応

エラーハンドリング

  • ファイルが存在しない場合: 「ファイルが見つかりませんでした」エラー
  • ファイル読み込み失敗時: 詳細なエラーメッセージを返す
  • パラメータ未指定時: text または path のいずれかを指定するよう要求
  • 無効なエンコーディング: Node.js がサポートしていないエンコーディングを指定した場合エラー

ライセンス

MIT