Skip to main content
Glama

detox_generate_matcher

Generate Detox matcher code for selecting mobile app elements by ID, text, label, type, or traits in React Native E2E testing.

Instructions

Generate Detox matcher code for element selection (by.id, by.text, etc.).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementDescriptionYesDescription of the element to match
matcherTypeNo
withAncestorNoAncestor matcher
withDescendantNoDescendant matcher
atIndexNoIndex for multiple matches

Implementation Reference

  • The handler function that executes the detox_generate_matcher tool: parses input args, calls generateMatcherCode helper, and returns the generated code.
    handler: async (args: z.infer<typeof GenerateMatcherArgsSchema>) => {
      const parsed = GenerateMatcherArgsSchema.parse(args);
    
      const code = generateMatcherCode({
        type: parsed.matcherType || "id",
        value: parsed.elementDescription,
        withAncestor: parsed.withAncestor,
        withDescendant: parsed.withDescendant,
        atIndex: parsed.atIndex,
      });
    
      return {
        success: true,
        code,
        description: `Matcher for: ${parsed.elementDescription}`,
      };
    },
  • Zod schema defining the input parameters for the detox_generate_matcher tool.
    export const GenerateMatcherArgsSchema = z.object({
      elementDescription: z.string().describe("Description of the element to match"),
      matcherType: z.enum(["id", "text", "label", "type", "traits"]).optional(),
      withAncestor: z.string().optional().describe("Ancestor matcher"),
      withDescendant: z.string().optional().describe("Descendant matcher"),
      atIndex: z.number().optional().describe("Index for multiple matches"),
    });
  • Core helper function that constructs the Detox matcher code string based on type, value, and optional modifiers like ancestor, descendant, and index.
    export function generateMatcherCode(options: {
      type: "id" | "text" | "label" | "type" | "traits";
      value: string;
      withAncestor?: string;
      withDescendant?: string;
      atIndex?: number;
    }): string {
      let matcher: string;
    
      switch (options.type) {
        case "id":
          matcher = `by.id('${options.value}')`;
          break;
        case "text":
          matcher = `by.text('${options.value}')`;
          break;
        case "label":
          matcher = `by.label('${options.value}')`;
          break;
        case "type":
          matcher = `by.type('${options.value}')`;
          break;
        case "traits":
          matcher = `by.traits(['${options.value}'])`;
          break;
        default:
          matcher = `by.id('${options.value}')`;
      }
    
      if (options.withAncestor) {
        matcher = `${matcher}.withAncestor(by.id('${options.withAncestor}'))`;
      }
    
      if (options.withDescendant) {
        matcher = `${matcher}.withDescendant(by.id('${options.withDescendant}'))`;
      }
    
      let code = `element(${matcher})`;
    
      if (options.atIndex !== undefined) {
        code = `element(${matcher}).atIndex(${options.atIndex})`;
      }
    
      return code;
    }
  • Registration of the detox_generate_matcher tool (as generateMatcherTool) in the allTools array exported for use in the MCP server.
    export const allTools: Tool[] = [
      buildTool,
      testTool,
      initTool,
      readConfigTool,
      listConfigurationsTool,
      validateConfigTool,
      createConfigTool,
      listDevicesTool,
      generateTestTool,
      generateMatcherTool,
      generateActionTool,
      generateExpectationTool,
    ];
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'generate' code, implying a creation operation, but doesn't specify whether this writes to files, outputs to console, requires specific permissions, or has side effects like modifying configurations. For a code generation tool with zero annotation coverage, this leaves significant gaps in understanding its behavior and impact.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core purpose. It avoids unnecessary words and gets straight to the point, making it easy to parse. However, it could be slightly more structured by explicitly mentioning the tool's role in the Detox testing workflow.

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?

Given the complexity of a code generation tool with 5 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the generated output looks like (e.g., code snippet format), how it integrates with other Detox tools, or any behavioral constraints. This leaves the agent with insufficient context to use the tool effectively beyond basic parameter passing.

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 80%, so the schema already documents most parameters well. The description adds minimal value beyond the schema by hinting at 'element selection (by.id, by.text, etc.)', which loosely relates to the matcherType enum but doesn't elaborate on parameter interactions or usage examples. With high schema coverage, the baseline is 3, and the description doesn't significantly enhance parameter understanding.

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

Purpose4/5

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

The description clearly states the verb 'generate' and the resource 'Detox matcher code for element selection', specifying it's for element selection mechanisms like 'by.id, by.text, etc.'. It distinguishes from siblings like detox_generate_action or detox_generate_expectation by focusing on matcher code generation rather than actions or expectations, but doesn't explicitly contrast with detox_generate_test which might also involve code generation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, such as needing a Detox setup, or contrast with other tools like detox_generate_test for broader test generation. Usage is implied through the context of element selection, but no explicit when/when-not or alternative recommendations are given.

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/gayancliyanage/detox-mcp'

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