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.
TypeScript agentandroidandroid-automationappium-alternativeclaude-codecodexcursoremulatoriosios-automationmcpmcp-servermobilemobile-automationmobile-testingreal-devicesimulatorskills
fix: batch commands use Map registry, validate step args via tool schema, reject screenshot
gmegidish9fcc1562353c
diff --git a/src/server.ts b/src/server.tsindex b414a56..d39dcf2 100644--- a/src/server.ts+++ b/src/server.ts@@ -79,10 +79,10 @@ export const createMcpServer = (): McpServer => {type ToolCallback = (args: any, telemetry: Record<string, string | number>) => Promise<string>;// ponytail: batch calls tool callbacks directly, bypassing mcp transport- const toolCallbacks: Record<string, ToolCallback> = {};+ const toolCallbacks = new Map<string, { callback: ToolCallback; paramsSchema: ZodSchemaShape }>();const tool = (name: string, title: string, description: string, paramsSchema: ZodSchemaShape, annotations: ToolAnnotations, cb: ToolCallback) => {- toolCallbacks[name] = cb;+ toolCallbacks.set(name, { callback: cb, paramsSchema });server.registerTool(name, {title,description,@@ -1131,13 +1131,18 @@ export const createMcpServer = (): McpServer => {throw new ActionableError("mobile_batch_commands cannot be nested");}- const cb = toolCallbacks[step.name];- if (!cb) {+ if (step.name === "mobile_take_screenshot") {+ throw new ActionableError("mobile_take_screenshot returns an image and cannot be used in a batch, use mobile_save_screenshot instead");+ }++ const entry = toolCallbacks.get(step.name);+ if (!entry) {throw new ActionableError(`Unknown tool in step ${i + 1}: ${step.name}`);}try {- const output = await cb({ device, ...step.arguments }, {});+ const args = z.object(entry.paramsSchema).parse({ device, ...step.arguments });+ const output = await entry.callback(args, {});results.push(`Step ${i + 1} (${step.name}): ${output}`);} catch (error: any) {results.push(`Step ${i + 1} (${step.name}) failed: ${error.message}`);@@ -1148,7 +1153,7 @@ export const createMcpServer = (): McpServer => {}if (listElementsAtEnd) {- results.push(await toolCallbacks["mobile_list_elements_on_screen"]({ device }, {}));+ results.push(await toolCallbacks.get("mobile_list_elements_on_screen")!.callback({ device }, {}));}return results.join("\n");diff --git a/test/server-batch.test.ts b/test/server-batch.test.tsindex 06641ff..dc34897 100644--- a/test/server-batch.test.ts+++ b/test/server-batch.test.ts@@ -51,3 +51,25 @@ test("stops at the first failing step by default", async () => {expect(text).toContain("Step 1 (mobile_click_on_screen_at_coordinates) failed");expect(text).not.toContain("Step 2");});++test("rejects a step named after an inherited object property", async () => {+ const client = await createConnectedClient();+ const text = await runBatch(client, { device: "nope", steps: [{ name: "constructor", arguments: {} }] });+ expect(text).toContain("Unknown tool in step 1: constructor");+});++test("rejects mobile_take_screenshot with a hint to use mobile_save_screenshot", async () => {+ const client = await createConnectedClient();+ const text = await runBatch(client, { device: "nope", steps: [{ name: "mobile_take_screenshot", arguments: {} }] });+ expect(text).toContain("use mobile_save_screenshot instead");+});++test("validates step arguments against the target tool schema", async () => {+ const client = await createConnectedClient();+ const text = await runBatch(client, {+ device: "nope",+ steps: [{ name: "mobile_click_on_screen_at_coordinates", arguments: { x: "not-a-number", y: 1 } }],+ });+ expect(text).toContain("Step 1 (mobile_click_on_screen_at_coordinates) failed");+ expect(text).toContain("x");+});