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.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_device_state"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No | Device serial number | default |
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, })), }; }