Skip to main content
Glama

navigate_dom_path

Navigate to specific DOM elements using dot notation paths. Extract content and element information from JSON-structured pages.

Instructions

Navigate to specific elements in DOM JSON using dot notation paths (e.g., 'body.main.article[0].paragraphs[2]'). Extracts content and provides element information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_idYesUnique identifier of the page to navigate
pathYesDot notation path to navigate (e.g., 'body.main.article[0].paragraphs[2]')
extract_contentNoWhether to extract text content from the target element
include_childrenNoWhether to include child elements in the response

Implementation Reference

  • Main handler function for the navigate_dom_path tool. Validates args, loads page data from DB, navigates the DOM path using the helper, and returns element information (tagName, textContent, attributes, children).
    async navigateDOMPath(args: any): Promise<any> {
      try {
        const validatedArgs = NavigateDOMPathSchema.parse(args);
        logger.info(`Navigating DOM path: ${validatedArgs.path} for page: ${validatedArgs.page_id}`);
    
        // Load page data from database
        const page = await this.pagesRepo.findById(validatedArgs.page_id);
        if (!page) {
          throw new Error(`Page with ID ${validatedArgs.page_id} not found`);
        }
    
        if (!page.domJsonContent) {
          throw new Error(`No DOM content available for page ${validatedArgs.page_id}`);
        }
    
        const domJson = page.domJsonContent;
    
        // Navigate to the specified path
        const targetElement = this.navigatePath(domJson, validatedArgs.path);
    
        const result = {
          page_id: validatedArgs.page_id,
          path: validatedArgs.path,
          element: {
            tagName: targetElement?.tagName,
            textContent: validatedArgs.extract_content ? targetElement?.textContent : undefined,
            attributes: targetElement?.attributes,
            children: validatedArgs.include_children ? targetElement?.children : undefined,
          },
          navigation_info: {
            element_type: targetElement?.tagName,
            has_children: targetElement?.children && Array.isArray(targetElement.children) && targetElement.children.length > 0,
            text_length: targetElement?.textContent?.length || 0,
            attribute_count: targetElement?.attributes ? Object.keys(targetElement.attributes).length : 0,
          }
        };
    
        return result;
    
      } catch (error) {
        logger.error("Error navigating DOM path:", error);
        throw new Error(`Failed to navigate DOM path: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Private helper navigatePath that traverses a DOM JSON object following a parsed dot-notation path, resolving property names and array indices.
    private navigatePath(domJson: any, path: string): any {
      const segments = this.parsePath(path);
      let current = domJson;
    
      for (const segment of segments) {
        if (segment.type === 'property') {
          if (current && typeof current === 'object' && segment.name in current) {
            current = current[segment.name];
          } else {
            throw new Error(`Property '${segment.name}' not found at path: ${path}`);
          }
        } else if (segment.type === 'index') {
          if (Array.isArray(current) && segment.index < current.length) {
            current = current[segment.index];
          } else {
            throw new Error(`Index ${segment.index} out of bounds at path: ${path}`);
          }
        }
      }
    
      return current;
    }
  • Private helper parsePath that splits a dot-notation path string into segments (property names and array indices like 'body.main.article[0]').
    private parsePath(path: string): Array<{ type: 'property' | 'index'; name?: string; index?: number }> {
      const segments: Array<{ type: 'property' | 'index'; name?: string; index?: number }> = [];
      const parts = path.split('.');
    
      for (const part of parts) {
        const arrayMatch = part.match(/^(.+)\[(\d+)\]$/);
        if (arrayMatch) {
          // Property with array index
          segments.push({ type: 'property', name: arrayMatch[1] });
          segments.push({ type: 'index', index: parseInt(arrayMatch[2]) });
        } else {
          // Simple property
          segments.push({ type: 'property', name: part });
        }
      }
    
      return segments;
    }
  • Local Zod schema (NavigateDOMPathSchema) defining input parameters: page_id, path (dot notation), extract_content (default true), include_children (default false).
    const NavigateDOMPathSchema = z.object({
      page_id: z.string().describe("Unique identifier of the page to navigate"),
      path: z.string().describe("Dot notation path to navigate (e.g., 'body.main.article[0].paragraphs[2]')"),
      extract_content: z.boolean().default(true).describe("Whether to extract text content from the target element"),
      include_children: z.boolean().default(false).describe("Whether to include child elements in the response"),
    });
  • Registration of the 'navigate_dom_path' tool in the getTools() method, mapping name, description, inputSchema, and handler (navigateDOMPath).
    {
      name: "navigate_dom_path", 
      description: "Navigate to specific elements in DOM JSON using dot notation paths (e.g., 'body.main.article[0].paragraphs[2]'). Extracts content and provides element information.",
      inputSchema: zodToJsonSchema(NavigateDOMPathSchema),
      handler: this.navigateDOMPath.bind(this)
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states navigation and extraction but omits details on error handling (e.g., invalid path), side effects (none implied), or what 'element information' includes. Read-only nature is not confirmed.

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

Conciseness4/5

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

The description is concise with a single sentence and a helpful example. It avoids redundancy but lacks structured details like return format or error responses.

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 4 parameters, no output schema, and no annotations, the description is insufficient. It does not explain what 'element information' entails, how to obtain paths, or what happens with invalid inputs. Sibling tools (e.g., analyze_dom_structure) are not referenced.

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?

All parameters have descriptions in the schema (100% coverage), so the baseline is 3. The description adds an example path but does not provide additional semantic meaning beyond the schema.

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

Purpose5/5

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

The description clearly states the tool navigates to specific elements in DOM JSON using dot notation paths, with an example. It distinguishes from siblings like search_dom_elements (search) and analyze_dom_structure (analysis) by focusing on direct navigation to a known path.

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 when a specific DOM path is known but does not provide explicit guidelines on when to use this tool versus siblings, nor does it mention prerequisites or alternatives.

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/ZachHandley/ZMCPTools'

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