update_note
Modify existing note content in your Obsidian vault by specifying the file path and new text to update your knowledge base.
Instructions
Update an existing note's content
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| path | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/obsidian_mcp/server.py:612-644 (handler)The MCP tool handler for 'update_note'. Validates input parameters, calls the vault helper method, and returns success/error messages.
@mcp.tool(name="update_note", description="Update an existing note's content") async def update_note(path: str, content: str) -> str: """ Update an existing note's content (preserves frontmatter). Args: path: Relative path to the note content: New content for the note body Returns: Success message """ if not path or not path.strip(): return "Error: Path cannot be empty" if len(path) > 1000: return "Error: Path too long" if len(content) > 1_000_000: return "Error: Content too large (max 1MB)" context = _get_context() try: await context.vault.update_note(path, content) return f"✓ Updated note: {path}" except FileNotFoundError: return f"Error: Note not found: {path}" except VaultSecurityError as e: return f"Error: Security violation: {e}" except Exception as e: logger.exception(f"Error updating note {path}") return f"Error updating note: {e}" - src/obsidian_mcp/server.py:612-612 (registration)The @mcp.tool decorator registers the update_note function as an MCP tool with the specified name.
@mcp.tool(name="update_note", description="Update an existing note's content") - src/obsidian_mcp/vault.py:512-550 (helper)The core helper method in ObsidianVault class that performs the actual file update, handling path validation, frontmatter preservation or update, and asynchronous file writing.
async def update_note( self, relative_path: str, content: str, frontmatter: dict[str, Any] | None = None ) -> None: """ Update an existing note's content. Args: relative_path: Path to the note content: New content for the note frontmatter: Optional frontmatter dict (replaces existing if provided) 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}") # If frontmatter not provided, preserve existing if frontmatter is None: note = await self.read_note(relative_path) frontmatter = note.frontmatter # Build full content full_content = "" if frontmatter: full_content = "---\n" full_content += yaml.dump(frontmatter, default_flow_style=False, sort_keys=False) full_content += "---\n" full_content += content # Write file async with aiofiles.open(file_path, "w", encoding="utf-8") as f: await f.write(full_content) logger.info(f"Updated note: {relative_path}")