word_count
Count words and characters in text strings. Optionally calculate unique word counts for text analysis.
Instructions
Count words and characters in a string. Optionally count unique words.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text to analyse | |
| unique | No | Count unique words only (default: false) |
Implementation Reference
- src/services/text-service.ts:18-29 (handler)The logic implementation of the word_count tool.
wordCount(input: WordCountInput): WordCountResult { const words = input.text.trim().split(/\s+/).filter(Boolean); const result: WordCountResult = { text: input.text, wordCount: words.length, characterCount: input.text.length, }; if (input.unique) { result.uniqueWords = new Set(words.map((w) => w.toLowerCase())).size; } return result; }