Skip to main content
Glama

get_document_tree

Retrieve hierarchical document tree structures to understand project organization, with options to filter by root category, include metadata, and control depth.

Instructions

Retrieve the hierarchical document tree structure

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rootCategoryNoRoot category to filter by
includeMetadataNoInclude document metadata
maxDepthNoMaximum tree depth

Implementation Reference

  • The main handler function that executes the get_document_tree tool logic. It retrieves all documents, builds the tree using DocumentTreeService, filters by root category if specified, builds a tree representation, and returns structured results including total nodes and max depth.
    tools.set('get_document_tree', async (args: any) => {
      try {
        logger.info(`Getting document tree: ${args.rootCategory || 'all'}`);
        
        const documents = await lifecycleService.getAllDocuments();
        const treeNodes = await treeService.buildTree(documents);
        
        // Filter by root category if specified
        const filteredNodes = args.rootCategory 
          ? treeNodes.filter(node => node.treeType === args.rootCategory)
          : treeNodes;
        
        // Build tree representation
        const treeRepresentation = await buildTreeRepresentation(
          filteredNodes, 
          documents, 
          args.includeMetadata, 
          args.maxDepth
        );
        
        return {
          success: true,
          totalNodes: filteredNodes.length,
          maxDepth: Math.max(...filteredNodes.map(n => n.depth)),
          tree: treeRepresentation,
          generatedAt: localizationService.getCurrentDateTimeString()
        };
      } catch (error) {
        logger.error('Failed to get document tree:', error);
        throw error;
      }
    });
  • Zod schema defining the input validation for the get_document_tree tool parameters: rootCategory (optional enum), includeMetadata (boolean, default false), maxDepth (number, default 10).
    export const GetDocumentTreeSchema = z.object({
      rootCategory: z.enum(['master', 'component', 'category']).optional(),
      includeMetadata: z.boolean().default(false),
      maxDepth: z.number().default(10),
    });
  • MCPTool registration object defining the name, description, and JSON schema for the get_document_tree tool inputs, used in the registerEnhancedTools function.
    {
      name: 'get_document_tree',
      description: 'Retrieve the hierarchical document tree structure',
      inputSchema: {
        type: 'object',
        properties: {
          rootCategory: {
            type: 'string',
            enum: ['master', 'component', 'category'],
            description: 'Root category to filter by'
          },
          includeMetadata: {
            type: 'boolean',
            description: 'Include document metadata',
            default: false
          },
          maxDepth: {
            type: 'number',
            description: 'Maximum tree depth',
            default: 10
          }
        },
        required: []
      }
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'retrieve' but doesn't clarify if this is a read-only operation, potential side effects (e.g., caching), performance considerations, or error handling. For a tool with zero annotation coverage, this is a significant gap in transparency.

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 directly states the tool's purpose without unnecessary words. It's front-loaded and every word earns its place, 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 complexity (a retrieval tool with 3 parameters), no annotations, and no output schema, the description is minimally adequate but incomplete. It covers the basic purpose but lacks details on behavior, usage context, and output format, which are crucial for effective tool invocation in this scenario.

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?

The schema description coverage is 100%, so the schema already documents all three parameters with descriptions and defaults. The description adds no additional meaning beyond implying hierarchical retrieval, which aligns with the schema but doesn't provide extra context like examples or edge cases. 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 'retrieve' and the resource 'hierarchical document tree structure', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'docs_search' or 'docs_reference', which might also retrieve document-related information but with different scopes or formats.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, context for retrieval (e.g., after initialization), or compare it to siblings like 'docs_search' for searching versus 'get_document_tree' for hierarchical views, leaving usage ambiguous.

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/Ghostseller/CastPlan_mcp'

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