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
| Name | Required | Description | Default |
|---|---|---|---|
| rootCategory | No | Root category to filter by | |
| includeMetadata | No | Include document metadata | |
| maxDepth | No | Maximum tree depth |
Implementation Reference
- src/tools/enhanced/index.ts:375-406 (handler)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; } });
- src/types/enhanced.types.ts:118-122 (schema)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), });
- src/tools/enhanced/index.ts:136-160 (registration)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: [] } },