Skip to main content
Glama
webreactiva-devs

MCP Character Counter

count-characters-in-text

Count total characters, letters, numbers, and symbols in any text. Analyze text length and structure for precise character-based insights.

Instructions

Count characters in a text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe text whose characters you want to count

Implementation Reference

  • The handler function that executes the tool logic: counts total characters, without spaces, letters, numbers, and symbols in the input text, logs details, and returns a formatted analysis.
      async ({ text }) => {
        server.server.sendLoggingMessage({
          level: "info",
          data: text,
        });
    
        // Total character count
        const totalCount = text.length;
    
        // Character count without spaces
        const noSpacesCount = text.replace(/\s/g, "").length;
    
        // Letter count (a-z, A-Z)
        const lettersCount = (text.match(/[a-zA-Z]/g) || []).length;
    
        // Number count
        const numbersCount = (text.match(/[0-9]/g) || []).length;
    
        // Symbol count (everything that is not a letter, number, or space)
        const symbolsCount = (text.match(/[^a-zA-Z0-9\s]/g) || []).length;
    
        server.server.sendLoggingMessage({
          level: "info",
          data: {
            totalCount,
            noSpacesCount,
            lettersCount,
            numbersCount,
            symbolsCount,
          },
        });
    
        return {
          content: [
            {
              type: "text",
              text: `Character analysis:
    - Total characters: ${totalCount}
    - Characters without spaces: ${noSpacesCount}
    - Letters: ${lettersCount}
    - Numbers: ${numbersCount}
    - Symbols: ${symbolsCount}`,
            },
          ],
        };
      }
  • Input schema for the tool using Zod: requires a 'text' string parameter.
    {
      text: z.string().describe("The text whose characters you want to count"),
    },
  • Registration of the 'count-characters-in-text' tool using server.tool, including name, description, input schema, and handler function.
    server.tool(
      "count-characters-in-text",
      "Count characters in a text",
      {
        text: z.string().describe("The text whose characters you want to count"),
      },
      async ({ text }) => {
        server.server.sendLoggingMessage({
          level: "info",
          data: text,
        });
    
        // Total character count
        const totalCount = text.length;
    
        // Character count without spaces
        const noSpacesCount = text.replace(/\s/g, "").length;
    
        // Letter count (a-z, A-Z)
        const lettersCount = (text.match(/[a-zA-Z]/g) || []).length;
    
        // Number count
        const numbersCount = (text.match(/[0-9]/g) || []).length;
    
        // Symbol count (everything that is not a letter, number, or space)
        const symbolsCount = (text.match(/[^a-zA-Z0-9\s]/g) || []).length;
    
        server.server.sendLoggingMessage({
          level: "info",
          data: {
            totalCount,
            noSpacesCount,
            lettersCount,
            numbersCount,
            symbolsCount,
          },
        });
    
        return {
          content: [
            {
              type: "text",
              text: `Character analysis:
    - Total characters: ${totalCount}
    - Characters without spaces: ${noSpacesCount}
    - Letters: ${lettersCount}
    - Numbers: ${numbersCount}
    - Symbols: ${symbolsCount}`,
            },
          ],
        };
      }
    );

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

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/webreactiva-devs/mcp-character-counter'

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