Skip to main content
Glama

replace_text

Replace text on Android devices by clearing existing content and typing new text for automated testing or content updates.

Instructions

Replace text on the connected Android device by clearing current text and typing new text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes

Implementation Reference

  • The replace_text tool handler, registered via @mcp.tool() decorator. It uses a series of ADB shell input keyevents to select all text (trying Ctrl+A, multiple Ctrl, or home+shift+end), clear it with DEL or BACK, then input the new text (replacing spaces with %s for ADB compatibility). Returns success message or raises RuntimeError on failure.
    @mcp.tool()
    def replace_text(text: str) -> str:
        """Replace text on the connected Android device by clearing current text and typing new text"""
        # Try using Ctrl+A to select all text
        ctrl_a = subprocess.run(
            ["adb", "shell", "input", "keyevent", "KEYCODE_CTRL_LEFT", "KEYCODE_A"],
            capture_output=True,
            text=True,
        )
        
        # If Ctrl+A doesn't work, try alternative selection methods
        if ctrl_a.returncode != 0:
            # Method 1: Select all using key combination
            select_all_combo = subprocess.run(
                ["adb", "shell", "input", "keyevent", "29", "29", "29"],  # Multiple Ctrl+A attempts
                capture_output=True,
                text=True,
            )
            
            if select_all_combo.returncode != 0:
                # Method 2: Move to start, then select to end
                move_home = subprocess.run(
                    ["adb", "shell", "input", "keyevent", "KEYCODE_MOVE_HOME"],
                    capture_output=True,
                    text=True,
                )
                if move_home.returncode == 0:
                    # Hold shift and move to end
                    subprocess.run(
                        ["adb", "shell", "input", "keyevent", "KEYCODE_SHIFT_LEFT"],
                        capture_output=True,
                        text=True,
                    )
                    subprocess.run(
                        ["adb", "shell", "input", "keyevent", "KEYCODE_MOVE_END"],
                        capture_output=True,
                        text=True,
                    )
        
        # Clear the selected text by pressing delete/backspace
        delete = subprocess.run(
            ["adb", "shell", "input", "keyevent", "KEYCODE_DEL"],
            capture_output=True,
            text=True,
        )
        if delete.returncode != 0:
            # If delete doesn't work, try backspace
            backspace = subprocess.run(
                ["adb", "shell", "input", "keyevent", "KEYCODE_BACK"],
                capture_output=True,
                text=True,
            )
            if backspace.returncode != 0:
                raise RuntimeError("Error clearing text: unable to delete selected text")
        
        # Type the new text
        adb_text = text.replace(" ", "%s")
        type_result = subprocess.run(
            ["adb", "shell", "input", "text", adb_text],
            capture_output=True,
            text=True,
        )
        if type_result.returncode != 0:
            raise RuntimeError(f"Error typing text '{text}': {type_result.stderr}")
        
        return f"Replaced text with '{text}' successfully."
  • Decorator that registers the replace_text function as an MCP tool.
    @mcp.tool()
  • Function signature defines input schema (text: str) and output (str), with docstring providing description.
    def replace_text(text: str) -> str:
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 describes the action ('clearing current text and typing new text'), which implies mutation, but lacks details on permissions, side effects, error handling, or what 'connected Android device' entails. For a mutation tool with zero annotation coverage, 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 ('Replace text on the connected Android device') and elaborates concisely. There's no wasted verbiage, though it could be slightly more structured for clarity.

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 (a mutation operation on an Android device), lack of annotations, no output schema, and low parameter coverage, the description is incomplete. It doesn't address what happens on failure, the scope of 'current text', or interaction with other tools, leaving significant gaps for an agent to use it correctly.

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 0%, so the description must compensate. It implies the 'text' parameter is the new text to type, but doesn't specify format, length limits, or handling of special characters. The description adds minimal semantic context beyond the schema's title ('Text'), meeting the baseline for low coverage without fully compensating.

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 ('replace text') and target ('on the connected Android device'), specifying the method ('by clearing current text and typing new text'). It distinguishes from 'type_text' by including clearing, but doesn't explicitly differentiate from 'clear_and_type_text' which appears similar. The purpose is specific and actionable.

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 like 'type_text' or 'clear_and_type_text'. The description implies it's for text replacement on Android devices, but there's no explicit context, prerequisites, or exclusions mentioned. Usage is left to inference from the tool name and description alone.

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/vs4vijay/espresso-mcp'

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