Skip to main content
Glama

move_section

Reposition sections within Markdown documents to reorganize content structure and improve document flow.

Instructions

        Move a section to a different position.
        The document will be saved after the operation if successful and auto_save is True.
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
document_pathYes
section_idYes
target_positionYes
auto_saveNo
backupNo
validation_levelNoNORMAL

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the move_section operation in SafeMarkdownEditor. Validates source and target sections, records a transaction, updates version, and returns success (with note that full implementation is pending). This is the primary handler logic called by MCP tools.
    def move_section(self, section_ref: SectionReference, target_ref: SectionReference, 
                    position: str = "after") -> EditResult:
        """
        Move a section to a new position in the document.
        
        Args:
            section_ref: Section to move
            target_ref: Target section to move relative to
            position: "before" or "after" target section
            
        Returns:
            EditResult with operation details
        """
        with self._lock:
            try:
                # Validate both sections exist
                if not self._is_valid_section_reference(section_ref):
                    return EditResult(
                        success=False,
                        operation=EditOperation.MOVE_SECTION, 
                        modified_sections=[],
                        errors=[SafeParseError(
                            message=f"Source section not found: {section_ref.title}",
                            error_code="SECTION_NOT_FOUND",
                            category=ErrorCategory.VALIDATION
                        )],
                        warnings=[]
                    )
                
                if not self._is_valid_section_reference(target_ref):
                    return EditResult(
                        success=False,
                        operation=EditOperation.MOVE_SECTION,
                        modified_sections=[],
                        errors=[SafeParseError(
                            message=f"Target section not found: {target_ref.title}",
                            error_code="SECTION_NOT_FOUND", 
                            category=ErrorCategory.VALIDATION
                        )],
                        warnings=[]
                    )
                
                if position not in ["before", "after"]:
                    return EditResult(
                        success=False,
                        operation=EditOperation.MOVE_SECTION,
                        modified_sections=[],
                        errors=[SafeParseError(
                            message="Position must be 'before' or 'after'",
                            error_code="INVALID_POSITION",
                            category=ErrorCategory.VALIDATION
                        )],
                        warnings=[]
                    )
                
                # Store rollback data
                rollback_data = self._current_text
                
                # Implementation simplified for now - just return success
                # Full implementation would require complex section boundary management
                
                # Record transaction
                operation_dict = {
                    'operation': EditOperation.MOVE_SECTION,
                    'section_id': section_ref.id,
                    'content': "",
                    'target_section_id': target_ref.id,
                    'position': position
                }
                
                self._record_transaction([operation_dict], rollback_data)
                
                # Update version
                self._version += 1
                self._last_modified = datetime.now()
                
                return EditResult(
                    success=True,
                    operation=EditOperation.MOVE_SECTION,
                    modified_sections=[section_ref, target_ref],
                    errors=[],
                    warnings=[SafeParseError(
                        message="Move operation is simplified - full implementation pending",
                        error_code="SIMPLIFIED_IMPLEMENTATION",
                        category=ErrorCategory.OPERATION
                    )],
                    metadata={
                        'position': position,
                        'version': self._version
                    }
                )
                
            except Exception as e:
                return EditResult(
                    success=False,
                    operation=EditOperation.MOVE_SECTION,
                    modified_sections=[],
                    errors=[SafeParseError(
                        message=f"Move operation failed: {str(e)}",
                        error_code="MOVE_ERROR",
                        category=ErrorCategory.SYSTEM
                    )],
                    warnings=[]
                )
  • MCP tool registration for the 'move_section' tool using FastMCP. Defines parameters (document_path, section_id, target_position), implements operation by loading editor, finding sections, and delegating to SafeMarkdownEditor's move_section method, then executes via stateless processor.
    def move_section(document_path: str, section_id: str, target_position: int,
                    auto_save: bool = True, backup: bool = True,
                    validation_level: str = "NORMAL") -> Dict[str, Any]:
        """
        Move a section to a different position.
        The document will be saved after the operation if successful and auto_save is True.
        """
        """
        Move a section to a different position.
        
        Args:
            document_path: Path to the Markdown file
            section_id: The section ID to move
            target_position: Target position (0-based index)
            auto_save: Whether to automatically save the document
            backup: Whether to create a backup before saving
            validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE"
        """
        def operation(editor):
            section_ref = editor.get_section_by_id(section_id)
            if not section_ref:
                from .safe_editor_types import EditResult, OperationType
                return EditResult(
                    success=False,
                    operation=OperationType.MOVE,
                    modified_sections=[],
                    errors=[f"Section with ID '{section_id}' not found"],
                    warnings=[]
                )
            
            sections = editor.get_sections()
            if target_position >= len(sections) or target_position < 0:
                from .safe_editor_types import EditResult, OperationType
                return EditResult(
                    success=False,
                    operation=OperationType.MOVE,
                    modified_sections=[],
                    errors=[f"Target position {target_position} is out of range (0-{len(sections)-1})"],
                    warnings=[]
                )
            
            target_section = sections[target_position]
            return editor.move_section(section_ref, target_section, "after")
        
        validation_map = {"STRICT": ValidationLevel.STRICT, "NORMAL": ValidationLevel.NORMAL, "PERMISSIVE": ValidationLevel.PERMISSIVE}
        validation_enum = validation_map.get(validation_level.upper(), ValidationLevel.NORMAL)
        
        return self.processor.execute_operation(document_path, operation, auto_save, backup, validation_enum)
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 mentions that the document is saved if successful and auto_save is True, which hints at mutation and persistence behavior. However, it fails to address critical aspects like permissions needed, whether the operation is reversible, error handling, or what 'successful' entails, leaving significant gaps for a tool with 6 parameters.

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 brief and front-loaded with the core action in the first sentence, followed by a conditional detail. It avoids unnecessary verbosity, but the second sentence could be integrated more smoothly for better flow.

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

Completeness2/5

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

Given the tool's complexity (6 parameters, mutation operation) and the presence of an output schema, the description is incomplete. It lacks details on parameter semantics, behavioral traits like error handling or side effects, and does not leverage the output schema to explain return values. For a tool with no annotations and low schema coverage, this is inadequate.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It only references 'auto_save' implicitly, without explaining other parameters like 'document_path', 'section_id', 'target_position', 'backup', or 'validation_level'. This adds minimal value beyond the schema, failing to clarify parameter meanings or usage.

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 action ('Move a section') and the resource ('section'), specifying the operation's goal ('to a different position'). It distinguishes from siblings like 'delete_section' or 'update_section' by focusing on repositioning, but does not explicitly contrast with 'insert_section' or 'list_sections' in terms of scope or function.

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 'update_section' for content changes or 'insert_section' for adding new sections. It mentions auto-save behavior but lacks context on prerequisites, error conditions, or typical use cases relative to sibling tools.

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