Skip to content

Commit 3299734

Browse files
committed
feat(android, ios): implement AI-driven app loading and update connection messages
1 parent 9cfd87e commit 3299734

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

packages/android-mcp/src/android-tools.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ export class AndroidMidsceneTools extends BaseMidsceneTools {
6565
// If URI is provided, launch the app
6666
if (uri) {
6767
await agent.page.launch(uri);
68-
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait for app to launch
68+
69+
// Wait for app to finish loading using AI-driven polling
70+
await agent.aiWaitFor(
71+
'the app has finished loading and is ready to use',
72+
{
73+
timeoutMs: 10000,
74+
checkIntervalMs: 2000,
75+
},
76+
);
6977
}
7078

7179
const screenshot = await agent.page.screenshotBase64();
@@ -75,7 +83,7 @@ export class AndroidMidsceneTools extends BaseMidsceneTools {
7583
content: [
7684
{
7785
type: 'text',
78-
text: `Connected to Android device${deviceId ? `: ${deviceId}` : ' (auto-detected)'}${uri ? ` and launched: ${uri}` : ''}`,
86+
text: `Connected to Android device${deviceId ? `: ${deviceId}` : ' (auto-detected)'}${uri ? ` and launched: ${uri} (app ready)` : ''}`,
7987
},
8088
{
8189
type: 'image',

packages/ios-mcp/src/ios-tools.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { z } from '@midscene/core';
12
import { type IOSAgent, agentFromWebDriverAgent } from '@midscene/ios';
23
import { parseBase64 } from '@midscene/shared/img';
34
import { getDebug } from '@midscene/shared/logger';
@@ -27,18 +28,41 @@ export class IOSMidsceneTools extends BaseMidsceneTools {
2728
return [
2829
{
2930
name: 'ios_connect',
30-
description: 'Connect to iOS device or simulator via WebDriverAgent',
31-
schema: {},
32-
handler: async () => {
31+
description:
32+
'Connect to iOS device or simulator via WebDriverAgent and optionally launch an app',
33+
schema: {
34+
uri: z
35+
.string()
36+
.optional()
37+
.describe(
38+
'Optional URI to launch app (e.g., http://example.com for URL, or com.example.app for bundle ID)',
39+
),
40+
},
41+
handler: async ({ uri }: { uri?: string }) => {
3342
const agent = await this.ensureAgent();
43+
44+
// If URI is provided, launch the app
45+
if (uri) {
46+
await agent.page.launch(uri);
47+
48+
// Wait for app to finish loading using AI-driven polling
49+
await agent.aiWaitFor(
50+
'the app has finished loading and is ready to use',
51+
{
52+
timeoutMs: 10000,
53+
checkIntervalMs: 2000,
54+
},
55+
);
56+
}
57+
3458
const screenshot = await agent.page.screenshotBase64();
3559
const { mimeType, body } = parseBase64(screenshot);
3660

3761
return {
3862
content: [
3963
{
4064
type: 'text',
41-
text: 'Connected to iOS device',
65+
text: `Connected to iOS device${uri ? ` and launched: ${uri} (app ready)` : ''}`,
4266
},
4367
{
4468
type: 'image',

packages/ios/src/device.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { IOSWebDriverClient as WebDriverAgentBackend } from './ios-webdriver-cli
3333
export type { IOSDeviceOpt, IOSDeviceInputOpt } from '@midscene/core/device';
3434

3535
const debugDevice = getDebug('ios:device');
36-
const BackspaceChar = '\u0008'; // Unicode backspace character
3736

3837
/**
3938
* HTTP methods supported by WebDriverAgent API

packages/mcp/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineConfig({
99
},
1010
entry: {
1111
index: './src/index.ts',
12+
server: './src/server.ts',
1213
},
1314
},
1415
output: {

0 commit comments

Comments
 (0)