Skip to main content
Glama
Nam0101

android-mcp-toolkit

Estimate text length difference

estimate-text-length-difference

Detect layout risk by comparing original and translated text lengths. Set tolerance percent (default 30%) to control flagging sensitivity.

Instructions

Compare original and translated text lengths to detect layout risk; configurable tolerancePercent (default 30%).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceTextYesOriginal text before translation
translatedTextYesTranslated text to compare against the original
tolerancePercentNoAllowed absolute percent difference between lengths before flagging risk

Implementation Reference

  • The main handler function (registerTextLengthTool) that registers and implements the 'estimate-text-length-difference' tool. It calculates source/translated text lengths, computes percent change, checks against tolerancePercent, and returns a verdict with summary.
    function registerTextLengthTool(server) {
      server.registerTool(
        'estimate-text-length-difference',
        {
          title: 'Estimate text length difference',
          description:
            'Compare original and translated text lengths to detect layout risk; configurable tolerancePercent (default 30%).',
          inputSchema: lengthDiffInputSchema
        },
        async params => {
          const sourceLength = measureLength(params.sourceText);
          const translatedLength = measureLength(params.translatedText);
          const delta = translatedLength - sourceLength;
          const percentChange = sourceLength === 0 ? null : (delta / sourceLength) * 100;
          const exceeds =
            percentChange === null ? translatedLength > 0 : Math.abs(percentChange) > params.tolerancePercent;
          const direction = delta === 0 ? 'no change' : delta > 0 ? 'longer' : 'shorter';
    
          const verdict =
            percentChange === null && translatedLength === 0
              ? '✅ Both texts are empty; no length risk.'
              : percentChange === null
                ? '⚠️ Source length is 0; percent change undefined and translated text is present.'
                : exceeds
                  ? '⚠️ Length difference exceeds tolerance (layout risk likely).'
                  : '✅ Length difference within tolerance.';
    
          const summary = [
            verdict,
            `Source length: ${sourceLength}`,
            `Translated length: ${translatedLength}`,
            percentChange === null
              ? `Change: N/A (source length is 0; direction: ${direction})`
              : `Change: ${percentChange.toFixed(2)}% (${direction})`,
            `Tolerance: ±${params.tolerancePercent}%`
          ].join('\n');
    
          return { content: [{ type: 'text', text: summary }] };
        }
      );
  • Input schema for the tool: sourceText (string), translatedText (string), and tolerancePercent (number, 1-500, default 30).
    const lengthDiffInputSchema = z.object({
      sourceText: z.string().min(1).describe('Original text before translation'),
      translatedText: z.string().min(1).describe('Translated text to compare against the original'),
      tolerancePercent: z
        .number()
        .min(1)
        .max(500)
        .default(30)
        .describe('Allowed absolute percent difference between lengths before flagging risk')
    });
  • Helper function measureLength that counts code points (via Array.from) to get string length.
    function measureLength(text) {
      return Array.from(text).length;
    }
  • Registration of the tool on the MCP server via server.registerTool('estimate-text-length-difference', ...) with title, description, inputSchema, and the async handler callback.
    server.registerTool(
      'estimate-text-length-difference',
      {
        title: 'Estimate text length difference',
        description:
          'Compare original and translated text lengths to detect layout risk; configurable tolerancePercent (default 30%).',
        inputSchema: lengthDiffInputSchema
      },
      async params => {
        const sourceLength = measureLength(params.sourceText);
        const translatedLength = measureLength(params.translatedText);
        const delta = translatedLength - sourceLength;
        const percentChange = sourceLength === 0 ? null : (delta / sourceLength) * 100;
        const exceeds =
          percentChange === null ? translatedLength > 0 : Math.abs(percentChange) > params.tolerancePercent;
        const direction = delta === 0 ? 'no change' : delta > 0 ? 'longer' : 'shorter';
    
        const verdict =
          percentChange === null && translatedLength === 0
            ? '✅ Both texts are empty; no length risk.'
            : percentChange === null
              ? '⚠️ Source length is 0; percent change undefined and translated text is present.'
              : exceeds
                ? '⚠️ Length difference exceeds tolerance (layout risk likely).'
                : '✅ Length difference within tolerance.';
    
        const summary = [
          verdict,
          `Source length: ${sourceLength}`,
          `Translated length: ${translatedLength}`,
          percentChange === null
            ? `Change: N/A (source length is 0; direction: ${direction})`
            : `Change: ${percentChange.toFixed(2)}% (${direction})`,
          `Tolerance: ±${params.tolerancePercent}%`
        ].join('\n');
    
        return { content: [{ type: 'text', text: summary }] };
      }
    );
  • src/index.js:29-29 (registration)
    Top-level registration call: registerTextLengthTool(server) wires the tool into the MCP server.
    registerTextLengthTool(server);
Behavior3/5

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

No annotations are provided, so the description must carry the burden. It discloses that it compares lengths and flags risk based on tolerance, but does not explicitly state that it is a read-only operation or describe any side effects. This is adequate but not comprehensive.

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 a single sentence that efficiently conveys the tool's purpose and key configurable parameter. No wasted words, and the most important information is front-loaded.

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

Completeness2/5

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

The description lacks information about the output format or return value, which is significant since no output schema exists. For a tool with low complexity, the description should at least hint at what is returned (e.g., a boolean, percentage, or risk flag). This gap reduces completeness.

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%, so the schema already documents all parameters well. The description adds marginal value by mentioning the default tolerancePercent, but does not provide additional semantics beyond what the schema offers. Baseline score of 3 is appropriate.

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: 'compare original and translated text lengths to detect layout risk'. It uses a specific verb ('compare') and resource ('text lengths'), and is distinct from sibling tools which are unrelated.

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 implies when to use (for layout risk detection), but does not explicitly state when not to use or list alternatives. However, given the context, usage context is clear.

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/Nam0101/android-mcp-toolkit'

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