Skip to main content
Glama

load_document

Load and analyze Markdown documents from file paths with configurable validation levels for structured content processing.

Instructions

        Load and analyze a Markdown document from a file path.
        
        Args:
            document_path: Path to the Markdown file (supports absolute, relative, and ~ expansion)
            validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE"
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
document_pathYes
validation_levelNoNORMAL

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary handler for the 'load_document' MCP tool in the enhanced server. Decorated with @self.mcp.tool() for automatic registration and schema inference. Loads document via processor, analyzes structure, and returns metadata including preview.
    @self.mcp.tool()
    def load_document(document_path: str, validation_level: str = "NORMAL") -> Dict[str, Any]:
        """Load a Markdown document from a file path (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)
            sections = editor.get_sections()
            content_preview = editor.to_markdown()[:200] + "..." if len(editor.to_markdown()) > 200 else editor.to_markdown()
            return {
                "success": True,
                "message": f"Successfully analyzed document at {document_path}",
                "document_path": document_path,
                "sections_count": len(sections),
                "content_preview": content_preview,
                "file_size": len(editor.to_markdown()),
                "stateless": True
            }
        except Exception as e:
            return self.processor.create_error_response(str(e), type(e).__name__)
  • Base handler for the 'load_document' MCP tool. Decorated with @self.mcp.tool() for registration. Performs validation level mapping, loads via processor, and returns structured response with document analysis.
    @self.mcp.tool()
    def load_document(document_path: str, validation_level: str = "NORMAL") -> Dict[str, Any]:
        """
        Load and analyze a Markdown document from a file path.
        
        Args:
            document_path: Path to the Markdown file (supports absolute, relative, and ~ expansion)
            validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE"
        """
        try:
            # Convert string validation level to enum
            validation_map = {
                "STRICT": ValidationLevel.STRICT,
                "NORMAL": ValidationLevel.NORMAL,
                "PERMISSIVE": ValidationLevel.PERMISSIVE
            }
            validation_enum = validation_map.get(validation_level.upper(), ValidationLevel.NORMAL)
            
            # Load document without server state
            editor = self.processor.load_document(document_path, validation_enum)
            sections = editor.get_sections()
            content_preview = editor.to_markdown()[:200] + "..." if len(editor.to_markdown()) > 200 else editor.to_markdown()
            
            return {
                "success": True,
                "message": f"Successfully analyzed document at {document_path}",
                "document_path": document_path,
                "sections_count": len(sections),
                "content_preview": content_preview,
                "file_size": len(editor.to_markdown()),
                "stateless": True
            }
            
        except Exception as e:
            return self.processor.create_error_response(str(e), type(e).__name__)
  • Core helper function that implements document loading logic: path resolution, file validation, content reading with encoding fallback, and instantiation of SafeMarkdownEditor. Invoked by MCP tool handlers.
    def load_document(document_path: str, validation_level: ValidationLevel = ValidationLevel.NORMAL) -> SafeMarkdownEditor:
        """Load a document and create a SafeMarkdownEditor instance."""
        resolved_path = StatelessMarkdownProcessor.resolve_path(document_path)
        StatelessMarkdownProcessor.validate_file_path(resolved_path, must_exist=True, must_be_file=True)
        
        # Read the file content
        try:
            content = resolved_path.read_text(encoding='utf-8')
        except UnicodeDecodeError:
            # Try with different encodings
            for encoding in ['utf-8-sig', 'latin1', 'cp1252']:
                try:
                    content = resolved_path.read_text(encoding=encoding)
                    break
                except UnicodeDecodeError:
                    continue
            else:
                raise ValueError(f"Could not decode file {resolved_path} with any supported encoding")
        
        # Create editor instance
        editor = SafeMarkdownEditor(
            markdown_text=content,
            validation_level=validation_level
        )
        
        return editor
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool loads and analyzes a document, implying read-only operations, but doesn't disclose critical behaviors such as error handling (e.g., what happens if the file doesn't exist), performance aspects (e.g., file size limits), or analysis specifics (e.g., what 'analyze' entails). This leaves significant gaps in understanding how the tool behaves beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core purpose ('Load and analyze a Markdown document from a file path') followed by parameter details in a structured 'Args' section. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is partially complete. It covers the purpose and parameters well, but lacks behavioral context (e.g., error handling, analysis output) and usage guidelines. The presence of an output schema means return values are documented elsewhere, so the description doesn't need to explain them, but overall gaps in transparency and guidelines reduce completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains that 'document_path' supports 'absolute, relative, and ~ expansion', clarifying usage beyond the schema's generic 'string' type, and defines 'validation_level' options ('STRICT', 'NORMAL', 'PERMISSIVE') with a default implied by 'NORMAL' in the schema. This compensates well for the low schema coverage, though it doesn't detail what each validation level means.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('load and analyze') and resource ('Markdown document from a file path'), distinguishing it from siblings like 'get_document' (which likely retrieves without analysis) or 'analyze_document' (which may analyze without loading). However, it doesn't explicitly differentiate from 'get_document' in terms of loading vs. retrieving, leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_document' or 'analyze_document'. It mentions loading and analyzing, but doesn't specify prerequisites (e.g., file existence), exclusions, or comparative contexts with sibling tools, leaving the agent to infer usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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