update_note
Update an existing note in an Obsidian vault by providing the file path, optionally updating its content and metadata.
Instructions
Update an existing note.
Args: path: Path to the note content: New content (optional) metadata: Metadata updates (optional)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| content | No | ||
| metadata | No |
Implementation Reference
- server.py:134-156 (handler)The MCP tool handler for 'update_note'. It is decorated with @mcp.tool(), accepts path, optional content, and optional metadata. It checks read-only mode, gets the vault client, and delegates to client.update_note().
@mcp.tool() def update_note(path: str, content: Optional[str] = None, metadata: Optional[dict] = None) -> dict: """Update an existing note. Args: path: Path to the note content: New content (optional) metadata: Metadata updates (optional) """ try: if is_read_only(): return read_only_error() client = get_vault_client() note = client.update_note(path, content, metadata) return note except Exception as e: return {"error": str(e)} @mcp.tool() def delete_note(path: str) -> dict: """Delete a note permanently. - obsidian_client.py:136-156 (helper)The ObsidianVaultClient.update_note() method that implements the actual note update logic. It loads the existing note's content and metadata, optionally updates the content and/or metadata, creates a backup if configured, and writes the note back to disk.
def update_note(self, path: str, content: Optional[str] = None, metadata: Optional[Dict] = None) -> Dict[str, Any]: """Update an existing note.""" note_path = self._resolve_vault_path(path) if not note_path.exists(): raise ValueError(f"Note does not exist: {path}") current_content, current_metadata = self._load_markdown(note_path) post = frontmatter.Post(current_content, **current_metadata) if content is not None: post.content = content if metadata is not None: post.metadata.update(metadata) self._backup_note(note_path) with open(note_path, 'w', encoding='utf-8') as f: f.write(frontmatter.dumps(post)) return self.get_note(path)