rename_category
Change the name of an existing category in your knowledge base while maintaining its hierarchical position and relationships.
Instructions
Rename a category while keeping it in the same parent location
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| old_path | Yes | Current category path (e.g., 'work/clients') | |
| new_name | Yes | New name for the category (just the name, not full path) |
Implementation Reference
- Core handler implementation: renames the category directory after validation, checks for conflicts and cycles.def rename_category( self, old_path: str, new_name: str ) -> str: """ Rename a category (keeps it in same parent location). Args: old_path: Current category path (e.g., "work/clients") new_name: New name for the category (just the name, not full path) Returns: Success message with new path Raises: CategoryNotFoundError: If category doesn't exist CategoryExistsError: If new name conflicts InvalidPathError: If new name is invalid """ old_normalized = normalize_path(old_path) if not old_normalized: raise InvalidPathError("Category path cannot be empty") if not self._category_exists(old_normalized): raise CategoryNotFoundError( f"❌ Error: Category '{old_normalized}' not found" ) # Validate new name is_valid, error_msg = validate_path(new_name) if not is_valid: raise InvalidPathError(f"Invalid new name: {error_msg}") if "/" in new_name: raise InvalidPathError( "New name should be just the category name, not a full path" ) # Determine new path parent = get_parent_path(old_normalized) new_path = join_path(parent, new_name) if parent else new_name # Check if new path already exists if self._category_exists(new_path): raise CategoryExistsError( f"❌ Error: Category '{new_path}' already exists" ) # Perform rename old_cat_path = self._get_category_path(old_normalized) new_cat_path = self._get_category_path(new_path) try: old_cat_path.rename(new_cat_path) except Exception as e: raise StorageError(f"Failed to rename category: {e}") return f"✓ Category renamed: '{old_normalized}' → '{new_path}'"
- src/knowledge_base_mcp/server.py:371-386 (handler)MCP tool handler wrapper: extracts arguments from tool call, invokes storage.rename_category, handles errors and formats response.async def handle_rename_category(arguments: dict) -> list[TextContent]: """Handle rename_category tool call.""" try: old_path = arguments["old_path"] new_name = arguments["new_name"] result = storage.rename_category( old_path=old_path, new_name=new_name ) return [TextContent(type="text", text=result)] except (CategoryNotFoundError, CategoryExistsError, InvalidPathError, 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:88-105 (registration)Tool registration in MCP server's list_tools(): defines name, description, and input schema.Tool( name="rename_category", description="Rename a category while keeping it in the same parent location", inputSchema={ "type": "object", "properties": { "old_path": { "type": "string", "description": "Current category path (e.g., 'work/clients')", }, "new_name": { "type": "string", "description": "New name for the category (just the name, not full path)", }, }, "required": ["old_path", "new_name"], }, ),
- Input schema definition for rename_category tool: validates old_path and new_name parameters.inputSchema={ "type": "object", "properties": { "old_path": { "type": "string", "description": "Current category path (e.g., 'work/clients')", }, "new_name": { "type": "string", "description": "New name for the category (just the name, not full path)", }, }, "required": ["old_path", "new_name"], },