Skip to main content
Glama

get_document

Retrieve and validate Markdown document content and structure from a specified file path to enable editing operations.

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
NameRequiredDescriptionDefault
document_pathYes
validation_levelNoNORMAL

Implementation Reference

  • Primary handler for the 'get_document' tool, decorated with @mcp.tool() for registration. Loads document content and structure using StatelessMarkdownProcessor and returns full markdown content, section list, and metadata.
    @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__)
  • Internal helper implementation for 'get_document' used in synchronous tool calls via call_tool_sync. Similar logic to main handler but wrapped in execute_operation.
    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)
  • Alternative handler for 'get_document' in the enhanced MCP server subclass, providing document content and statistics.
    @self.mcp.tool()
    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__)

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/quantalogic/quantalogic_markdown_mcp'

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