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.

add typings to ios (#22)

Andreas Lüdeke0311ca4352cc
diff --git a/src/ios.ts b/src/ios.ts
index a04cbd6..2e983dd 100644
--- a/src/ios.ts
+++ b/src/ios.ts
@@ -5,7 +5,7 @@ import { readFileSync, unlinkSync } from "fs";
import { execFileSync } from "child_process";
import { Socket } from "net";
-import { WebDriverAgent } from "./webdriver-agent";
+import { ScreenElement, WebDriverAgent } from "./webdriver-agent";
import { Button, Dimensions, InstalledApp, Robot, SwipeDirection } from "./robot";
const WDA_PORT = 8100;
@@ -114,7 +114,7 @@ export class IosRobot implements Robot {
await wda.tap(x, y);
}
- public async getElementsOnScreen(): Promise<any[]> {
+ public async getElementsOnScreen(): Promise<ScreenElement[]> {
const wda = await this.wda();
return await wda.getElementsOnScreen();
}
diff --git a/src/webdriver-agent.ts b/src/webdriver-agent.ts
index 07ebc75..ac1d1ab 100644
--- a/src/webdriver-agent.ts
+++ b/src/webdriver-agent.ts
@@ -1,6 +1,6 @@
-import { SwipeDirection } from "./robot";
+import { Dimensions, SwipeDirection } from "./robot";
-interface SourceTreeElement {
+export interface SourceTreeElement {
type: string;
label?: string;
name?: string;
@@ -15,16 +15,28 @@ interface SourceTreeElement {
children?: Array<SourceTreeElement>;
}
-interface SourceTree {
+export interface SourceTree {
value: SourceTreeElement;
}
+export interface ScreenElement {
+ type: string;
+ label?: string;
+ name?: string;
+ rect: {
+ x0: number;
+ y0: number;
+ x1: number;
+ y1: number;
+ };
+}
+
export class WebDriverAgent {
constructor(private readonly host: string, private readonly port: number) {
}
- public async createSession() {
+ public async createSession(): Promise<string> {
const url = `http://${this.host}:${this.port}/session`;
const response = await fetch(url, {
method: "POST",
@@ -52,7 +64,7 @@ export class WebDriverAgent {
return result;
}
- public async getScreenSize() {
+ public async getScreenSize(): Promise<Dimensions> {
return this.withinSession(async sessionUrl => {
const url = `${sessionUrl}/wda/screen`;
const response = await fetch(url);
@@ -137,9 +149,9 @@ export class WebDriverAgent {
});
}
- private filterSourceElements(source: SourceTreeElement): Array<any> {
+ private filterSourceElements(source: SourceTreeElement): Array<ScreenElement> {
- const output: any[] = [];
+ const output: ScreenElement[] = [];
if (["TextField", "Button", "Switch", "Icon", "SearchField"].includes(source.type)) {
if (source.label !== null || source.name !== null) {
@@ -173,7 +185,7 @@ export class WebDriverAgent {
return json as SourceTree;
}
- public async getElementsOnScreen(): Promise<any[]> {
+ public async getElementsOnScreen(): Promise<ScreenElement[]> {
const source = await this.getPageSource();
return this.filterSourceElements(source.value);
}