Skip to content

Mobile MCP: let AI agents drive your iOS and Android apps. MCP server for simulators, emulators and real devices. Works with Claude Code, Codex, Cursor and any MCP client.

perf: cache Robot per device id

gmegidish868b1646be1a
diff --git a/src/server.ts b/src/server.ts
index 2a24ed1..ef9c3a4 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -173,7 +173,21 @@ export const createMcpServer = (): McpServer => {
}
};
+ // ponytail: cache per device id, saves ~0.2s (mobilecli --version + devices) on every tool call
+ const robotCache = new Map<string, Robot>();
+
const getRobotFromDevice = (deviceId: string): Robot => {
+ const cached = robotCache.get(deviceId);
+ if (cached) {
+ return cached;
+ }
+
+ const robot = createRobotFromDevice(deviceId);
+ robotCache.set(deviceId, robot);
+ return robot;
+ };
+
+ const createRobotFromDevice = (deviceId: string): Robot => {
// from now on, we must have mobilecli working
ensureMobilecliAvailable();