text_stats
Analyze text to calculate character, word, line, sentence, paragraph counts and reading time for content assessment.
Instructions
Analyze text and return detailed statistics: character count, word count, line count, sentence count, paragraph count, and reading time.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | The text to analyze |
Implementation Reference
- src/tools/text.ts:10-42 (handler)The handler function for the text_stats tool that calculates various text metrics and returns them as a JSON string.
async ({ input }) => { const chars = input.length; const charsNoSpaces = input.replace(/\s/g, "").length; const words = input.trim() === "" ? 0 : input.trim().split(/\s+/).length; const lines = input === "" ? 0 : input.split(/\r?\n/).length; const sentences = input.trim() === "" ? 0 : input.split(/[.!?]+/).filter((s) => s.trim().length > 0).length; const paragraphs = input.trim() === "" ? 0 : input.split(/\n\s*\n/).filter((p) => p.trim().length > 0).length; const readingTimeMinutes = Math.ceil(words / 200); const result = { characters: chars, characters_no_spaces: charsNoSpaces, words, lines, sentences, paragraphs, reading_time_minutes: readingTimeMinutes, avg_word_length: words > 0 ? +(charsNoSpaces / words).toFixed(1) : 0, }; return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2) }, ], }; } - src/tools/text.ts:6-9 (registration)Registration of the text_stats tool using the MCP server instance.
server.tool( "text_stats", "Analyze text and return detailed statistics: character count, word count, line count, sentence count, paragraph count, and reading time.", { input: z.string().describe("The text to analyze") },