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
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text whose characters you want to count |
Implementation Reference
- mcp/character-counter.js:28-73 (handler)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}`, }, ], }; }
- mcp/character-counter.js:25-27 (schema)Input schema for the tool using Zod: requires a 'text' string parameter.{ text: z.string().describe("The text whose characters you want to count"), },
- mcp/character-counter.js:22-74 (registration)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}`, }, ], }; } );