get_document
Retrieve and validate the full content and structure of a Markdown file to ensure compliance with specified validation levels: STRICT, NORMAL, or PERMISSIVE.
Instructions
Get the complete document content and structure.
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
- Primary MCP tool handler for 'get_document'. Decorated with @self.mcp.tool(), loads the Markdown document using the processor, retrieves full content and detailed section information, and returns a structured JSON response including content, sections metadata, and statistics.@self.mcp.tool() def get_document(document_path: str, validation_level: str = "NORMAL") -> Dict[str, Any]: """ Get the complete document content and structure. 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() content = editor.to_markdown() return { "success": True, "document_path": document_path, "content": content, "sections": [ { "id": section.id, "title": section.title, "level": section.level, "line_start": section.line_start, "line_end": section.line_end } for section in sections ], "metadata": { "total_sections": len(sections), "total_lines": len(content.split('\n')), "file_size": len(content), "validation_level": validation_level } } except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)
- Helper implementation _get_document_impl used internally for synchronous tool calls via call_tool_sync. Wraps document retrieval logic in an EditResult operation and executes via processor.def _get_document_impl(self, document_path: str) -> Dict[str, Any]: """Implementation for get_document tool.""" def operation(editor): from .safe_editor_types import EditResult, EditOperation content = editor.to_markdown() sections = editor.get_sections() document_data = { "content": content, "sections": [ { "id": section.id, "title": section.title, "level": section.level, "start_line": section.line_start, "end_line": section.line_end } for section in sections ], "word_count": len(content.split()), "character_count": len(content) } return EditResult( success=True, operation=EditOperation.BATCH_OPERATIONS, modified_sections=[], errors=[], warnings=[], metadata=document_data ) return self.processor.execute_operation(document_path, operation, auto_save=False)
- src/quantalogic_markdown_mcp/mcp_server.py:618-628 (registration)Internal registration/mapping of 'get_document' to its implementation in the tools dictionary for call_tool_sync method, used in testing and direct calls."load_document": self._load_document_impl, "list_sections": self._list_sections_impl, "get_section": self._get_section_impl, "insert_section": self._insert_section_impl, "update_section": self._update_section_impl, "delete_section": self._delete_section_impl, "move_section": self._move_section_impl, "get_document": self._get_document_impl, "save_document": self._save_document_impl, "analyze_document": self._analyze_document_impl, }
- Alternative handler for 'get_document' in the enhanced MCP server variant. Similar logic but uses editor.get_statistics() for metadata.def get_document(document_path: str, validation_level: str = "NORMAL") -> Dict[str, Any]: """Get the complete document (stateless only).""" 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) content = editor.to_markdown() statistics = editor.get_statistics() return { "success": True, "document": content, "statistics": { "total_sections": statistics.total_sections, "total_lines": statistics.total_lines, "word_count": statistics.word_count, "character_count": statistics.character_count }, "document_path": document_path, "stateless": True } except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)