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,
        })),
      };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full disclosure burden. It successfully signals behavioral traits through 'tracked state,' 'history,' and 'recent actions,' indicating temporal accumulation rather than a single snapshot. However, it omits safety considerations (though likely read-only), return format structure, or history retention limits.

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 consists of two efficient sentences with zero redundancy. It front-loads the core action and resource in the first sentence and follows with usage context in the second. Every word earns its place.

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?

The tool returns complex structured data (three distinct data types) but lacks an output schema. The description partially compensates by listing the three returned components (app, history, actions), but does not describe the data structure, types, or relationships between these fields, leaving significant gaps for an agent attempting to parse the response.

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?

The input schema has 100% description coverage (device_id is documented as 'Device serial number'), establishing a baseline of 3. The description implies device targeting but does not add syntax details, validation rules, or explain the default 'default' value behavior beyond what the schema provides.

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 uses a specific verb ('Get') and resource ('tracked state of a device') and clearly enumerates the three components returned: current app, screen history, and recent actions. The term 'tracked' effectively distinguishes it from sibling tools like get_device_info (likely static) and get_current_app (snapshot only).

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?

While it mentions the tool is 'Useful for understanding context,' it provides no explicit guidance on when to select this tool versus similar siblings like get_current_app, get_ui_tree, or get_device_info. Given the large number of overlapping device-query tools available, the lack of selection criteria is a significant gap.

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

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