Skip to main content
Glama
cwente25

Knowledge Base MCP Server

by cwente25

create_category

Add a new category or subcategory to organize content in your knowledge base. Specify the category path with forward slashes for nested structures and include an optional description.

Instructions

Create a new category or subcategory in the knowledge base

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
category_pathYesCategory path (e.g., 'work', 'work/clients', 'personal/spiritual/devotionals'). Use forward slashes for nested categories.
descriptionNoOptional description for the category

Implementation Reference

  • The handler function that executes the create_category tool. It extracts arguments, calls the storage layer to create the category, handles errors, and returns formatted TextContent.
    async def handle_create_category(arguments: dict) -> list[TextContent]:
        """Handle create_category tool call."""
        try:
            category_path = arguments["category_path"]
            description = arguments.get("description")
    
            result = storage.create_category(
                category_path=category_path,
                description=description,
                create_parents=True
            )
    
            return [TextContent(type="text", text=result)]
        except (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)}")]
  • The tool registration in list_tools(), defining the name, description, and input schema for create_category.
    Tool(
        name="create_category",
        description="Create a new category or subcategory in the knowledge base",
        inputSchema={
            "type": "object",
            "properties": {
                "category_path": {
                    "type": "string",
                    "description": "Category path (e.g., 'work', 'work/clients', 'personal/spiritual/devotionals'). Use forward slashes for nested categories.",
                },
                "description": {
                    "type": "string",
                    "description": "Optional description for the category",
                },
            },
            "required": ["category_path"],
        },
    ),
  • The inputSchema defining the parameters for the create_category tool: required category_path and optional description.
    inputSchema={
        "type": "object",
        "properties": {
            "category_path": {
                "type": "string",
                "description": "Category path (e.g., 'work', 'work/clients', 'personal/spiritual/devotionals'). Use forward slashes for nested categories.",
            },
            "description": {
                "type": "string",
                "description": "Optional description for the category",
            },
        },
        "required": ["category_path"],
    },
  • The core storage method that performs the actual category creation: validates path, creates directory, saves optional metadata, and returns success message.
    def create_category(
        self,
        category_path: str,
        description: Optional[str] = None,
        create_parents: bool = True
    ) -> str:
        """
        Create a new category.
    
        Args:
            category_path: Category path (e.g., "work/clients/acme")
            description: Optional description for the category
            create_parents: If True, create parent directories as needed
    
        Returns:
            Success message
    
        Raises:
            CategoryExistsError: If category already exists
            InvalidPathError: If path is invalid
            StorageError: If creation fails
        """
        # Normalize and validate path
        normalized = normalize_path(category_path)
        if not normalized:
            raise InvalidPathError("Category path cannot be empty")
    
        is_valid, error_msg = validate_path(normalized)
        if not is_valid:
            raise InvalidPathError(error_msg)
    
        # Check if already exists
        if self._category_exists(normalized):
            raise CategoryExistsError(
                f"❌ Error: Category '{normalized}' already exists\n"
                f"πŸ’‘ Tip: Use rename_category to rename it"
            )
    
        # Create the directory
        cat_path = self._get_category_path(normalized)
        try:
            cat_path.mkdir(parents=create_parents, exist_ok=False)
        except FileExistsError:
            raise CategoryExistsError(f"Category '{normalized}' already exists")
        except FileNotFoundError:
            parent = get_parent_path(normalized)
            raise StorageError(
                f"❌ Error: Parent category '{parent}' does not exist\n"
                f"πŸ’‘ Tip: Create parent first or use create_parents=True"
            )
        except Exception as e:
            raise StorageError(f"Failed to create category '{normalized}': {e}")
    
        # Save metadata if description provided
        if description:
            metadata = CategoryMetadata(description=description)
            self._save_category_metadata(normalized, metadata)
    
        return f"βœ“ Category '{normalized}' created successfully"

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