get_outline
Extract and display the table of contents from loaded documents to understand document structure and navigate content efficiently.
Instructions
Get document outline/table of contents.
Tips: First use this tool to understand document structure after you load a document.
Args:
doc_id: Document identifier
max_depth: Maximum heading depth to include, defaults to 3
Returns:
Formatted document outline
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | ||
| max_depth | No |
Implementation Reference
- server.py:54-67 (handler)MCP tool handler for 'get_outline'. This is the function executed when the tool is called, decorated with @mcp.tool() for automatic registration. It delegates to the navigator's implementation.@mcp.tool() def get_outline(doc_id: str, max_depth: int = 3) -> str: """Get document outline/table of contents. Tips: First use this tool to understand document structure after you load a document. Args: doc_id: Document identifier max_depth: Maximum heading depth to include, defaults to 3 Returns: Formatted document outline """ return navigator.get_outline(doc_id, max_depth)
- docnav/navigator.py:827-851 (helper)Core helper function in DocumentNavigator that implements the outline generation logic by recursively traversing the document's node tree, collecting headings up to the specified max_depth, and formatting them as a string.def get_outline(self, doc_id: str, max_depth: int = 3) -> str: """Get document outline.""" document = self.get_document(doc_id) if not document: return f"Document '{doc_id}' not found" # Create a simple outline from document nodes outline = [] def build_outline(node: DocumentNode, depth: int = 0) -> None: if depth > max_depth: return if node.type == "heading" and node.title: indent = " " * (depth - 1) if depth > 0 else "" outline.append(f"{indent}#{node.id} - {node.title}") for child in node.children: build_outline(child, depth + 1 if node.type == "heading" else depth) if document.root: build_outline(document.root) return "\n".join(outline)