Skip to main content
Glama

get_device_state

Retrieve current Android device state including active app, screen history, and recent actions to understand user context for automation tasks.

Instructions

Get the current tracked state of a device including current app, screen history, and recent actions. Useful for understanding context.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idNoDevice serial numberdefault

Implementation Reference

  • Registration and handler implementation of the 'get_device_state' tool.
    server.registerTool(
      'get_device_state',
      {
        description: 'Get the current tracked state of a device including current app, screen history, and recent actions. Useful for understanding context.',
        inputSchema: {
          device_id: z.string().optional().default('default').describe('Device serial number'),
        },
      },
      async ({ device_id }) => {
        const summary = stateTracker.getStateSummary(device_id || 'default');
        return {
          content: [{
            type: 'text' as const,
            text: JSON.stringify({ success: true, state: summary }, null, 2),
          }],
  • The logic that actually computes the state summary for the 'get_device_state' tool.
    getStateSummary(deviceId: string): Record<string, unknown> {
      const state = this.getState(deviceId);
    
      return {
        currentApp: state.currentApp,
        screenHash: state.screenHash,
        lastScreenAge: state.lastScreenTimestamp
          ? `${Math.round((Date.now() - state.lastScreenTimestamp) / 1000)}s ago`
          : 'never',
        screenHistoryLength: state.screenHistory.length,
        recentActions: state.lastActions.slice(-5).map(a => ({
          tool: a.tool,
          ago: `${Math.round((Date.now() - a.timestamp) / 1000)}s`,
        })),
        knownApps: Array.from(state.appStates.values()).map(a => ({
          package: a.packageName,
          visits: a.visitCount,
        })),
      };
    }

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