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.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>"
},
"name": "word_count"
}
}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; }