Skip to main content
Glama

navigate_section

Navigate document sections to find parent, sibling, and child relationships for better document comprehension and analysis.

Instructions

Get navigation context for a section (parent, siblings, children).

Args:
    doc_id: Document identifier
    section_id: Section ID to navigate to

Returns:
    Navigation context with related sections

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes
section_idYes

Implementation Reference

  • MCP tool handler and registration for the 'navigate_section' tool. Includes input schema via type hints and docstring, delegates core logic to DocumentNavigator.navigate.
    @mcp.tool()
    def navigate_section(doc_id: str, section_id: str) -> str:
        """Get navigation context for a section (parent, siblings, children).
    
        Args:
            doc_id: Document identifier
            section_id: Section ID to navigate to
    
        Returns:
            Navigation context with related sections
        """
        return navigator.navigate(doc_id, section_id.strip("#"))
  • Core implementation of section navigation in DocumentNavigator, providing formatted output with current section, breadcrumb path, parent, siblings, and subsections.
    def navigate(self, doc_id: str, section_id: str) -> str:
        """Get navigation context as formatted string."""
        document = self.get_document(doc_id)
        if not document:
            return f"Document '{doc_id}' not found"
    
        node = document.get_node(section_id)
        if not node:
            return f"Section '{section_id}' not found"
    
        output = f"Current: {node.title or node.id}\n"
    
        # Build breadcrumbs
        ancestors = []
        current = node.parent
        while current and current.type != "document":
            if current.type == "heading":
                ancestors.append(current)
            current = current.parent
    
        if ancestors:
            breadcrumb_path = " > ".join([a.title for a in reversed(ancestors)])
            output += f"Path: {breadcrumb_path} > {node.title or node.id}\n"
    
        # Find parent
        if node.parent and node.parent.type == "heading":
            output += f"Parent: {node.parent.title}\n"
    
        # Find siblings (same level headings)
        if node.parent:
            siblings = [
                child for child in node.parent.children if child.type == "heading"
            ]
            if len(siblings) > 1:
                output += "Siblings:\n"
                for sibling in siblings:
                    marker = "→ " if sibling.id == node.id else "  "
                    output += f"{marker}{sibling.title} (#{sibling.id})\n"
    
        # Find children (direct child headings)
        children = [child for child in node.children if child.type == "heading"]
        if children:
            output += "Subsections:\n"
            for child in children:
                output += f"  {child.title} (#{child.id})\n"
    
        return output

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/shenyimings/DocNav-MCP'

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