update_note
Modify existing notes in your knowledge base by updating content, tags, or categories to keep information current and organized.
Instructions
Update an existing note's content or tags
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category_path | Yes | Category path (e.g., 'work/clients/acme') | |
| title | Yes | Note title | |
| content | No | New content (optional) | |
| tags | No | New comma-separated tags (optional) | |
| append | No | If true, append content instead of replacing (default: false) |
Implementation Reference
- src/knowledge_base_mcp/server.py:499-535 (handler)The handler function for the 'update_note' MCP tool. It extracts parameters from arguments, parses tags, calls the storage layer to update the note, formats a success message with details, and handles errors by returning appropriate TextContent.
async def handle_update_note(arguments: dict) -> list[TextContent]: """Handle update_note tool call.""" try: category_path = arguments["category_path"] title = arguments["title"] content = arguments.get("content") tags_str = arguments.get("tags") append = arguments.get("append", False) # Parse tags tags = None if tags_str: tags = [tag.strip() for tag in tags_str.split(",") if tag.strip()] # Update note note = storage.update_note( category_path=category_path, title=title, content=content, tags=tags, append=append ) result = f"✓ Note '{title}' updated successfully\n" result += f" Category: {category_path or 'root'}\n" if tags: result += f" Tags: {', '.join(note.frontmatter.tags)}\n" result += f" Last updated: {note.frontmatter.updated}" return [TextContent(type="text", text=result)] except (NoteNotFoundError, StorageError) as e: return [TextContent(type="text", text=str(e))] except Exception as e: return [TextContent(type="text", text=f"❌ Error: {str(e)}")] - src/knowledge_base_mcp/server.py:210-240 (registration)Registration of the 'update_note' tool in the MCP server's list_tools() method, including name, description, and JSON input schema defining parameters and validation.
Tool( name="update_note", description="Update an existing note's content or tags", inputSchema={ "type": "object", "properties": { "category_path": { "type": "string", "description": "Category path (e.g., 'work/clients/acme')", }, "title": { "type": "string", "description": "Note title", }, "content": { "type": "string", "description": "New content (optional)", }, "tags": { "type": "string", "description": "New comma-separated tags (optional)", }, "append": { "type": "boolean", "description": "If true, append content instead of replacing (default: false)", "default": False, }, }, "required": ["category_path", "title"], }, ), - Core helper method in KnowledgeBaseStorage that implements the note update logic: retrieves the note, updates content (replace or append), tags, metadata, timestamp, writes to file with backup, and returns the updated Note object.
def update_note( self, category_path: str, title: str, content: Optional[str] = None, tags: Optional[list[str]] = None, append: bool = False, metadata: Optional[dict] = None ) -> Note: """ Update an existing note. Args: category_path: Category path (e.g., "work/clients/acme") title: Note title content: New content (or content to append) tags: New tags (replaces existing) append: If True, append content instead of replacing metadata: Additional metadata to update Returns: Updated Note object Raises: NoteNotFoundError: If note doesn't exist """ # Get existing note normalized = normalize_path(category_path) note = self.get_note(normalized, title) # Update content if content is not None: if append: note.content = note.content.strip() + "\n\n" + content else: note.content = content # Update tags if tags is not None: note.frontmatter.tags = tags # Update metadata if metadata is not None: note.frontmatter.metadata.update(metadata) # Update timestamp note.frontmatter.updated = datetime.now().strftime("%Y-%m-%d") # Write updated note file_path = Path(note.file_path) self._write_note_file(note, file_path, backup=True) return note