Skip to main content
Glama

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
NameRequiredDescriptionDefault
textYesText 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 }) => {
  • 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 } ] }; } ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kylekanouse/Test-MCP---DEMO-MCP-Dev-1'

If you have feedback or need assistance with the MCP directory API, please join our Discord server