Skip to main content
Glama
cwente25

Knowledge Base MCP Server

by cwente25

rename_category

Update category names in your knowledge base while preserving their hierarchical structure and location. Specify the current path and new name to reorganize content.

Instructions

Rename a category while keeping it in the same parent location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
old_pathYesCurrent category path (e.g., 'work/clients')
new_nameYesNew name for the category (just the name, not full path)

Implementation Reference

  • Registration of the 'rename_category' tool with the MCP server, including its 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 the rename_category tool, specifying parameters old_path and new_name.
    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"],
  • MCP tool handler that processes arguments for rename_category and calls the storage layer method.
    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)}")]
  • Core helper method in storage layer that validates inputs, checks existence, and performs the filesystem rename operation for categories.
    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}'"

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/cwente25/KnowledgeBaseMCP'

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