@nbakka/mcp-appium 1.0.27 → 1.0.28

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 +1 -1
  2. package/src/lib/server.js +20 -17
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.28",
4
4
  "description": "Selenium WebDriver MCP Server",
5
5
  "type": "module",
6
6
  "main": "src/lib/server.js",
package/src/lib/server.js CHANGED
@@ -147,40 +147,43 @@ 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;
156
+ const xml = response.data;
157
157
  console.log(response.data);
158
- function collectTextsFromJson(node, texts = []) {
158
+ const parsed = await parseStringPromise(xml, { explicitArray: false, mergeAttrs: true });
159
+
160
+ function collectTextsFromXml(node, texts = []) {
159
161
  if (!node) return texts;
162
+
163
+ // If array, recurse each element
160
164
  if (Array.isArray(node)) {
161
- node.forEach(child => collectTextsFromJson(child, texts));
165
+ node.forEach(child => collectTextsFromXml(child, texts));
162
166
  return texts;
163
167
  }
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
- }
168
+
169
+ // If node has 'text' attribute with non-empty value, collect it
170
+ if (node.text && node.text.trim() !== "") {
171
+ texts.push(node.text.trim());
172
+ }
173
+
174
+ // Recurse into all children nodes
175
+ for (const key in node) {
176
+ if (key !== "text" && typeof node[key] === "object") {
177
+ collectTextsFromXml(node[key], texts);
175
178
  }
176
179
  }
177
180
  return texts;
178
181
  }
179
182
 
180
- const allTexts = collectTextsFromJson(data);
183
+ const allTexts = collectTextsFromXml(parsed);
181
184
  return { content: [{ type: "json", json: allTexts }] };
182
185
  } catch (e) {
183
- return { content: [{ type: "text", text: `Error fetching or parsing source: ${e.message}` }] };
186
+ return { content: [{ type: "text", text: `Error fetching or parsing source XML: ${e.message}` }] };
184
187
  }
185
188
  }
186
189
  );