Skip to main content
Glama
Aaryan-Kapoor

MCP Character Tools

batch_count

Count occurrences of a specific letter across multiple words simultaneously. Analyze word lists to identify letter frequency with case-sensitive options and get sorted results.

Instructions

Count a letter across multiple words at once.

Efficiently process a list of words.

Args:

  • words (string[]): Array of words to analyze

  • letter (string): The letter to count

  • case_sensitive (boolean): Match case exactly (default: false)

Returns: Results for each word, totals, sorted by count.

Example: batch_count(["strawberry", "raspberry", "blueberry"], "r") → individual and total counts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
wordsYesWords to analyze
letterYesThe letter to count
case_sensitiveNoMatch case exactly

Implementation Reference

  • Core implementation of batchCount function: processes array of words, counts specified letter in each using countLetter helper, computes totals, stats, and sorted results.
    export function batchCount(input: BatchCountInput): BatchCountOutput {
      const { words, letter, case_sensitive } = input;
      
      const results: BatchWordResult[] = words.map(word => {
        const result = countLetter({ text: word, letter, case_sensitive });
        return {
          word,
          count: result.count,
          positions: result.positions,
        };
      });
    
      const total_count = results.reduce((sum, r) => sum + r.count, 0);
      const words_with_letter = results.filter(r => r.count > 0).length;
      const words_without_letter = results.filter(r => r.count === 0).length;
      
      const sorted_by_count = [...results].sort((a, b) => b.count - a.count);
      
      const summary = `Analyzed ${words.length} word${words.length === 1 ? '' : 's'}: found ${total_count} total '${letter}'${total_count === 1 ? '' : 's'}. ${words_with_letter} word${words_with_letter === 1 ? '' : 's'} contain the letter, ${words_without_letter} do not.`;
    
      return {
        letter,
        case_sensitive,
        results,
        total_count,
        words_with_letter,
        words_without_letter,
        summary,
        sorted_by_count,
      };
    }
  • TypeScript interfaces defining input (BatchCountInput), per-word result (BatchWordResult), and output (BatchCountOutput) schemas for batch_count tool.
    export interface BatchCountInput {
      words: string[];
      letter: string;
      case_sensitive: boolean;
    }
    
    export interface BatchWordResult {
      word: string;
      count: number;
      positions: number[];
    }
    
    export interface BatchCountOutput {
      letter: string;
      case_sensitive: boolean;
      results: BatchWordResult[];
      total_count: number;
      words_with_letter: number;
      words_without_letter: number;
      summary: string;
      sorted_by_count: BatchWordResult[];
    }
  • src/index.ts:447-483 (registration)
    MCP server registration of 'batch_count' tool: defines Zod inputSchema, description, and async handler wrapper that calls batchCount and formats response.
    server.registerTool(
      "batch_count",
      {
        title: "Batch Count",
        description: `Count a letter across multiple words at once.
    
    Efficiently process a list of words.
    
    Args:
      - words (string[]): Array of words to analyze
      - letter (string): The letter to count
      - case_sensitive (boolean): Match case exactly (default: false)
    
    Returns: Results for each word, totals, sorted by count.
    
    Example: batch_count(["strawberry", "raspberry", "blueberry"], "r") → individual and total counts`,
        inputSchema: z.object({
          words: z.array(z.string().min(1)).min(1).describe("Words to analyze"),
          letter: z.string().length(1).describe("The letter to count"),
          case_sensitive: z.boolean().default(false).describe("Match case exactly"),
        }).strict(),
        annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
      },
      async (params) => {
        const result = batchCount({
          words: params.words,
          letter: params.letter,
          case_sensitive: params.case_sensitive,
        });
        const breakdown = result.results
          .map(r => `"${r.word}": ${r.count} at [${r.positions.join(', ')}]`)
          .join('\n');
        return {
          content: [{ type: "text" as const, text: `${result.summary}\n\n${breakdown}` }],
        };
      }
    );

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/Aaryan-Kapoor/mcp-character-tools'

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