appium-mcp 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/interactions/handle-alert.d.ts +11 -0
- package/dist/tools/interactions/handle-alert.d.ts.map +1 -0
- package/dist/tools/interactions/handle-alert.js +134 -0
- package/dist/tools/interactions/handle-alert.js.map +1 -0
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/tools/index.ts +2 -0
- package/src/tools/interactions/handle-alert.ts +168 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [1.15.0](https://github.com/appium/appium-mcp/compare/v1.14.0...v1.15.0) (2026-02-15)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **interactions:** add handle-alert tool ([#57](https://github.com/appium/appium-mcp/issues/57)) ([966d035](https://github.com/appium/appium-mcp/commit/966d035455c2767cc027e78bda592a01a3847c17))
|
|
6
|
+
|
|
1
7
|
## [1.14.0](https://github.com/appium/appium-mcp/compare/v1.13.0...v1.14.0) (2026-02-15)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/README.md
CHANGED
|
@@ -265,6 +265,7 @@ MCP Appium provides a comprehensive set of tools organized into the following ca
|
|
|
265
265
|
| `appium_drag_and_drop` | Perform a drag and drop gesture from a source location to a target location (supports element-to-element, element-to-coordinates, coordinates-to-element, and coordinates-to-coordinates) |
|
|
266
266
|
| `appium_set_value` | Enter text into an input field |
|
|
267
267
|
| `appium_get_text` | Get text content from an element |
|
|
268
|
+
| `appium_handle_alert` | Accept or dismiss system/permission alerts, or click a dialog button by label |
|
|
268
269
|
|
|
269
270
|
### Screen & Navigation
|
|
270
271
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAiClC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAkH3D"}
|
package/dist/tools/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import dragAndDrop from './interactions/drag-and-drop.js';
|
|
|
20
20
|
import setValue from './interactions/set-value.js';
|
|
21
21
|
import getText from './interactions/get-text.js';
|
|
22
22
|
import getPageSource from './interactions/get-page-source.js';
|
|
23
|
+
import handleAlert from './interactions/handle-alert.js';
|
|
23
24
|
import { screenshot, elementScreenshot } from './interactions/screenshot.js';
|
|
24
25
|
import activateApp from './app-management/activate-app.js';
|
|
25
26
|
import installApp from './app-management/install-app.js';
|
|
@@ -112,6 +113,7 @@ export default function registerTools(server) {
|
|
|
112
113
|
setValue(server);
|
|
113
114
|
getText(server);
|
|
114
115
|
getPageSource(server);
|
|
116
|
+
handleAlert(server);
|
|
115
117
|
screenshot(server);
|
|
116
118
|
elementScreenshot(server);
|
|
117
119
|
// App Management
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAeA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,YAAY,MAAM,kCAAkC,CAAC;AAC5D,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,aAAa,MAAM,6BAA6B,CAAC;AACxD,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAC7D,OAAO,cAAc,MAAM,8BAA8B,CA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S,CAAC,MAAM,CAAC,CAAC;IAClB,SAAS,CAAC,MAAM,CAAC,CAAC;IAClB,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjB,OAAO,CAAC,MAAM,CAAC,CAAC;IAChB,aAAa,CAAC,MAAM,CAAC,CAAC;IACtB,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,UAAU,CAAC,MAAM,CAAC,CAAC;IACnB,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE1B,iBAAiB;IACjB,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,UAAU,CAAC,MAAM,CAAC,CAAC;IACnB,YAAY,CAAC,MAAM,CAAC,CAAC;IACrB,YAAY,CAAC,MAAM,CAAC,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEjB,qBAAqB;IACrB,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,aAAa,CAAC,MAAM,CAAC,CAAC;IAEtB,kBAAkB;IAClB,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzB,YAAY,CAAC,MAAM,CAAC,CAAC;IAErB,gBAAgB;IAChB,YAAY,CAAC,MAAM,CAAC,CAAC;IACrB,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FastMCP } from 'fastmcp';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const handleAlertSchema: z.ZodObject<{
|
|
4
|
+
action: z.ZodEnum<{
|
|
5
|
+
accept: "accept";
|
|
6
|
+
dismiss: "dismiss";
|
|
7
|
+
}>;
|
|
8
|
+
buttonLabel: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
export default function handleAlert(server: FastMCP): void;
|
|
11
|
+
//# sourceMappingURL=handle-alert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-alert.d.ts","sourceRoot":"","sources":["../../../src/tools/interactions/handle-alert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,iBAAiB;;;;;;iBAe5B,CAAC;AAsFH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CA6DzD"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { generateAllElementLocators } from '../../locators/generate-all-locators.js';
|
|
3
|
+
import { getDriver, getPlatformName, PLATFORM } from '../../session-store.js';
|
|
4
|
+
export const handleAlertSchema = z.object({
|
|
5
|
+
action: z
|
|
6
|
+
.enum(['accept', 'dismiss'])
|
|
7
|
+
.describe('Action to perform on the alert: accept or dismiss'),
|
|
8
|
+
buttonLabel: z
|
|
9
|
+
.string()
|
|
10
|
+
.optional()
|
|
11
|
+
.describe(`Optional label of the button to click. Common permission dialog buttons:
|
|
12
|
+
Android: "While using the app", "Only this time", "Don't allow"
|
|
13
|
+
iOS: "Always" or "Allow Always", "Once" or "Allow Once", "Don't allow"
|
|
14
|
+
Standard: "OK", "Cancel", "Allow", "Deny"
|
|
15
|
+
If not provided, uses default button based on action.
|
|
16
|
+
Use appium_get_page_source or generate_locators to inspect the screen and discover exact labels.`),
|
|
17
|
+
});
|
|
18
|
+
const ANDROID_LOCATOR_STRATEGY_ORDER = [
|
|
19
|
+
'id',
|
|
20
|
+
'accessibility id',
|
|
21
|
+
'xpath',
|
|
22
|
+
'-android uiautomator',
|
|
23
|
+
'class name',
|
|
24
|
+
];
|
|
25
|
+
async function handleAndroidAlert(driver, action, buttonLabel) {
|
|
26
|
+
if (buttonLabel) {
|
|
27
|
+
const pageSource = await driver.getPageSource();
|
|
28
|
+
const elements = generateAllElementLocators(pageSource, true, 'uiautomator2', {
|
|
29
|
+
fetchableOnly: true,
|
|
30
|
+
});
|
|
31
|
+
const normalizedLabel = buttonLabel.trim();
|
|
32
|
+
const match = elements.find((el) => (el.text?.trim() === normalizedLabel ||
|
|
33
|
+
el.contentDesc?.trim() === normalizedLabel) &&
|
|
34
|
+
el.clickable) ??
|
|
35
|
+
elements.find((el) => el.text?.trim() === normalizedLabel ||
|
|
36
|
+
el.contentDesc?.trim() === normalizedLabel);
|
|
37
|
+
if (!match) {
|
|
38
|
+
throw new Error(`No element found with text or content-desc "${buttonLabel}"`);
|
|
39
|
+
}
|
|
40
|
+
let button = null;
|
|
41
|
+
for (const strategy of ANDROID_LOCATOR_STRATEGY_ORDER) {
|
|
42
|
+
const selector = match.locators[strategy];
|
|
43
|
+
if (!selector) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
button = await driver.findElement(strategy, selector);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!button) {
|
|
55
|
+
throw new Error('Could not find element with any generated locator; it may have disappeared');
|
|
56
|
+
}
|
|
57
|
+
const buttonUUID = button.ELEMENT || button;
|
|
58
|
+
await driver.click(buttonUUID);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (action === 'accept') {
|
|
62
|
+
await driver.execute('mobile: acceptAlert', {});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
await driver.execute('mobile: dismissAlert', {});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function handleiOSAlert(driver, action, buttonLabel) {
|
|
70
|
+
const params = { action };
|
|
71
|
+
if (buttonLabel) {
|
|
72
|
+
params.buttonLabel = buttonLabel;
|
|
73
|
+
}
|
|
74
|
+
await driver.execute('mobile: alert', params);
|
|
75
|
+
}
|
|
76
|
+
export default function handleAlert(server) {
|
|
77
|
+
server.addTool({
|
|
78
|
+
name: 'appium_handle_alert',
|
|
79
|
+
description: `Handle system alerts or dialogs that do not belong to the app.
|
|
80
|
+
Use this to dismiss or accept alerts programmatically instead of using autoDismissAlerts capability.
|
|
81
|
+
Supports permission dialogs with buttons like:
|
|
82
|
+
- Android: "While using the app", "Only this time", "Don't allow"
|
|
83
|
+
- iOS: "Always", "Allow Once", "Don't allow"
|
|
84
|
+
For iOS: Uses mobile: alert execute command.
|
|
85
|
+
For Android: Uses mobile: acceptAlert/dismissAlert or searches the current page source for an element whose text or content-desc matches the label, then uses generated locators to find and click it (no hardcoded resource IDs or XPaths).
|
|
86
|
+
If no alert is present, the error is caught and returned gracefully.
|
|
87
|
+
To discover button labels and screen structure first, use appium_get_page_source (XML hierarchy) or generate_locators (interactable elements with text/content-desc).`,
|
|
88
|
+
parameters: handleAlertSchema,
|
|
89
|
+
annotations: {
|
|
90
|
+
readOnlyHint: false,
|
|
91
|
+
openWorldHint: false,
|
|
92
|
+
},
|
|
93
|
+
execute: async (args, context) => {
|
|
94
|
+
const driver = getDriver();
|
|
95
|
+
if (!driver) {
|
|
96
|
+
throw new Error('No driver found');
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const platform = getPlatformName(driver);
|
|
100
|
+
if (platform === PLATFORM.android) {
|
|
101
|
+
await handleAndroidAlert(driver, args.action, args.buttonLabel);
|
|
102
|
+
}
|
|
103
|
+
else if (platform === PLATFORM.ios) {
|
|
104
|
+
await handleiOSAlert(driver, args.action, args.buttonLabel);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw new Error(`Unsupported platform: ${platform}. Only Android and iOS are supported.`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
type: 'text',
|
|
113
|
+
text: `Successfully ${args.action}ed alert${args.buttonLabel ? ` with button "${args.buttonLabel}"` : ''}`,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
const contextStr = args.buttonLabel
|
|
120
|
+
? `action=${args.action}, buttonLabel="${args.buttonLabel}"`
|
|
121
|
+
: `action=${args.action}`;
|
|
122
|
+
return {
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: 'text',
|
|
126
|
+
text: `Failed to handle alert (${contextStr}). err: ${err.toString()}`,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=handle-alert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-alert.js","sourceRoot":"","sources":["../../../src/tools/interactions/handle-alert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE9E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC;SACN,IAAI,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;SAC3B,QAAQ,CAAC,mDAAmD,CAAC;IAChE,WAAW,EAAE,CAAC;SACX,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP;;;;;iGAK2F,CAC5F;CACJ,CAAC,CAAC;AAEH,MAAM,8BAA8B,GAAG;IACrC,IAAI;IACJ,kBAAkB;IAClB,OAAO;IACP,sBAAsB;IACtB,YAAY;CACb,CAAC;AAEF,KAAK,UAAU,kBAAkB,CAC/B,MAAW,EACX,MAAc,EACd,WAAoB;IAEpB,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC;QAChD,MAAM,QAAQ,GAAG,0BAA0B,CACzC,UAAU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KAAK,QAAQ,CAAC,GAAG,EAAE,CAAC;oBACrC,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC9D,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CACb,yBAAyB,QAAQ,uCAAuC,CACzE,CAAC;gBACJ,CAAC;gBAED,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,gBAAgB,IAAI,CAAC,MAAM,WAC/B,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAC5D,EAAE;yBACH;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW;oBACjC,CAAC,CAAC,UAAU,IAAI,CAAC,MAAM,kBAAkB,IAAI,CAAC,WAAW,GAAG;oBAC5D,CAAC,CAAC,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC5B,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,2BAA2B,UAAU,WAAW,GAAG,CAAC,QAAQ,EAAE,EAAE;yBACvE;qBACF;iBACF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"name": "io.github.appium/appium-mcp",
|
|
4
4
|
"title": "MCP Appium - Mobile Development and Automation Server",
|
|
5
5
|
"description": "MCP server for Appium mobile automation on iOS and Android devices with test creation tools.",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.15.0",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "appium-mcp",
|
|
11
|
-
"version": "1.
|
|
11
|
+
"version": "1.15.0",
|
|
12
12
|
"transport": {
|
|
13
13
|
"type": "stdio"
|
|
14
14
|
}
|
package/src/tools/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ import dragAndDrop from './interactions/drag-and-drop.js';
|
|
|
35
35
|
import setValue from './interactions/set-value.js';
|
|
36
36
|
import getText from './interactions/get-text.js';
|
|
37
37
|
import getPageSource from './interactions/get-page-source.js';
|
|
38
|
+
import handleAlert from './interactions/handle-alert.js';
|
|
38
39
|
import { screenshot, elementScreenshot } from './interactions/screenshot.js';
|
|
39
40
|
import activateApp from './app-management/activate-app.js';
|
|
40
41
|
import installApp from './app-management/install-app.js';
|
|
@@ -136,6 +137,7 @@ export default function registerTools(server: FastMCP): void {
|
|
|
136
137
|
setValue(server);
|
|
137
138
|
getText(server);
|
|
138
139
|
getPageSource(server);
|
|
140
|
+
handleAlert(server);
|
|
139
141
|
screenshot(server);
|
|
140
142
|
elementScreenshot(server);
|
|
141
143
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { FastMCP } from 'fastmcp';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { generateAllElementLocators } from '../../locators/generate-all-locators.js';
|
|
4
|
+
import { getDriver, getPlatformName, PLATFORM } from '../../session-store.js';
|
|
5
|
+
|
|
6
|
+
export const handleAlertSchema = z.object({
|
|
7
|
+
action: z
|
|
8
|
+
.enum(['accept', 'dismiss'])
|
|
9
|
+
.describe('Action to perform on the alert: accept or dismiss'),
|
|
10
|
+
buttonLabel: z
|
|
11
|
+
.string()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe(
|
|
14
|
+
`Optional label of the button to click. Common permission dialog buttons:
|
|
15
|
+
Android: "While using the app", "Only this time", "Don't allow"
|
|
16
|
+
iOS: "Always" or "Allow Always", "Once" or "Allow Once", "Don't allow"
|
|
17
|
+
Standard: "OK", "Cancel", "Allow", "Deny"
|
|
18
|
+
If not provided, uses default button based on action.
|
|
19
|
+
Use appium_get_page_source or generate_locators to inspect the screen and discover exact labels.`
|
|
20
|
+
),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const ANDROID_LOCATOR_STRATEGY_ORDER = [
|
|
24
|
+
'id',
|
|
25
|
+
'accessibility id',
|
|
26
|
+
'xpath',
|
|
27
|
+
'-android uiautomator',
|
|
28
|
+
'class name',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
async function handleAndroidAlert(
|
|
32
|
+
driver: any,
|
|
33
|
+
action: string,
|
|
34
|
+
buttonLabel?: string
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
if (buttonLabel) {
|
|
37
|
+
const pageSource = await driver.getPageSource();
|
|
38
|
+
const elements = generateAllElementLocators(
|
|
39
|
+
pageSource,
|
|
40
|
+
true,
|
|
41
|
+
'uiautomator2',
|
|
42
|
+
{
|
|
43
|
+
fetchableOnly: true,
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
const normalizedLabel = buttonLabel.trim();
|
|
47
|
+
const match =
|
|
48
|
+
elements.find(
|
|
49
|
+
(el) =>
|
|
50
|
+
(el.text?.trim() === normalizedLabel ||
|
|
51
|
+
el.contentDesc?.trim() === normalizedLabel) &&
|
|
52
|
+
el.clickable
|
|
53
|
+
) ??
|
|
54
|
+
elements.find(
|
|
55
|
+
(el) =>
|
|
56
|
+
el.text?.trim() === normalizedLabel ||
|
|
57
|
+
el.contentDesc?.trim() === normalizedLabel
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (!match) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`No element found with text or content-desc "${buttonLabel}"`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let button: any = null;
|
|
67
|
+
for (const strategy of ANDROID_LOCATOR_STRATEGY_ORDER) {
|
|
68
|
+
const selector = match.locators[strategy];
|
|
69
|
+
if (!selector) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
button = await driver.findElement(strategy, selector);
|
|
74
|
+
break;
|
|
75
|
+
} catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!button) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'Could not find element with any generated locator; it may have disappeared'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
const buttonUUID = button.ELEMENT || button;
|
|
85
|
+
await driver.click(buttonUUID);
|
|
86
|
+
} else {
|
|
87
|
+
if (action === 'accept') {
|
|
88
|
+
await driver.execute('mobile: acceptAlert', {});
|
|
89
|
+
} else {
|
|
90
|
+
await driver.execute('mobile: dismissAlert', {});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function handleiOSAlert(
|
|
96
|
+
driver: any,
|
|
97
|
+
action: string,
|
|
98
|
+
buttonLabel?: string
|
|
99
|
+
): Promise<void> {
|
|
100
|
+
const params: any = { action };
|
|
101
|
+
if (buttonLabel) {
|
|
102
|
+
params.buttonLabel = buttonLabel;
|
|
103
|
+
}
|
|
104
|
+
await driver.execute('mobile: alert', params);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default function handleAlert(server: FastMCP): void {
|
|
108
|
+
server.addTool({
|
|
109
|
+
name: 'appium_handle_alert',
|
|
110
|
+
description: `Handle system alerts or dialogs that do not belong to the app.
|
|
111
|
+
Use this to dismiss or accept alerts programmatically instead of using autoDismissAlerts capability.
|
|
112
|
+
Supports permission dialogs with buttons like:
|
|
113
|
+
- Android: "While using the app", "Only this time", "Don't allow"
|
|
114
|
+
- iOS: "Always", "Allow Once", "Don't allow"
|
|
115
|
+
For iOS: Uses mobile: alert execute command.
|
|
116
|
+
For Android: Uses mobile: acceptAlert/dismissAlert or searches the current page source for an element whose text or content-desc matches the label, then uses generated locators to find and click it (no hardcoded resource IDs or XPaths).
|
|
117
|
+
If no alert is present, the error is caught and returned gracefully.
|
|
118
|
+
To discover button labels and screen structure first, use appium_get_page_source (XML hierarchy) or generate_locators (interactable elements with text/content-desc).`,
|
|
119
|
+
parameters: handleAlertSchema,
|
|
120
|
+
annotations: {
|
|
121
|
+
readOnlyHint: false,
|
|
122
|
+
openWorldHint: false,
|
|
123
|
+
},
|
|
124
|
+
execute: async (args: any, context: any): Promise<any> => {
|
|
125
|
+
const driver = getDriver();
|
|
126
|
+
if (!driver) {
|
|
127
|
+
throw new Error('No driver found');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const platform = getPlatformName(driver);
|
|
132
|
+
|
|
133
|
+
if (platform === PLATFORM.android) {
|
|
134
|
+
await handleAndroidAlert(driver, args.action, args.buttonLabel);
|
|
135
|
+
} else if (platform === PLATFORM.ios) {
|
|
136
|
+
await handleiOSAlert(driver, args.action, args.buttonLabel);
|
|
137
|
+
} else {
|
|
138
|
+
throw new Error(
|
|
139
|
+
`Unsupported platform: ${platform}. Only Android and iOS are supported.`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
content: [
|
|
145
|
+
{
|
|
146
|
+
type: 'text',
|
|
147
|
+
text: `Successfully ${args.action}ed alert${
|
|
148
|
+
args.buttonLabel ? ` with button "${args.buttonLabel}"` : ''
|
|
149
|
+
}`,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
} catch (err: any) {
|
|
154
|
+
const contextStr = args.buttonLabel
|
|
155
|
+
? `action=${args.action}, buttonLabel="${args.buttonLabel}"`
|
|
156
|
+
: `action=${args.action}`;
|
|
157
|
+
return {
|
|
158
|
+
content: [
|
|
159
|
+
{
|
|
160
|
+
type: 'text',
|
|
161
|
+
text: `Failed to handle alert (${contextStr}). err: ${err.toString()}`,
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|