Skip to main content
Glama

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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
  • 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()
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the basic action ('Get a specific section by ID') without mentioning any behavioral traits such as error handling, permissions required, rate limits, or what happens if the section doesn't exist. For a tool with no annotations, this is a significant gap in transparency.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by a structured 'Args' section. There's no wasted text, and the information is organized efficiently. A 5 would require even more conciseness or bullet-point formatting, but this is very good.

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 that there's an output schema (which handles return values), the description doesn't need to explain outputs. However, with 3 parameters, no annotations, and multiple sibling tools, the description is incomplete: it lacks usage guidelines and behavioral context. It's minimally adequate but has clear gaps, especially for a tool in a complex environment with many alternatives.

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 for all three parameters: it explains that 'document_path' is a 'Path to the Markdown file,' 'section_id' is 'The section ID to retrieve,' and 'validation_level' specifies 'Validation strictness' with enum values. Since schema description coverage is 0% (no schema descriptions), this fully compensates by providing clear parameter meanings beyond just the schema's titles and types.

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: 'Get a specific section by ID.' This is a specific verb+resource combination (get + section). However, it doesn't explicitly distinguish this tool from its siblings like 'get_document' or 'list_sections,' which would require a 5.

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. There are multiple sibling tools for document/section operations (e.g., get_document, list_sections, update_section), but the description doesn't mention any of them or specify contexts where get_section is preferred. This leaves the agent without usage direction.

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