@nbakka/mcp-appium 1.0.27 → 1.0.30

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/package.json +2 -2
  2. package/src/lib/server.js +27 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbakka/mcp-appium",
3
- "version": "1.0.27",
3
+ "version": "1.0.30",
4
4
  "description": "Selenium WebDriver MCP Server",
5
5
  "type": "module",
6
6
  "main": "src/lib/server.js",
@@ -21,4 +21,4 @@
21
21
  "yargs": "^17.7.2",
22
22
  "xml2js": "0.6.2"
23
23
  }
24
- }
24
+ }
package/src/lib/server.js CHANGED
@@ -147,40 +147,49 @@ server.tool(
147
147
  // Get visible text elements including duplicates
148
148
  server.tool(
149
149
  "get_visible_text_elements",
150
- "Get all visible texts from screen JSON source including duplicates",
150
+ "Get all visible texts from screen XML source including duplicates",
151
151
  {},
152
152
  async () => {
153
153
  if (!state.sessionId) return { content: [{ type: "text", text: "No active session" }] };
154
154
  try {
155
155
  const response = await axios.get(`${APPIUM_URL}/session/${state.sessionId}/source`);
156
- const data = response.data;
157
- console.log(response.data);
158
- function collectTextsFromJson(node, texts = []) {
156
+
157
+ const xml = response.data.value;
158
+
159
+ if (!xml || typeof xml !== "string") {
160
+ throw new Error("No XML source found in response");
161
+ }
162
+ console.log(response.data.value);
163
+
164
+ const parsed = await parseStringPromise(xml, { explicitArray: false, mergeAttrs: true });
165
+
166
+ function collectTextsFromXml(node, texts = []) {
159
167
  if (!node) return texts;
168
+
169
+ // If array, recurse each element
160
170
  if (Array.isArray(node)) {
161
- node.forEach(child => collectTextsFromJson(child, texts));
171
+ node.forEach(child => collectTextsFromXml(child, texts));
162
172
  return texts;
163
173
  }
164
- if (typeof node === "object") {
165
- if (node.text && node.text.trim() !== "") {
166
- texts.push(node.text.trim());
167
- }
168
- if (node.children) {
169
- collectTextsFromJson(node.children, texts);
170
- }
171
- for (const key in node) {
172
- if (key !== "text" && key !== "children" && typeof node[key] === "object") {
173
- collectTextsFromJson(node[key], texts);
174
- }
174
+
175
+ // If node has 'text' attribute with non-empty value, collect it
176
+ if (node.text && node.text.trim() !== "") {
177
+ texts.push(node.text.trim());
178
+ }
179
+
180
+ // Recurse into all children nodes
181
+ for (const key in node) {
182
+ if (key !== "text" && typeof node[key] === "object") {
183
+ collectTextsFromXml(node[key], texts);
175
184
  }
176
185
  }
177
186
  return texts;
178
187
  }
179
188
 
180
- const allTexts = collectTextsFromJson(data);
189
+ const allTexts = collectTextsFromXml(parsed);
181
190
  return { content: [{ type: "json", json: allTexts }] };
182
191
  } catch (e) {
183
- return { content: [{ type: "text", text: `Error fetching or parsing source: ${e.message}` }] };
192
+ return { content: [{ type: "text", text: `Error fetching or parsing source XML: ${e.message}` }] };
184
193
  }
185
194
  }
186
195
  );