Skip to main content
Glama

type_text

Input text into focused fields on Android devices or emulators, optionally clearing existing content first for automated testing and interaction.

Instructions

Type text into the currently focused input field on the Android device/emulator.

Args:
    text: The text to type into the input field
    device_id: Optional device ID to target specific device/emulator
    clear_first: If True, clears existing text before typing new text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clear_firstNo
device_idNo
textYes

Implementation Reference

  • The handler function for the MCP tool 'type_text'. It connects to the Android device using uiautomator2, enables fast input IME, and uses device.send_keys() to type the provided text, optionally clearing the field first. The @mcp.tool() decorator registers it as an MCP tool.
    @mcp.tool()
    async def type_text(text: str, device_id: str = None, clear_first: bool = False) -> dict:
        """Type text into the currently focused input field on the Android device/emulator.
    
        Args:
            text: The text to type into the input field
            device_id: Optional device ID to target specific device/emulator
            clear_first: If True, clears existing text before typing new text
        """
        try:
            if not text:
                return {
                    "success": False,
                    "error": "Text parameter cannot be empty",
                    "text": text
                }
    
            # Get device connection for uiautomator2
            device = get_device_connection(device_id)
    
            # Enable fast input IME for reliable text input
            device.set_fastinput_ime(enable=True)
    
            # Use uiautomator2's send_keys method which is much more reliable
            device.send_keys(text=text, clear=clear_first)
    
            return {
                "success": True,
                "message": f"Successfully typed text into input field",
                "text": text,
                "cleared_first": clear_first,
                "action_type": "type_text",
                "device_id": device_id or "default"
            }
    
        except subprocess.CalledProcessError as e:
            return {
                "success": False,
                "error": f"Failed to type text: {e}",
                "stderr": e.stderr if e.stderr else "",
                "text": text,
                "action_type": "type_text"
            }
        except FileNotFoundError:
            return {
                "success": False,
                "error": "ADB not found. Please ensure Android SDK is installed and adb is in PATH.",
                "text": text,
                "action_type": "type_text"
            }
        except Exception as e:
            return {
                "success": False,
                "error": f"Unexpected error: {e}",
                "text": text,
                "action_type": "type_text"
            }
  • puppeteer.py:822-822 (registration)
    The @mcp.tool() decorator registers the type_text function as an MCP tool.
    @mcp.tool()
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 the clear_first parameter behavior ('clears existing text before typing new text'), which is useful, but doesn't describe other important traits like error conditions (what happens if no input field is focused), permissions needed, or whether this is a read-only or mutation operation. For a tool that modifies device state, this is a significant gap.

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 appropriately sized with a clear purpose statement followed by parameter explanations. The Args section is well-structured but could be more integrated with the main description. Every sentence adds value, though the formatting as a bullet list under 'Args:' slightly disrupts flow.

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

Completeness3/5

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

Given 3 parameters with no schema descriptions and no output schema, the description does well on parameter semantics but lacks completeness for a mutation tool. It doesn't explain return values, error conditions, or behavioral constraints beyond the clear_first parameter. The description is adequate but has clear gaps for a tool that modifies device state.

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

Parameters4/5

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

The description provides clear semantic explanations for all three parameters beyond what the schema shows (0% coverage). It explains that 'text' is 'The text to type into the input field', 'device_id' is 'Optional device ID to target specific device/emulator', and 'clear_first' controls whether to 'clears existing text before typing new text'. This fully compensates for the lack of schema descriptions.

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 specific action ('Type text into the currently focused input field') and target resource ('Android device/emulator'), distinguishing it from sibling tools like press, swipe, or long_press. It uses precise verb+resource language that leaves no ambiguity about what the tool does.

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

Usage Guidelines3/5

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

The description implies usage context ('currently focused input field') but doesn't explicitly state when to use this tool versus alternatives like press (for buttons) or scroll_element (for navigation). No guidance is provided about prerequisites (e.g., needing an input field focused) or exclusions, leaving usage context somewhat implied rather than explicitly documented.

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/pedro-rivas/android-puppeteer-mcp'

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