count_clipboard_chars
Measure the character count of text excluding spaces and line breaks. Use this tool to analyze Japanese or English text for precise character counts, ensuring accurate text processing.
Instructions
テキストの文字数を計測します。スペースや改行を除いた実質的な文字数をカウントします。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | 文字数をカウントするテキスト |
Implementation Reference
- src/index.ts:180-201 (handler)The private method countTextCharsImpl that contains the core logic for counting characters in the provided text, excluding whitespace and newlines. This is invoked by the count_clipboard_chars tool handler.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 }; } }
- src/index.ts:521-527 (registration)Registration of the 'count_clipboard_chars' tool using this.server.tool(), including the inline schema with zod and the handler function that delegates to countTextCharsImpl.this.server.tool( 'count_clipboard_chars', 'テキストの文字数を計測します。スペースや改行を除いた実質的な文字数をカウントします。', { text: z.string().describe('文字数をカウントするテキスト') }, async ({ text }) => this.countTextCharsImpl(text) );