analyze-text
Extract statistics and insights from text to assess its structure and content. Input text for detailed analysis, such as word count, character frequency, and other metrics.
Instructions
Analyze text and provide statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to analyze |
Implementation Reference
- src/tools/text-processing-tools.ts:70-106 (registration)Registration of the 'analyze-text' tool using server.registerTool, including title, description, input schema, and inline handler function.server.registerTool( "analyze-text", { title: "Text Analyzer", description: "Analyze text and provide statistics", inputSchema: { text: z.string().describe("Text to analyze") } }, async ({ text }) => { const characterCount = text.length; const characterCountNoSpaces = text.replace(/\s/g, "").length; const wordCount = text.trim().split(/\s+/).filter(word => word.length > 0).length; const sentenceCount = text.split(/[.!?]+/).filter(sentence => sentence.trim().length > 0).length; const paragraphCount = text.split(/\n\s*\n/).filter(paragraph => paragraph.trim().length > 0).length; const analysis = [ `📊 Text Analysis Results:`, `Characters: ${characterCount}`, `Characters (no spaces): ${characterCountNoSpaces}`, `Words: ${wordCount}`, `Sentences: ${sentenceCount}`, `Paragraphs: ${paragraphCount}`, `Average words per sentence: ${sentenceCount > 0 ? (wordCount / sentenceCount).toFixed(2) : "0"}`, `Reading time (approx): ${Math.ceil(wordCount / 200)} minutes` ].join("\n"); return { content: [ { type: "text", text: analysis } ] }; } );
- Handler function that analyzes the input text by calculating character count, word count, sentence count, paragraph count, average words per sentence, and estimated reading time, then returns a formatted text response.async ({ text }) => { const characterCount = text.length; const characterCountNoSpaces = text.replace(/\s/g, "").length; const wordCount = text.trim().split(/\s+/).filter(word => word.length > 0).length; const sentenceCount = text.split(/[.!?]+/).filter(sentence => sentence.trim().length > 0).length; const paragraphCount = text.split(/\n\s*\n/).filter(paragraph => paragraph.trim().length > 0).length; const analysis = [ `📊 Text Analysis Results:`, `Characters: ${characterCount}`, `Characters (no spaces): ${characterCountNoSpaces}`, `Words: ${wordCount}`, `Sentences: ${sentenceCount}`, `Paragraphs: ${paragraphCount}`, `Average words per sentence: ${sentenceCount > 0 ? (wordCount / sentenceCount).toFixed(2) : "0"}`, `Reading time (approx): ${Math.ceil(wordCount / 200)} minutes` ].join("\n"); return { content: [ { type: "text", text: analysis } ] }; }
- Input schema using Zod: requires a 'text' string parameter.inputSchema: { text: z.string().describe("Text to analyze") }