Skip to main content
Glama
Mistizz

Japanese Text Analyzer

count_chars

Counts the characters in a specified text file, excluding spaces and line breaks. Supports Windows or WSL/Linux file paths for accurate character analysis.

Instructions

ファイルの文字数を計測します。絶対パスを指定してください(Windows形式 C:\Users...、またはWSL/Linux形式 /c/Users/... のどちらも可)。スペースや改行を除いた実質的な文字数をカウントします。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes文字数をカウントするファイルのパス(Windows形式かWSL/Linux形式の絶対パスを推奨)

Implementation Reference

  • The handler function for the 'count_chars' tool. It resolves the file path, reads the file content using fs.readFileSync, and calls the countTextCharsImpl helper to compute the character count.
    async ({ filePath }) => {
      try {
        // ファイルパスを解決
        const resolvedPath = resolveFilePath(filePath);
        const fileContent = fs.readFileSync(resolvedPath, 'utf8');
        return this.countTextCharsImpl(fileContent, `ファイル '${resolvedPath}'`);
      } catch (error: any) {
        return {
          content: [{ 
            type: 'text' as const, 
            text: `ファイル読み込みエラー: ${error.message}`
          }],
          isError: true
        };
      }
    }
  • Zod input schema defining the 'filePath' parameter for the tool.
    { 
      filePath: z.string().describe('文字数をカウントするファイルのパス(Windows形式かWSL/Linux形式の絶対パスを推奨)')
    },
  • src/index.ts:470-492 (registration)
    Registration of the 'count_chars' tool on the McpServer instance using the tool() method, specifying name, description, schema, and handler.
    this.server.tool(
      'count_chars', 
      'ファイルの文字数を計測します。絶対パスを指定してください(Windows形式 C:\\Users\\...、またはWSL/Linux形式 /c/Users/... のどちらも可)。スペースや改行を除いた実質的な文字数をカウントします。',
      { 
        filePath: z.string().describe('文字数をカウントするファイルのパス(Windows形式かWSL/Linux形式の絶対パスを推奨)')
      },
      async ({ filePath }) => {
        try {
          // ファイルパスを解決
          const resolvedPath = resolveFilePath(filePath);
          const fileContent = fs.readFileSync(resolvedPath, 'utf8');
          return this.countTextCharsImpl(fileContent, `ファイル '${resolvedPath}'`);
        } catch (error: any) {
          return {
            content: [{ 
              type: 'text' as const, 
              text: `ファイル読み込みエラー: ${error.message}`
            }],
            isError: true
          };
        }
      }
    );
  • Helper method that implements the core character counting logic, excluding spaces, newlines, and returns formatted text response.
    private countTextCharsImpl(text: string, sourceName: string = 'テキスト') {
      try {
        // 改行とスペースを除外した文字数
        const contentWithoutSpacesAndNewlines = text.replace(/[\s\n\r]/g, '');
        const effectiveCharCount = contentWithoutSpacesAndNewlines.length;
        
        return {
          content: [{ 
            type: 'text' as const, 
            text: `${sourceName}の文字数: ${effectiveCharCount}文字(改行・スペース除外)`
          }]
        };
      } catch (error: any) {
        return {
          content: [{ 
            type: 'text' as const, 
            text: `エラーが発生しました: ${error.message}`
          }],
          isError: true
        };
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses key behavioral traits: it requires absolute paths, accepts two OS path formats, and excludes whitespace from counts. However, it doesn't mention error handling, file size limits, encoding considerations, or what happens with non-existent files - important gaps for a file operation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three efficient sentences with zero waste. First states purpose, second specifies path requirements with examples, third clarifies counting behavior. Each sentence adds distinct, necessary information. The description is appropriately sized and front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter tool with good schema coverage but no annotations or output schema, the description is adequate but has gaps. It covers the what and how of character counting but lacks information about return values, error conditions, or performance characteristics. Given the complexity (file operations can fail in many ways), more behavioral context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% with one parameter, so baseline would be 3. The description adds meaningful context: it emphasizes the absolute path requirement, specifies acceptable formats (Windows or WSL/Linux), and explains this is for character counting. This provides practical guidance beyond the schema's basic parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('計測します' - measure/count) and resource ('ファイルの文字数' - file character count). It distinguishes from sibling tools like count_words (words vs characters), count_clipboard_chars (clipboard vs file), and analyze_file/analyze_text (analysis vs counting).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool: for counting characters in files with absolute paths. It specifies acceptable path formats (Windows or WSL/Linux) and that it counts '実質的な文字数' (substantial characters) excluding spaces and line breaks. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mistizz/mcp-JapaneseTextAnalyzer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server