Skip to main content
Glama
zillow
by zillow

inputText

Enter text into mobile applications for Android or iOS devices to automate data entry during testing.

Instructions

Input text to the device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText to input to the device
imeActionNoOptional IME action to perform after text input
platformYesPlatform of the device

Implementation Reference

  • Registers the 'inputText' MCP tool with its name, description, schema, and handler function in the ToolRegistry.
    ToolRegistry.registerDeviceAware(
      "inputText",
      "Input text to the device",
      inputTextSchema,
      inputTextHandler,
      false // Does not support progress notifications
    );
  • Zod schema defining the input arguments for the inputText tool: text (required), optional imeAction, and platform.
    export const inputTextSchema = z.object({
      text: z.string().describe("Text to input to the device"),
      imeAction: z.enum(["done", "next", "search", "send", "go", "previous"]).optional()
        .describe("Optional IME action to perform after text input"),
      platform: z.enum(["android", "ios"]).describe("Platform of the device")
    });
  • The main handler function for the inputText tool. It creates an InputText instance and calls its execute method with the provided text and optional IME action.
    const inputTextHandler = async (device: BootedDevice, args: InputTextArgs) => {
      const inputText = new InputText(device);
      const result = await inputText.execute(args.text, args.imeAction);
      return createJSONToolResponse({
        message: `Input text`,
        observation: result.observation,
        ...result
      });
    };
  • Core execute method of InputText class that handles text input validation, platform dispatching (Android/iOS), and wraps in observedInteraction for visual change detection.
    async execute(
      text: string,
      imeAction?: "done" | "next" | "search" | "send" | "go" | "previous"
    ): Promise<SendTextResult & { method?: "native" | "virtual" }> {
      // Validate text input
      if (text === undefined || text === null) {
        return {
          success: false,
          text: "",
          error: "No text provided"
        };
      }
    
      return this.observedInteraction(
        async () => {
          try {
            // Platform-specific text input execution
            switch (this.device.platform) {
              case "android":
                return await this.executeAndroidTextInput(text, imeAction);
              case "ios":
                return await this.executeiOSTextInput(text, imeAction);
              default:
                throw new Error(`Unsupported platform: ${this.device.platform}`);
            }
          } catch (error) {
            const errorMessage = error instanceof Error ? error.message : String(error);
    
            return {
              success: false,
              text,
              error: `Failed to send text input: ${errorMessage}`,
              method: this.device.platform === "android" ? "native" : "native"
            };
          }
        },
        {
          changeExpected: true,
          tolerancePercent: 0.00,
          timeoutMs: 5000 // Reduce timeout for faster execution
        }
      );
    }
  • InputText class providing the detailed implementation for text input on Android (handling Unicode via virtual keyboard or ASCII escaping) and iOS (using axe tool). Used by the tool handler.
    export class InputText extends BaseVisualChange {
      private virtualKeyboardManager: VirtualKeyboardManager;
    
      constructor(device: BootedDevice, adb: AdbUtils | null = null, axe: Axe | null = null) {
        super(device, adb, axe);
        this.device = device;
        this.virtualKeyboardManager = new VirtualKeyboardManager(device);
      }
    
      async execute(
        text: string,
        imeAction?: "done" | "next" | "search" | "send" | "go" | "previous"
      ): Promise<SendTextResult & { method?: "native" | "virtual" }> {
        // Validate text input
        if (text === undefined || text === null) {
          return {
            success: false,
            text: "",
            error: "No text provided"
          };
        }
    
        return this.observedInteraction(
          async () => {
            try {
              // Platform-specific text input execution
              switch (this.device.platform) {
                case "android":
                  return await this.executeAndroidTextInput(text, imeAction);
                case "ios":
                  return await this.executeiOSTextInput(text, imeAction);
                default:
                  throw new Error(`Unsupported platform: ${this.device.platform}`);
              }
            } catch (error) {
              const errorMessage = error instanceof Error ? error.message : String(error);
    
              return {
                success: false,
                text,
                error: `Failed to send text input: ${errorMessage}`,
                method: this.device.platform === "android" ? "native" : "native"
              };
            }
          },
          {
            changeExpected: true,
            tolerancePercent: 0.00,
            timeoutMs: 5000 // Reduce timeout for faster execution
          }
        );
      }
    
      /**
       * Execute Android-specific text input
       * @param text - Text to input
       * @param imeAction - Optional IME action
       * @returns Result with method information
       */
      private async executeAndroidTextInput(
        text: string,
        imeAction?: "done" | "next" | "search" | "send" | "go" | "previous"
      ): Promise<SendTextResult & { method?: "native" | "virtual" }> {
        // Determine input method
        const inputMethod = VirtualKeyboardManager.getInputMethod(text);
    
        if (inputMethod === "virtual") {
          // Automatically setup virtual keyboard for Unicode text
          const setupResult = await this.virtualKeyboardManager.setupAdbKeyboard(false);
    
          if (!setupResult.success) {
            return {
              success: false,
              text,
              error: `Failed to setup virtual keyboard for Unicode text: ${setupResult.error}`,
              method: "virtual"
            };
          }
    
          // Send text using virtual keyboard
          try {
            await this.sendUnicodeTextViaVirtualKeyboard(text);
          } catch (error) {
            return {
              success: false,
              text,
              error: `Failed to send Unicode text: ${error instanceof Error ? error.message : String(error)}`,
              method: "virtual"
            };
          }
        } else {
          // Use native input for ASCII text
          await this.sendAsciiText(text);
        }
    
        // Handle IME action if specified
        if (imeAction) {
          await this.executeImeAction(imeAction);
        }
    
        return {
          success: true,
          text,
          imeAction,
          method: inputMethod
        };
      }
    
      /**
       * Execute iOS-specific text input
       * @param text - Text to input
       * @param imeAction - Optional IME action (ignored on iOS)
       * @returns Result with method information
       */
      private async executeiOSTextInput(
        text: string,
        imeAction?: "done" | "next" | "search" | "send" | "go" | "previous"
      ): Promise<SendTextResult & { method?: "native" | "virtual" }> {
        // iOS uses idb's inputText method which handles Unicode natively
        await this.axe.inputText(text);
    
        // Note: iOS IME actions are handled differently and imeAction parameter is ignored
        // The iOS keyboard handles actions through its own UI
    
        return {
          success: true,
          text,
          imeAction: imeAction, // Preserved for API compatibility but not used on iOS
          method: "native"
        };
      }
    
      private async sendUnicodeTextViaVirtualKeyboard(text: string): Promise<void> {
        try {
          logger.info("Sending Unicode text via hybrid approach", {
            textLength: text.length,
            hasUnicode: VirtualKeyboardManager.containsUnicode(text),
            hasNewlines: text.includes("\n")
          });
    
          // Split text by newlines first, then handle each line separately
          const lines = text.split("\n");
    
          for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
            const line = lines[lineIndex];
    
            if (line.length > 0) {
              // Split line by spaces and handle each part separately
              const parts = line.split(" ");
    
              for (let i = 0; i < parts.length; i++) {
                const part = parts[i];
    
                if (part.length > 0) {
                  // Send the text part via virtual keyboard
                  await this.virtualKeyboardManager.sendUnicodeText(part);
                }
    
                // Add space using native ADB input (except for the last part)
                if (i < parts.length - 1) {
                  await this.adb.executeCommand('shell input text "%s"');
                  // Small delay to ensure proper sequencing
                  await new Promise(resolve => setTimeout(resolve, 50));
                }
              }
            }
    
            // Add newline using KEYCODE_ENTER (except for the last line)
            if (lineIndex < lines.length - 1) {
              await this.adb.executeCommand("shell input keyevent KEYCODE_ENTER");
              // Small delay to ensure proper sequencing
              await new Promise(resolve => setTimeout(resolve, 50));
            }
          }
        } catch (error) {
          throw new Error(`Failed to send Unicode text via hybrid approach: ${error instanceof Error ? error.message : String(error)}`);
        }
      }
    
      private async sendAsciiText(text: string): Promise<void> {
        try {
          logger.info("Sending ASCII text via native input", {
            textLength: text.length,
            hasNewlines: text.includes("\n")
          });
    
          // Split text by newlines first, then handle each line separately
          const lines = text.split("\n");
    
          for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
            const line = lines[lineIndex];
    
            if (line.length > 0) {
              // Escape special characters for ASCII text according to ADB shell requirements
              // Based on: https://stackoverflow.com/questions/25791423/adb-shell-input-text-does-not-take-ampersand-character
              const escapedText = line
                .replace(/\\/g, "\\\\")  // Escape backslashes first
                .replace(/"/g, '\\"')    // Escape double quotes
                .replace(/'/g, "\\'")    // Escape single quotes
                .replace(/&/g, "\\&")    // Escape ampersand
                .replace(/</g, "\\<")    // Escape less than
                .replace(/>/g, "\\>")    // Escape greater than
                .replace(/\(/g, "\\(")   // Escape left parenthesis
                .replace(/\)/g, "\\)")   // Escape right parenthesis
                .replace(/\|/g, "\\|")   // Escape pipe
                .replace(/;/g, "\\;")    // Escape semicolon
                .replace(/\$/g, "\\$")   // Escape dollar sign
                .replace(/`/g, "\\`")    // Escape backtick
                .replace(/ /g, "%s");    // Replace spaces with %s
    
              await this.adb.executeCommand(`shell input text "${escapedText}"`);
            }
    
            // Add newline using KEYCODE_ENTER (except for the last line)
            if (lineIndex < lines.length - 1) {
              await this.adb.executeCommand("shell input keyevent KEYCODE_ENTER");
              // Small delay to ensure proper sequencing
              await new Promise(resolve => setTimeout(resolve, 50));
            }
          }
        } catch (error) {
          throw new Error(`Failed to send ASCII text: ${error instanceof Error ? error.message : String(error)}`);
        }
      }
    
      private async executeImeAction(imeAction: string): Promise<void> {
        // Map IME actions to Android key codes
        const imeKeyCodeMap: { [key: string]: string } = {
          "done": "KEYCODE_ENTER",
          "next": "KEYCODE_TAB",
          "search": "KEYCODE_SEARCH",
          "send": "KEYCODE_ENTER",
          "go": "KEYCODE_ENTER",
          "previous": "KEYCODE_SHIFT_LEFT KEYCODE_TAB" // Shift+Tab for previous
        };
    
        const keyCode = imeKeyCodeMap[imeAction];
        if (keyCode) {
          // Small delay to ensure text input is processed
          await new Promise(resolve => setTimeout(resolve, 100));
    
          // Execute the key event(s)
          if (keyCode.includes(" ")) {
            // Handle multiple key combinations like Shift+Tab
            const keys = keyCode.split(" ");
            for (const key of keys) {
              await this.adb.executeCommand(`shell input keyevent ${key}`);
            }
          } else {
            await this.adb.executeCommand(`shell input keyevent ${keyCode}`);
          }
        }
      }
    }
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 states the action ('input text') but doesn't explain how it behaves—e.g., whether it simulates typing, requires device focus, has side effects like triggering UI responses, or handles errors. This leaves key behavioral traits unspecified.

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, efficient sentence with zero waste—'Input text to the device' is front-loaded and directly conveys the core purpose without unnecessary details, making it highly concise and well-structured.

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 tool's complexity (3 parameters, no output schema, no annotations), the description is incomplete. It doesn't address behavioral aspects, usage context, or output expectations, leaving gaps that hinder the agent's ability to invoke it correctly in a device interaction scenario.

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 fully documents parameters like 'text', 'imeAction', and 'platform'. The description adds no additional meaning beyond implying text input, which aligns with the schema but doesn't enhance understanding. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Input text to the device' clearly states the action (input) and target (device), but it's vague about what 'input' entails (e.g., typing, pasting) and doesn't distinguish it from sibling tools like 'clearText' or 'selectAllText'. It avoids tautology by not restating the name exactly, but lacks specificity.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention context, prerequisites, or exclusions, leaving the agent to infer usage from sibling tool names alone, which is insufficient for clear decision-making.

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/zillow/auto-mobile'

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