Skip to main content
Glama

save_document

Save and validate Markdown documents with configurable backup and strictness levels using the SafeMarkdownEditor MCP Server.

Instructions

Save the document (mainly for validation purposes since auto_save handles most cases). Args: document_path: Path to the source Markdown file target_path: Path to save to (if different from source) backup: Whether to create a backup before saving validation_level: Validation strictness - "STRICT", "NORMAL", or "PERMISSIVE"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
backupNo
document_pathYes
target_pathNo
validation_levelNoNORMAL

Implementation Reference

  • Primary MCP tool handler for 'save_document'. Loads the document editor and delegates saving to the stateless processor.
    @self.mcp.tool() def save_document(document_path: str, target_path: Optional[str] = None, backup: bool = True, validation_level: str = "NORMAL") -> Dict[str, Any]: """ Save the document (mainly for validation purposes since auto_save handles most cases). Args: document_path: Path to the source Markdown file target_path: Path to save to (if different from source) backup: Whether to create a backup before saving 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) # Determine save path save_path = target_path if target_path else document_path # Save the document save_result = self.processor.save_document(editor, save_path, backup) return save_result except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)
  • Core helper function that performs the actual file backup creation and content writing for saving the document.
    @staticmethod def save_document(editor: SafeMarkdownEditor, document_path: str, backup: bool = True) -> Dict[str, Any]: """Save a document to the specified path.""" target_path = StatelessMarkdownProcessor.resolve_path(document_path) # Create parent directories if they don't exist target_path.parent.mkdir(parents=True, exist_ok=True) # Create backup if requested and file exists if backup and target_path.exists(): backup_path = target_path.with_suffix(f"{target_path.suffix}.bak") backup_path.write_bytes(target_path.read_bytes()) # Save the document content = editor.to_markdown() target_path.write_text(content, encoding='utf-8') return { "success": True, "message": f"Successfully saved document to {target_path}", "file_path": str(target_path), "backup_created": backup and Path(str(target_path) + ".bak").exists(), "file_size": len(content) }
  • Alternative handler implementation used for synchronous tool calls in call_tool_sync.
    def _save_document_impl(self, document_path: str, target_path: Optional[str] = None, backup: bool = True, validation_level: str = "NORMAL") -> Dict[str, Any]: """Implementation for save_document tool.""" 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) # Determine save path save_path = target_path if target_path else document_path return self.processor.save_document(editor, save_path, backup) except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)
  • Handler for save_document in the enhanced MCP server variant.
    def save_document(document_path: str, backup: bool = True) -> Dict[str, Any]: """Save document to file (stateless only).""" try: editor = self.processor.load_document(document_path) return self.processor.save_document(editor, document_path, backup) except Exception as e: return self.processor.create_error_response(str(e), type(e).__name__)

Other Tools

Related 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