Skip to main content
Glama
observeTools.ts1.87 kB
import { z } from "zod"; import { ToolRegistry } from "./toolRegistry"; import { ActionableError } from "../models/ActionableError"; import { ObserveScreen } from "../features/observe/ObserveScreen"; import { ListInstalledApps } from "../features/observe/ListInstalledApps"; import { createJSONToolResponse } from "../utils/toolUtils"; import { BootedDevice } from "../models"; // Schema definitions export const observeSchema = z.object({ platform: z.enum(["android", "ios"]).describe("Target platform") }); export const listAppsSchema = z.object({ platform: z.enum(["android", "ios"]).describe("Target platform") }); // Register tools (this will be called when this file is imported) export function registerObserveTools() { // Observe handler const observeHandler = async (device: BootedDevice) => { try { const observeScreen = new ObserveScreen(device); const result = await observeScreen.execute(); return createJSONToolResponse(result); } catch (error) { throw new ActionableError(`Failed to execute observe: ${error}`); } }; // List Apps handler const listAppsHandler = async (device: BootedDevice) => { try { const listInstalledApps = new ListInstalledApps(device); const apps = await listInstalledApps.execute(); return createJSONToolResponse({ message: `Listed ${apps.length} apps`, apps }); } catch (error) { throw new ActionableError(`Failed to list apps: ${error}`); } }; // Register with the tool registry using the new device-aware method ToolRegistry.registerDeviceAware( "observe", "Get the view hierarchy of what is displayed on screen", observeSchema, observeHandler, ); ToolRegistry.registerDeviceAware( "listApps", "List all apps installed on the device", listAppsSchema, listAppsHandler ); }

Implementation Reference

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/zillow/auto-mobile'

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