@nbakka/mcp-appium 1.0.26 → 1.0.27

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 +16 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbakka/mcp-appium",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
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,44 +147,40 @@ 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 XML including duplicates",
150
+ "Get all visible texts from screen JSON 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 xml = response.data;
157
-
158
- const parsed = await parseStringPromise(xml, { explicitArray: false, mergeAttrs: true });
159
-
160
- function collectTexts(node, texts = []) {
156
+ const data = response.data;
157
+ console.log(response.data);
158
+ function collectTextsFromJson(node, texts = []) {
161
159
  if (!node) return texts;
162
-
163
160
  if (Array.isArray(node)) {
164
- node.forEach(child => collectTexts(child, texts));
161
+ node.forEach(child => collectTextsFromJson(child, texts));
165
162
  return texts;
166
163
  }
167
-
168
- if (node.text && node.text.trim() !== "") {
169
- texts.push(node.text.trim());
170
- }
171
-
172
- if (node.node) collectTexts(node.node, texts);
173
- else if (node.child) collectTexts(node.child, texts);
174
- else {
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
+ }
175
171
  for (const key in node) {
176
- if (typeof node[key] === "object") {
177
- collectTexts(node[key], texts);
172
+ if (key !== "text" && key !== "children" && typeof node[key] === "object") {
173
+ collectTextsFromJson(node[key], texts);
178
174
  }
179
175
  }
180
176
  }
181
177
  return texts;
182
178
  }
183
179
 
184
- const allTexts = collectTexts(parsed);
180
+ const allTexts = collectTextsFromJson(data);
185
181
  return { content: [{ type: "json", json: allTexts }] };
186
182
  } catch (e) {
187
- return { content: [{ type: "text", text: `Error fetching or parsing XML: ${e.message}` }] };
183
+ return { content: [{ type: "text", text: `Error fetching or parsing source: ${e.message}` }] };
188
184
  }
189
185
  }
190
186
  );