Skip to main content
Glama

batch_append_notes

Append content to multiple notes in a single atomic operation within Obsidian vaults, ensuring all updates complete successfully or none are applied.

Instructions

Append content to multiple notes atomically

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
appendsYes
confirmNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function for the batch_append_notes tool. Performs batch appends to multiple notes with automatic backup creation, concurrent execution, error handling with rollback, and confirmation safety checks.
        name="batch_append_notes",
        description="Append content to multiple notes atomically",
    )
    async def batch_append_notes(
        appends: list[NoteAppend],
        confirm: bool = False,
    ) -> str:
        """
        Append content to multiple notes.
    
        Args:
            appends: List of NoteAppend objects with path and content
            confirm: Must be true to apply changes
    
        Returns:
            Success message with append summary
        """
        if not appends:
            return "Error: No appends provided"
    
        # Check batch size limit
        if len(appends) > MAX_BATCH_SIZE:
            return (
                f"Error: Batch size ({len(appends)}) exceeds maximum ({MAX_BATCH_SIZE}).\n"
                f"Split into smaller batches to avoid server timeouts."
            )
    
        logger.info(f"Starting batch_append_notes: {len(appends)} notes")
    
        # Extract paths (Pydantic already validated)
        paths = [append.path for append in appends]
    
        if not confirm:
            return (
                f"Error: Batch append to {len(appends)} notes requires explicit confirmation. "
                f"Set confirm=true to proceed."
            )
    
        context = _get_context()
    
        try:
            # Create backup (async)
            backup_id = await context.vault.create_batch_backup(paths)
    
            # Apply all appends
            appended = []
            failed = []
    
            for append in appends:
                try:
                    await context.vault.append_to_note(append.path, append.content)
                    appended.append(append.path)
                except Exception as e:
                    failed.append((append.path, str(e)))
    
            # Rollback on failure (async)
            if failed:
                await context.vault.restore_batch_backup(backup_id)
                result = ["❌ Batch append failed - all changes rolled back\n"]
                result.append("**Failed appends:**")
                for path, error in failed:
                    result.append(f"- `{path}`: {error}")
                return "\n".join(result)
    
            # Success
            logger.info(f"Completed batch_append_notes: {len(appended)} notes updated successfully")
            result = [f"✅ Appended to {len(appended)} notes\n"]
            for path in appended:
                result.append(f"- `{path}`")
            result.append(f"\n**Backup:** `.batch_backups/{backup_id}/`")
            return "\n".join(result)
    
        except Exception as e:
            logger.exception("Error in batch append")
            return f"Error: {e}"
  • Pydantic schema defining the input structure for each append operation in the batch: path and content.
    class NoteAppend(BaseModel):
        """Schema for appending to a single note."""
    
        path: str = Field(description="Relative path to the note")
        content: str = Field(description="Content to append to the note")
  • Supporting method in ObsidianVault class that implements the core single-note append logic, reading existing content, ensuring newline separation, and asynchronously writing the updated content.
    async def append_to_note(self, relative_path: str, content: str) -> None:
        """
        Append content to an existing note.
    
        Args:
            relative_path: Path to the note
            content: Content to append
    
        Raises:
            VaultSecurityError: If path is invalid
            FileNotFoundError: If note doesn't exist
        """
        file_path = self._validate_path(relative_path)
    
        if not file_path.exists():
            raise FileNotFoundError(f"Note not found: {relative_path}")
    
        # Read existing content
        async with aiofiles.open(file_path, encoding="utf-8") as f:
            existing = await f.read()
    
        # Append new content (with newline separator if needed)
        if not existing.endswith("\n"):
            existing += "\n"
    
        existing += content
    
        # Write back
        async with aiofiles.open(file_path, "w", encoding="utf-8") as f:
            await f.write(existing)
        logger.info(f"Appended to note: {relative_path}")
  • Batch backup creation helper used by batch_append_notes for atomicity. Creates timestamped backups of specified notes concurrently with metadata preservation.
    async def create_batch_backup(self, relative_paths: list[str]) -> str:
        """
        Create a backup of multiple notes asynchronously.
    
        Args:
            relative_paths: List of note paths to backup
    
        Returns:
            Backup ID (timestamp) for later restoration
    
        Raises:
            VaultSecurityError: If any path is invalid
            FileNotFoundError: If any note doesn't exist
        """
        # Validate all paths first
        file_paths = []
        for rel_path in relative_paths:
            file_path = self._validate_path(rel_path)
            if not file_path.exists():
                raise FileNotFoundError(f"Note not found: {rel_path}")
            file_paths.append((rel_path, file_path))
    
        # Create backup directory with timestamp
        backup_id = datetime.now().strftime("%Y%m%d_%H%M%S")
        backup_dir = self.vault_path / ".batch_backups" / backup_id
        backup_dir.mkdir(parents=True, exist_ok=True)
    
        logger.info(f"Creating batch backup {backup_id}: {len(relative_paths)} files...")
    
        # Copy all files to backup asynchronously
        async def copy_file(i: int, rel_path: str, file_path: Path) -> None:
            backup_file = backup_dir / rel_path
            backup_file.parent.mkdir(parents=True, exist_ok=True)
    
            # Use async file operations
            async with aiofiles.open(file_path, "rb") as src:
                content = await src.read()
            async with aiofiles.open(backup_file, "wb") as dst:
                await dst.write(content)
    
            # Preserve metadata
            shutil.copystat(file_path, backup_file)
            logger.debug(f"Backed up ({i}/{len(file_paths)}): {rel_path}")
    
        # Run all copies concurrently
        await asyncio.gather(
            *[
                copy_file(i, rel_path, file_path)
                for i, (rel_path, file_path) in enumerate(file_paths, 1)
            ]
        )
    
        logger.info(f"Completed batch backup: {backup_id} ({len(relative_paths)} notes)")
        return backup_id
  • Batch restore helper used for rollback on failure in batch_append_notes. Restores notes from backup concurrently preserving structure and metadata.
    async def restore_batch_backup(self, backup_id: str) -> list[str]:
        """
        Restore notes from a batch backup asynchronously.
    
        Args:
            backup_id: Backup ID (timestamp) to restore from
    
        Returns:
            List of restored note paths
    
        Raises:
            FileNotFoundError: If backup doesn't exist
        """
        backup_dir = self.vault_path / ".batch_backups" / backup_id
    
        if not backup_dir.exists():
            raise FileNotFoundError(f"Backup not found: {backup_id}")
    
        logger.info(f"Restoring batch backup {backup_id}...")
    
        # Get all backup files
        backup_files = list(backup_dir.rglob("*.md"))
    
        # Restore all files asynchronously
        async def restore_file(i: int, backup_file: Path) -> str:
            # Get relative path from backup directory
            rel_path = backup_file.relative_to(backup_dir)
            target_file = self.vault_path / rel_path
    
            # Ensure parent directory exists
            target_file.parent.mkdir(parents=True, exist_ok=True)
    
            # Restore file
            async with aiofiles.open(backup_file, "rb") as src:
                content = await src.read()
            async with aiofiles.open(target_file, "wb") as dst:
                await dst.write(content)
    
            # Preserve metadata
            shutil.copystat(backup_file, target_file)
            logger.debug(f"Restored ({i}): {rel_path}")
            return str(rel_path)
    
        # Run all restores concurrently
        restored = await asyncio.gather(
            *[restore_file(i, backup_file) for i, backup_file in enumerate(backup_files, 1)]
        )
    
        logger.info(f"Completed batch restore: {backup_id} ({len(restored)} notes)")
        return list(restored)
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. It mentions 'atomically' which hints at transactional behavior (all-or-nothing execution), but fails to disclose critical details like required permissions, rate limits, error handling, or what 'content' means (e.g., text formatting, metadata). For a batch mutation tool, this is a significant gap in behavioral disclosure.

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 a single, efficient sentence with zero wasted words. It front-loads the core action ('Append content') and key qualifiers ('multiple notes', 'atomically'), making it easy to parse quickly.

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 complexity (batch mutation with 2 parameters, no annotations, but has an output schema), the description is minimally adequate. The output schema likely covers return values, reducing the need for that in the description. However, for a batch operation, more context on usage, parameters, and behavioral traits would improve completeness.

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. It mentions 'appends' implicitly but doesn't explain what 'NoteAppend' entails (e.g., note identifiers, content format) or the purpose of the 'confirm' parameter (e.g., safety confirmation). The description adds minimal value beyond the parameter names visible in the schema.

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 ('Append content') and target ('multiple notes'), and specifies 'atomically' which distinguishes it from the sibling tool 'append_to_note' that likely handles single notes. However, it doesn't explicitly name the resource type (e.g., 'notes in a vault' or similar context), leaving some ambiguity about what 'notes' refers to.

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 'append_to_note' (for single notes) or 'batch_update_notes' (for other batch operations). It mentions 'atomically' which implies transactional safety, but doesn't explain practical scenarios or prerequisites for using batch operations.

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/getglad/obsidian_mcp'

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