Skip to main content
Glama

replay_recording

Replay recorded Android device actions to automate repetitive tasks, using JSON files to control app interactions and UI sequences.

Instructions

Replay a previously recorded action sequence.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recording_pathYesFile path to the recording JSON file
delay_between_actionsNoDelay between actions in ms
stop_on_errorNo
device_idNoOverride the device ID from the recording

Implementation Reference

  • The core implementation of the replay logic that iterates through recorded actions and executes them.
    export async function replayRecording(
      recording: Recording,
      options: {
        delayBetweenActions?: number;
        stopOnError?: boolean;
        deviceId?: string;
      } = {}
    ): Promise<ReplayResult> {
      const {
        delayBetweenActions = 500,
        stopOnError = false,
        deviceId = recording.deviceId,
      } = options;
    
      const result: ReplayResult = {
        totalActions: recording.actions.length,
        successCount: 0,
        failureCount: 0,
        results: [],
      };
    
      log.info('Replaying recording', {
        id: recording.id,
        name: recording.name,
        actionCount: recording.actions.length,
        deviceId,
      });
    
      for (const action of recording.actions) {
        const start = Date.now();
        let success = true;
        let error: string | undefined;
    
        try {
          await executeAction(action, deviceId);
        } catch (err) {
          success = false;
          error = err instanceof Error ? err.message : String(err);
          log.error('Replay action failed', { actionId: action.id, tool: action.tool, error });
    
          if (stopOnError) {
            result.results.push({
              actionId: action.id,
              tool: action.tool,
              success: false,
              error,
              durationMs: Date.now() - start,
            });
            result.failureCount++;
            break;
          }
        }
    
        result.results.push({
          actionId: action.id,
          tool: action.tool,
          success,
          error,
          durationMs: Date.now() - start,
        });
    
        if (success) result.successCount++;
        else result.failureCount++;
    
        // Delay between actions
        if (delayBetweenActions > 0) {
          await new Promise(resolve => setTimeout(resolve, delayBetweenActions));
        }
      }
    
      log.info('Replay completed', {
        id: recording.id,
        success: result.successCount,
        failures: result.failureCount,
      });
    
      return result;
    }
  • Registration of the 'replay_recording' MCP tool, which parses input and calls the replayRecording handler.
    server.registerTool(
      'replay_recording',
      {
        description: 'Replay a previously recorded action sequence.',
        inputSchema: {
          recording_path: z.string().describe('File path to the recording JSON file'),
          delay_between_actions: z.number().optional().default(500).describe('Delay between actions in ms'),
          stop_on_error: z.boolean().optional().default(false),
          device_id: z.string().optional().describe('Override the device ID from the recording'),
        },
      },
      async ({ recording_path, delay_between_actions, stop_on_error, device_id }) => {
        return await metrics.measure('replay_recording', device_id || 'default', async () => {
          const recording = actionRecorder.loadRecording(recording_path);
          const result = await replayRecording(recording, {
            delayBetweenActions: delay_between_actions,
            stopOnError: stop_on_error,
            deviceId: device_id,
          });
          return {
            content: [{
              type: 'text' as const,
              text: JSON.stringify({
                success: result.failureCount === 0,
                summary: {
                  total: result.totalActions,
                  succeeded: result.successCount,
                  failed: result.failureCount,
                },
                results: result.results,
              }, null, 2),
            }],
          };
        });
      }
    );

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/divineDev-dotcom/android_mcp'

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