analyze-text
Analyze text to extract statistics and insights for processing needs. This tool processes input text to provide measurable data points.
Instructions
Analyze text and provide statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to analyze |
Implementation Reference
- The main handler function that performs comprehensive text analysis, calculating character counts (with and without spaces), word count, sentence count, paragraph count, average words per sentence, and estimated reading time, then formats and returns the results as a text content block.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 } ] }; } ); }
- The Zod-based input schema defining the required 'text' parameter as a string.} }, async ({ text }) => {
- src/tools/text-processing-tools.ts:72-108 (registration)Registers the "analyze-text" tool with the MCP server, providing title, description, input schema, and handler function.{ 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 } ] }; } ); }