@nbakka/mcp-appium 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/lib/server.js +83 -2
  2. package/package.json +2 -2
package/lib/server.js CHANGED
@@ -14,6 +14,7 @@ const getAgentVersion = () => {
14
14
  const json = require("../package.json");
15
15
  return json.version;
16
16
  };
17
+
17
18
  const getLatestAgentVersion = async () => {
18
19
  const response = await fetch("https://api.github.com/repos/mobile-next/mobile-mcp/tags?per_page=1");
19
20
  const json = await response.json();
@@ -146,11 +147,10 @@ tool("mobile_click_on_element_by_text", "Click on the screen element identified
146
147
  }, async ({ text }) => {
147
148
  requireRobot();
148
149
  const xpath = `//*[@text="${text}"]`;
149
- const element = await robot.findElementByXPath(xpath);
150
+ const element = await robot.clickByXPath(xpath);
150
151
  if (!element) {
151
152
  throw new Error(`Element with text "${text}" not found`);
152
153
  }
153
- await element.click();
154
154
  // Wait for 2 seconds after click
155
155
  await new Promise(resolve => setTimeout(resolve, 2000));
156
156
  return `Clicked on element with text: "${text}"`;
@@ -223,4 +223,85 @@ await new Promise(resolve => setTimeout(resolve, 5000));
223
223
  checkForLatestAgentVersion().then();
224
224
  return server;
225
225
  };
226
+
227
+ tool(
228
+ "mobile_create_session",
229
+ "create a mobile session once so that session id can be used in other tools where it is needed",
230
+ {},
231
+ async () => {
232
+ const capabilities = {
233
+ platformName: "Android",
234
+ "appium:udid": "emulator-5554",
235
+ "appium:automationName": "UiAutomator2",
236
+ "appium:noReset": true,
237
+ "appium:appPackage": "com.locon.housing",
238
+ "appium:appActivity": "com.locon.housing.presentation.MainActivity",
239
+ };
240
+
241
+ const payload = {
242
+ capabilities: {
243
+ firstMatch: [{}],
244
+ alwaysMatch: capabilities,
245
+ },
246
+ };
247
+
248
+ const response = await fetch("http://localhost:4723/session", {
249
+ method: "POST",
250
+ headers: { "Content-Type": "application/json" },
251
+ body: JSON.stringify(payload),
252
+ });
253
+
254
+ if (!response.ok) {
255
+ throw new Error(`Failed to create session: ${response.statusText}`);
256
+ }
257
+
258
+ const json = await response.json();
259
+ return `Session created with sessionId: ${json.sessionId}`;
260
+ }
261
+ );
262
+
263
+
264
+ tool(
265
+ "mobile_click_using_xpath",
266
+ "Click an element identified by text using path",
267
+ {
268
+ sessionId: zod_1.z.string().describe("Appium session ID"),
269
+ text: zod_1.z.string().describe("Visible text of the element to click"),
270
+ },
271
+ async ({ sessionId, text }) => {
272
+ const xpath = `//*[@text="${text}"]`;
273
+ const clickUrl = `http://localhost:4723/session/${sessionId}/element`;
274
+
275
+ // Find element
276
+ const findResponse = await fetch(clickUrl, {
277
+ method: "POST",
278
+ headers: { "Content-Type": "application/json" },
279
+ body: JSON.stringify({ using: "xpath", value: xpath }),
280
+ });
281
+
282
+ if (!findResponse.ok) {
283
+ throw new Error(`Failed to find element: ${findResponse.statusText}`);
284
+ }
285
+
286
+ const findJson = await findResponse.json();
287
+ if (!findJson.value || !findJson.value.elementId) {
288
+ throw new Error(`Element with text "${text}" not found`);
289
+ }
290
+
291
+ const elementId = findJson.value.elementId;
292
+
293
+ // Click element
294
+ const clickElementUrl = `http://localhost:4723/session/${sessionId}/element/${elementId}/click`;
295
+ const clickResponse = await fetch(clickElementUrl, { method: "POST" });
296
+
297
+ if (!clickResponse.ok) {
298
+ throw new Error(`Failed to click element: ${clickResponse.statusText}`);
299
+ }
300
+
301
+ // Optional wait after click
302
+ await new Promise((resolve) => setTimeout(resolve, 2000));
303
+
304
+ return `Clicked on element with text: "${text}" in session: ${sessionId}`;
305
+ }
306
+ );
226
307
  exports.createMcpServer = createMcpServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbakka/mcp-appium",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Appium MCP",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "main": "index.js",
45
45
  "bin": {
46
- "mcp-server-mobile": "lib/index.js"
46
+ "mcp-appium": "lib/index.js"
47
47
  },
48
48
  "directories": {
49
49
  "lib": "lib"