get_section
Extract specific sections from Markdown documents by ID to retrieve targeted content quickly. Supports configurable validation levels for document integrity.
Instructions
Get a specific section by ID.
Args:
document_path: Path to the Markdown file
section_id: The section ID to retrieve
validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_path | Yes | ||
| section_id | Yes | ||
| validation_level | No | NORMAL |
Implementation Reference
- The MCP tool handler for 'get_section'. Loads the document using StatelessMarkdownProcessor, retrieves the SectionReference by ID using SafeMarkdownEditor.get_section_by_id, extracts the full section content from the markdown lines using line_start and line_end, and returns a structured JSON response with success status and section details.def get_section(document_path: str, section_id: str, validation_level: str = "NORMAL") -> Dict[str, Any]: """ Get a specific section by ID. Args: document_path: Path to the Markdown file section_id: The section ID to retrieve 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) section_ref = editor.get_section_by_id(section_id) if not section_ref: return { "success": False, "error": f"Section with ID '{section_id}' not found", "suggestions": ["Use list_sections to see available sections"] } # Extract section content using line ranges full_content = editor.to_markdown() lines = full_content.split('\n') section_lines = lines[section_ref.line_start:section_ref.line_end+1] section_content = '\n'.join(section_lines) return { "success": True, "section": { "id": section_ref.id, "title": section_ref.title, "level": section_ref.level, "content": section_content, "line_start": section_ref.line_start, "line_end": section_ref.line_end } } except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)
- Helper method in SafeMarkdownEditor that retrieves a SectionReference by its stable section_id. Builds current sections via _build_section_references() and returns the matching one or None. Used by the get_section tool handler.def get_section_by_id(self, section_id: str) -> Optional[SectionReference]: """ Find section by stable identifier. Args: section_id: Stable section identifier Returns: SectionReference if found, None otherwise Complexity: O(n) where n is number of sections """ with self._lock: sections = self._build_section_references() for section in sections: if section.id == section_id: return section return None
- src/quantalogic_markdown_mcp/mcp_server.py:242-285 (registration)MCP tool registration via @self.mcp.tool() decorator on the get_section handler function in MarkdownMCPServer._setup_tools().def get_section(document_path: str, section_id: str, validation_level: str = "NORMAL") -> Dict[str, Any]: """ Get a specific section by ID. Args: document_path: Path to the Markdown file section_id: The section ID to retrieve 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) section_ref = editor.get_section_by_id(section_id) if not section_ref: return { "success": False, "error": f"Section with ID '{section_id}' not found", "suggestions": ["Use list_sections to see available sections"] } # Extract section content using line ranges full_content = editor.to_markdown() lines = full_content.split('\n') section_lines = lines[section_ref.line_start:section_ref.line_end+1] section_content = '\n'.join(section_lines) return { "success": True, "section": { "id": section_ref.id, "title": section_ref.title, "level": section_ref.level, "content": section_content, "line_start": section_ref.line_start, "line_end": section_ref.line_end } } except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)
- Related helper method that returns all SectionReference objects by calling _build_section_references(). Called indirectly via get_section_by_id.def get_sections(self) -> List[SectionReference]: """ Get immutable references to all document sections. Returns: List of SectionReference objects in document order Complexity: O(n) where n is number of headings Thread Safety: Safe for concurrent access """ with self._lock: return self._build_section_references()