Skip to main content
Glama

xcresult_get_ui_element

Extract detailed information about a specific UI element from an Xcode UI hierarchy JSON file by providing its index, enabling targeted analysis of UI components during testing.

Instructions

Get full details of a specific UI element by index from a previously exported UI hierarchy JSON file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hierarchy_json_pathYesAbsolute path to the UI hierarchy JSON file (the full version saved by xcresult-get-ui-hierarchy)
element_indexYesIndex of the element to get details for (the "j" value from the slim hierarchy)
include_childrenNoWhether to include children in the response. Defaults to false.

Implementation Reference

  • Core handler implementation: reads UI hierarchy JSON, extracts flatElements[elementIndex], constructs result object with element details (type, label, raw, attributes, optional children/parent), returns as JSON text content.
    public static async xcresultGetUIElement(
      hierarchyJsonPath: string,
      elementIndex: number,
      includeChildren: boolean = false
    ): Promise<McpResult> {
      const fs = await import('fs');
      
      if (!fs.existsSync(hierarchyJsonPath)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `UI hierarchy JSON file not found: ${hierarchyJsonPath}`
        );
      }
    
      try {
        const hierarchyData = JSON.parse(fs.readFileSync(hierarchyJsonPath, 'utf8'));
        const flatElements = hierarchyData.flatElements || [];
        
        if (elementIndex < 0 || elementIndex >= flatElements.length) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Element index ${elementIndex} out of range. Available indices: 0-${flatElements.length - 1}`
          );
        }
    
        const element = flatElements[elementIndex];
        
        // Create result with full element details
        const result: any = {
          index: elementIndex,
          type: element.type,
          label: element.label,
          raw: element.raw,
          indentLevel: element.indentLevel,
          attributes: element.attributes || {}
        };
    
        if (includeChildren && element.children) {
          result.children = element.children;
        } else if (element.children) {
          result.childrenCount = element.children.length;
          result.hasChildren = true;
        }
    
        if (element.parent) {
          result.parent = element.parent;
        }
    
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(result)
          }]
        };
    
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to read UI element: ${errorMessage}`
        );
      }
    }
  • Input schema definition specifying required parameters: hierarchy_json_path (string), element_index (number), optional include_children (boolean). Used for tool validation and documentation.
    {
      name: 'xcresult_get_ui_element',
      description: 'Get full details of a specific UI element by index from a previously exported UI hierarchy JSON file',
      inputSchema: {
        type: 'object',
        properties: {
          hierarchy_json_path: {
            type: 'string',
            description: 'Absolute path to the UI hierarchy JSON file (the full version saved by xcresult-get-ui-hierarchy)',
          },
          element_index: {
            type: 'number',
            description: 'Index of the element to get details for (the "j" value from the slim hierarchy)',
          },
          include_children: {
            type: 'boolean',
            description: 'Whether to include children in the response. Defaults to false.',
          },
        },
        required: ['hierarchy_json_path', 'element_index'],
      },
    },
  • MCP server registration in CallToolRequestSchema handler: switch case dispatches to XCResultTools.xcresultGetUIElement after parameter validation.
    case 'xcresult_get_ui_element':
      if (!args.hierarchy_json_path) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: hierarchy_json_path`);
      }
      if (args.element_index === undefined) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: element_index`);
      }
      return await XCResultTools.xcresultGetUIElement(
        args.hierarchy_json_path as string,
        args.element_index as number,
        args.include_children as boolean | undefined
      );
  • Direct tool call registration in callToolDirect method: identical dispatch logic for CLI compatibility.
    case 'xcresult_get_ui_element':
      if (!args.hierarchy_json_path) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: hierarchy_json_path`);
      }
      if (args.element_index === undefined) {
        throw new McpError(ErrorCode.InvalidParams, `Missing required parameter: element_index`);
      }
      return await XCResultTools.xcresultGetUIElement(
        args.hierarchy_json_path as string,
        args.element_index as number,
        args.include_children as boolean | undefined
      );
  • Fallback schema definition in MCP library for tool listing when CLI is unavailable.
    name: 'xcresult_get_ui_element',
    description: 'Get full details of a specific UI element by index from a previously exported UI hierarchy JSON file',
    inputSchema: {
      type: 'object',
      properties: {
        hierarchy_json_path: {
          type: 'string',
          description: 'Absolute path to the UI hierarchy JSON file (the full version saved by xcresult-get-ui-hierarchy)',
        },
        element_index: {
          type: 'number',
          description: 'Index of the element to get details for (the "j" value from the slim hierarchy)',
        },
        include_children: {
          type: 'boolean',
          description: 'Whether to include children in the response. Defaults to false.',
        },
      },
      required: ['hierarchy_json_path', 'element_index'],
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions retrieving 'full details' but doesn't specify what those details include, potential errors (e.g., invalid index), or performance aspects. This is inadequate for a tool with no annotation coverage, as it lacks critical behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the key action and resource. There is no wasted verbiage, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete. It doesn't explain what 'full details' entail in the response, which is crucial for a tool that retrieves data. This gap makes it insufficient for the tool's complexity and lack of structured output information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond implying the hierarchy file comes from 'xcresult-get-ui-hierarchy,' but doesn't provide additional semantic context for the parameters. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get full details') and resource ('specific UI element by index from a previously exported UI hierarchy JSON file'), making the purpose understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'xcresult_get_ui_hierarchy' which exports the hierarchy file, so it misses the highest clarity score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by referencing a 'previously exported UI hierarchy JSON file,' suggesting it should be used after exporting with 'xcresult_get_ui_hierarchy.' However, it doesn't provide explicit when-to-use guidance, alternatives, or exclusions compared to other tools, leaving some ambiguity.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lapfelix/XcodeMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server