Skip to main content
Glama
cwente25

Knowledge Base MCP Server

by cwente25

list_categories

Retrieve all knowledge base categories in a hierarchical tree structure to organize and navigate content effectively.

Instructions

List all categories in a hierarchical tree structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
parent_pathNoOptional: list only subcategories of this path

Implementation Reference

  • The handler function that executes the list_categories tool. It extracts the optional parent_path from arguments, calls storage.get_category_hierarchy to get the category tree, formats it as a textual tree using format_tree, and returns it as TextContent.
    async def handle_list_categories(arguments: dict) -> list[TextContent]:
        """Handle list_categories tool call."""
        parent_path = arguments.get("parent_path")
    
        # Get hierarchical category structure
        categories = storage.get_category_hierarchy(parent_path=parent_path)
    
        if not categories:
            if parent_path:
                return [TextContent(type="text", text=f"No subcategories found in '{parent_path}/'")]
            else:
                return [TextContent(type="text", text="No categories found. Create one with create_category!")]
    
        # Format as tree
        if parent_path:
            output = f"Categories in {parent_path}/:\n\n"
        else:
            output = "Category Hierarchy:\n\n"
    
        for cat in categories:
            output += cat.format_tree(indent=0, show_counts=True)
    
        return [TextContent(type="text", text=output)]
  • Registration of the list_categories tool in the @app.list_tools() function, including its name, description, and input schema.
    Tool(
        name="list_categories",
        description="List all categories in a hierarchical tree structure",
        inputSchema={
            "type": "object",
            "properties": {
                "parent_path": {
                    "type": "string",
                    "description": "Optional: list only subcategories of this path",
                },
            },
        },
    ),
  • The input schema definition for the list_categories tool, defining an optional parent_path parameter.
    inputSchema={
        "type": "object",
        "properties": {
            "parent_path": {
                "type": "string",
                "description": "Optional: list only subcategories of this path",
            },
        },
    },
  • Supporting helper method in KnowledgeBaseStorage that recursively builds the hierarchical structure of categories as CategoryInfo objects, used by the handler. Includes note counts, metadata, and sorting.
    def get_category_hierarchy(
        self,
        parent_path: Optional[str] = None
    ) -> List[CategoryInfo]:
        """
        Get hierarchical category structure.
    
        Args:
            parent_path: Optional parent path to list subcategories of
    
        Returns:
            List of CategoryInfo objects representing the category tree
        """
        if parent_path:
            normalized = normalize_path(parent_path)
            search_path = self._get_category_path(normalized)
        else:
            search_path = self.base_path
            normalized = ""
    
        if not search_path.exists():
            return []
    
        categories = []
    
        # Find all direct subdirectories
        for item in search_path.iterdir():
            if not item.is_dir():
                continue
    
            # Get relative path from base
            try:
                rel_path = item.relative_to(self.base_path)
                cat_path = str(rel_path)
            except ValueError:
                continue
    
            # Count notes in this category (non-recursive)
            note_count = self._count_notes_in_category(cat_path, recursive=False)
    
            # Load metadata
            metadata = self._load_category_metadata(cat_path)
    
            # Get depth
            depth = get_depth(cat_path)
    
            # Create CategoryInfo
            cat_info = CategoryInfo(
                name=item.name,
                path=cat_path,
                note_count=note_count,
                depth=depth,
                metadata=metadata
            )
    
            # Recursively get children
            cat_info.children = self.get_category_hierarchy(cat_path)
    
            categories.append(cat_info)
    
        return sorted(categories, key=lambda c: c.name)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the output format ('hierarchical tree structure'), which adds value beyond the input schema, but doesn't disclose critical behavioral traits like whether it's read-only, paginated, rate-limited, or requires authentication. For a tool with zero annotation coverage, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('List all categories') and adds essential context ('in a hierarchical tree structure'). There is zero waste or redundancy, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one optional parameter, no output schema, no annotations), the description is minimally adequate. It covers the purpose and output format but lacks behavioral details and usage guidelines. For a simple read operation, this is borderline viable but leaves gaps an agent might need to infer.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the 'parent_path' parameter fully. The description doesn't add any parameter-specific information beyond what's in the schema, such as examples of path formats or hierarchical implications. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('all categories'), specifying they are returned in a 'hierarchical tree structure'. It distinguishes from siblings like 'create_category' or 'move_category' by focusing on retrieval, but doesn't explicitly differentiate from other list operations like 'list_notes' beyond resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites, when to use 'parent_path' filtering, or how it compares to other category-related tools like 'create_category' or 'move_category'. The agent must infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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