Skip to main content
Glama
Aaryan-Kapoor

MCP Character Tools

Compare Texts

compare_texts
Read-onlyIdempotent

Analyze letter frequencies between two texts to identify common characters, unique elements, and calculate similarity scores for text comparison.

Instructions

Compare letter frequencies between two texts.

Useful for analyzing similarity or differences.

Args:

  • text1 (string): First text

  • text2 (string): Second text

  • case_sensitive (boolean): Distinguish case (default: false)

Returns: Common characters, unique to each, frequency comparison, similarity score.

Example: compare_texts("hello", "world") → common: ['l', 'o'], unique_to_text1: ['h', 'e'], etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
text1YesFirst text
text2YesSecond text
case_sensitiveNoDistinguish case

Implementation Reference

  • The core handler function `compareTexts` that executes the tool's logic: computes letter frequencies for both texts using `letterFrequency`, determines common/unique characters, frequency differences, Jaccard similarity score, and generates a summary.
    export function compareTexts(input: CompareTextsInput): CompareTextsOutput {
      const { text1, text2, case_sensitive } = input;
      
      const freq1 = letterFrequency({
        text: text1,
        case_sensitive,
        include_spaces: false,
        include_punctuation: false,
        letters_only: true,
      });
      
      const freq2 = letterFrequency({
        text: text2,
        case_sensitive,
        include_spaces: false,
        include_punctuation: false,
        letters_only: true,
      });
    
      const chars1 = new Set(Object.keys(freq1.frequency));
      const chars2 = new Set(Object.keys(freq2.frequency));
      
      const common_characters = [...chars1].filter(c => chars2.has(c)).sort();
      const unique_to_text1 = [...chars1].filter(c => !chars2.has(c)).sort();
      const unique_to_text2 = [...chars2].filter(c => !chars1.has(c)).sort();
      
      const allChars = new Set([...chars1, ...chars2]);
      const frequency_comparison: FrequencyComparison[] = [...allChars]
        .sort()
        .map(char => ({
          char,
          count_in_text1: freq1.frequency[char] || 0,
          count_in_text2: freq2.frequency[char] || 0,
          difference: (freq1.frequency[char] || 0) - (freq2.frequency[char] || 0),
        }));
    
      // Calculate Jaccard similarity
      const intersection = common_characters.length;
      const union = allChars.size;
      const similarity_score = union > 0 ? Math.round((intersection / union) * 100) : 0;
    
      const summary = `Text1 (${text1.length} chars) and Text2 (${text2.length} chars) share ${common_characters.length} common characters. Similarity: ${similarity_score}%.`;
    
      return {
        text1,
        text2,
        text1_length: text1.length,
        text2_length: text2.length,
        case_sensitive,
        common_characters,
        unique_to_text1,
        unique_to_text2,
        frequency_comparison,
        similarity_score,
        summary,
      };
    }
  • TypeScript interfaces defining the input (CompareTextsInput), supporting types (FrequencyComparison), and output (CompareTextsOutput) for the compare_texts tool.
    export interface CompareTextsInput {
      text1: string;
      text2: string;
      case_sensitive: boolean;
    }
    
    export interface FrequencyComparison {
      char: string;
      count_in_text1: number;
      count_in_text2: number;
      difference: number;
    }
    
    export interface CompareTextsOutput {
      text1: string;
      text2: string;
      text1_length: number;
      text2_length: number;
      case_sensitive: boolean;
      common_characters: string[];
      unique_to_text1: string[];
      unique_to_text2: string[];
      frequency_comparison: FrequencyComparison[];
      similarity_score: number;
      summary: string;
    }
  • src/index.ts:377-410 (registration)
    Registration of the "compare_texts" tool using McpServer.registerTool, including Zod inputSchema validation, description, and the async handler that calls the compareTexts function and formats the MCP response.
    server.registerTool(
      "compare_texts",
      {
        title: "Compare Texts",
        description: `Compare letter frequencies between two texts.
    
    Useful for analyzing similarity or differences.
    
    Args:
      - text1 (string): First text
      - text2 (string): Second text
      - case_sensitive (boolean): Distinguish case (default: false)
    
    Returns: Common characters, unique to each, frequency comparison, similarity score.
    
    Example: compare_texts("hello", "world") → common: ['l', 'o'], unique_to_text1: ['h', 'e'], etc.`,
        inputSchema: z.object({
          text1: z.string().min(1).describe("First text"),
          text2: z.string().min(1).describe("Second text"),
          case_sensitive: z.boolean().default(false).describe("Distinguish case"),
        }).strict(),
        annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
      },
      async (params) => {
        const result = compareTexts({
          text1: params.text1,
          text2: params.text2,
          case_sensitive: params.case_sensitive,
        });
        return {
          content: [{ type: "text" as const, text: `${result.summary}\n\nCommon: [${result.common_characters.join(', ')}]\nOnly in text1: [${result.unique_to_text1.join(', ')}]\nOnly in text2: [${result.unique_to_text2.join(', ')}]` }],
        };
      }
    );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare read-only, non-destructive, and idempotent behavior, which the description doesn't contradict. The description adds valuable context about the return format ('common characters, unique to each, frequency comparison, similarity score') and provides an example output, enhancing transparency beyond annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by usage context, parameter details, return values, and an example. Every sentence adds value without redundancy, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity, rich annotations, and 100% schema coverage, the description is mostly complete. It explains the purpose, usage, parameters, and return format. However, without an output schema, it could benefit from more detail on the similarity score calculation or output structure to fully compensate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing full parameter documentation. The description repeats parameter names and basic purposes but doesn't add significant semantic context beyond the schema, such as explaining how case_sensitivity affects comparison or edge cases. Baseline 3 is appropriate given the schema's completeness.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('compare letter frequencies') and resources ('between two texts'), distinguishing it from siblings like 'letter_frequency' (single text) or 'count_letters' (counting without comparison). It precisely defines the analysis scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context ('useful for analyzing similarity or differences'), indicating when to use this tool. However, it doesn't explicitly mention when NOT to use it or name specific alternatives among siblings like 'letter_frequency' or 'count_substring' for different text analysis needs.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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