Skip to main content
Glama

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
NameRequiredDescriptionDefault
textYesText to analyze

Implementation Reference

  • 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") }

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