Skip to main content
Glama

key_sequence

Simulate HID keycodes with configurable delays on iOS simulators to test or automate interactions using precise key sequence inputs.

Instructions

Press key sequence using HID keycodes on iOS simulator with configurable delay

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
delayNo
keyCodesYes
simulatorUuidYes

Implementation Reference

  • Core handler logic: parses params, builds AXe 'key-sequence' command args, executes via executeAxeCommand, handles errors and returns responses.
    export async function key_sequenceLogic(
      params: KeySequenceParams,
      executor: CommandExecutor,
      axeHelpers: AxeHelpers = {
        getAxePath,
        getBundledAxeEnvironment,
        createAxeNotAvailableResponse,
      },
    ): Promise<ToolResponse> {
      const toolName = 'key_sequence';
      const { simulatorId, keyCodes, delay } = params;
      const commandArgs = ['key-sequence', '--keycodes', keyCodes.join(',')];
      if (delay !== undefined) {
        commandArgs.push('--delay', String(delay));
      }
    
      log(
        'info',
        `${LOG_PREFIX}/${toolName}: Starting key sequence [${keyCodes.join(',')}] on ${simulatorId}`,
      );
    
      try {
        await executeAxeCommand(commandArgs, simulatorId, 'key-sequence', executor, axeHelpers);
        log('info', `${LOG_PREFIX}/${toolName}: Success for ${simulatorId}`);
        return createTextResponse(`Key sequence [${keyCodes.join(',')}] executed successfully.`);
      } catch (error) {
        log('error', `${LOG_PREFIX}/${toolName}: Failed - ${error}`);
        if (error instanceof DependencyError) {
          return axeHelpers.createAxeNotAvailableResponse();
        } else if (error instanceof AxeError) {
          return createErrorResponse(
            `Failed to execute key sequence: ${error.message}`,
            error.axeOutput,
          );
        } else if (error instanceof SystemError) {
          return createErrorResponse(
            `System error executing axe: ${error.message}`,
            error.originalError?.stack,
          );
        }
        return createErrorResponse(
          `An unexpected error occurred: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Zod schema defining input parameters: simulatorId (UUID), keyCodes (array of 0-255 ints, min 1), optional delay (non-neg number).
    const keySequenceSchema = z.object({
      simulatorId: z.string().uuid('Invalid Simulator UUID format'),
      keyCodes: z.array(z.number().int().min(0).max(255)).min(1, 'At least one key code required'),
      delay: z.number().min(0, 'Delay must be non-negative').optional(),
    });
  • Tool registration as default export: name 'key_sequence', description, public schema (without simulatorId), and session-aware handler wrapping the logic.
    export default {
      name: 'key_sequence',
      description: 'Press key sequence using HID keycodes on iOS simulator with configurable delay',
      schema: publicSchemaObject.shape, // MCP SDK compatibility
      handler: createSessionAwareTool<KeySequenceParams>({
        internalSchema: keySequenceSchema as unknown as z.ZodType<KeySequenceParams>,
        logicFunction: (params: KeySequenceParams, executor: CommandExecutor) =>
          key_sequenceLogic(params, executor, {
            getAxePath,
            getBundledAxeEnvironment,
            createAxeNotAvailableResponse,
          }),
        getExecutor: getDefaultCommandExecutor,
        requirements: [{ allOf: ['simulatorId'], message: 'simulatorId is required' }],
      }),
    };
  • TypeScript type inferred from the Zod schema for type safety.
    type KeySequenceParams = z.infer<typeof keySequenceSchema>;
  • Internal helper to execute AXe commands: resolves binary, adds UDID, runs with executor, throws typed errors.
    async function executeAxeCommand(
      commandArgs: string[],
      simulatorId: string,
      commandName: string,
      executor: CommandExecutor = getDefaultCommandExecutor(),
      axeHelpers: AxeHelpers = { getAxePath, getBundledAxeEnvironment, createAxeNotAvailableResponse },
    ): Promise<void> {
      // Get the appropriate axe binary path
      const axeBinary = axeHelpers.getAxePath();
      if (!axeBinary) {
        throw new DependencyError('AXe binary not found');
      }
    
      // Add --udid parameter to all commands
      const fullArgs = [...commandArgs, '--udid', simulatorId];
    
      // Construct the full command array with the axe binary as the first element
      const fullCommand = [axeBinary, ...fullArgs];
    
      try {
        // Determine environment variables for bundled AXe
        const axeEnv = axeBinary !== 'axe' ? axeHelpers.getBundledAxeEnvironment() : undefined;
    
        const result = await executor(fullCommand, `${LOG_PREFIX}: ${commandName}`, false, axeEnv);
    
        if (!result.success) {
          throw new AxeError(
            `axe command '${commandName}' failed.`,
            commandName,
            result.error ?? result.output,
            simulatorId,
          );
        }
    
        // Check for stderr output in successful commands
        if (result.error) {
          log(
            'warn',
            `${LOG_PREFIX}: Command '${commandName}' produced stderr output but exited successfully. Output: ${result.error}`,
          );
        }
    
        // Function now returns void - the calling code creates its own response
      } catch (error) {
        if (error instanceof Error) {
          if (error instanceof AxeError) {
            throw error;
          }
    
          // Otherwise wrap it in a SystemError
          throw new SystemError(`Failed to execute axe command: ${error.message}`, error);
        }
    
        // For any other type of error
        throw new SystemError(`Failed to execute axe command: ${String(error)}`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'configurable delay' and the use of HID keycodes, but lacks critical details such as whether this is a read-only or destructive operation, error handling, performance implications, or what happens if the simulator is not ready. For a tool that likely interacts with a simulator (implying potential side effects), this is insufficient.

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 action ('Press key sequence') and includes key details (HID keycodes, iOS simulator, configurable delay). It avoids redundancy and waste, though it could be slightly more structured for clarity. Every word contributes to understanding the tool's function.

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 (simulator interaction with 3 parameters), no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It lacks information on behavioral traits, error cases, return values, and detailed parameter usage, making it inadequate for safe and effective tool invocation by an AI agent.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'configurable delay' (hinting at the 'delay' parameter) and 'HID keycodes' (hinting at 'keyCodes'), but does not explain 'simulatorUuid' or provide details on keycode ranges, delay units, or parameter interactions. This adds minimal value beyond the bare schema, failing to adequately cover the 3 parameters.

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 action ('Press key sequence') and target ('on iOS simulator'), specifying the mechanism ('using HID keycodes') and a configurable aspect ('with configurable delay'). It distinguishes from siblings like 'key_press' (single key) and 'type_text' (text input), though it doesn't explicitly mention these distinctions. The purpose is specific but could be more explicit about sibling differentiation.

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 minimal guidance on when to use this tool, mentioning the iOS simulator context but not explaining when to choose it over alternatives like 'key_press' or 'type_text'. No exclusions, prerequisites, or explicit alternatives are stated, leaving usage context implied rather than clearly defined.

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

Related 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/getsentry/XcodeBuildMCP'

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