list_sections
Extract and display all sections from a Markdown document to help users navigate content and understand document structure.
Instructions
List all sections in the document.
Args:
document_path: Path to the Markdown file
validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_path | Yes | ||
| validation_level | No | NORMAL |
Implementation Reference
- The primary handler function for the 'list_sections' MCP tool. It loads the document using StatelessMarkdownProcessor, retrieves sections, extracts content previews using line ranges, and returns a structured list of sections with metadata.def list_sections(document_path: str, validation_level: str = "NORMAL") -> Dict[str, Any]: """ List all sections in the document. Args: document_path: Path to the Markdown file validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE" """ try: validation_map = {"STRICT": ValidationLevel.STRICT, "NORMAL": ValidationLevel.NORMAL, "PERMISSIVE": ValidationLevel.PERMISSIVE} validation_enum = validation_map.get(validation_level.upper(), ValidationLevel.NORMAL) editor = self.processor.load_document(document_path, validation_enum) sections = editor.get_sections() # Get full content to extract section content full_content = editor.to_markdown() lines = full_content.split('\n') # Build section list with content preview section_list = [] for section in sections: # Extract section content using line ranges try: section_lines = lines[section.line_start:section.line_end+1] section_content = '\n'.join(section_lines) content_preview = section_content[:100] + "..." if len(section_content) > 100 else section_content except (IndexError, AttributeError): # Fallback if line extraction fails content_preview = "Content preview not available" section_list.append({ "id": section.id, "title": section.title, "level": section.level, "line_start": section.line_start, "line_end": section.line_end, "content_preview": content_preview }) return { "success": True, "sections": section_list, "total_sections": len(sections) } except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)