get_workspace_hierarchy
Retrieve the complete workspace structure including spaces, folders, and lists to understand ClickUp organization and relationships.
Instructions
Get the complete workspace hierarchy including spaces, folders, and lists.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/workspace.ts:37-53 (handler)Main tool handler that calls the workspace service to get the hierarchy and formats the response as a text tree.
export async function handleGetWorkspaceHierarchy() { try { // Get workspace hierarchy from the workspace service const hierarchy = await workspaceService.getWorkspaceHierarchy(); const response = formatHierarchyResponse(hierarchy); return response; } catch (error: any) { return { content: [ { type: "text", text: `Error getting workspace hierarchy: ${error.message}` } ] }; } } - src/tools/workspace.ts:18-25 (schema)Tool schema defining the get_workspace_hierarchy tool with no input parameters.
export const workspaceHierarchyTool: Tool = { name: 'get_workspace_hierarchy', description: 'Get the complete workspace hierarchy including spaces, folders, and lists.', inputSchema: { type: 'object', properties: {} } }; - src/server.ts:100-101 (registration)Dispatch registration in the CallToolRequestHandler switch statement.
case "get_workspace_hierarchy": return handleGetWorkspaceHierarchy(); - src/server.ts:67-92 (registration)Tool list registration including get_workspace_hierarchy in ListToolsRequestHandler. Note: excerpt abbreviated.
server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ workspaceHierarchyTool, createTaskTool, getTaskTool, getTasksTool, updateTaskTool, moveTaskTool, duplicateTaskTool, deleteTaskTool, createBulkTasksTool, updateBulkTasksTool, moveBulkTasksTool, deleteBulkTasksTool, createListTool, createListInFolderTool, getListTool, updateListTool, deleteListTool, createFolderTool, getFolderTool, updateFolderTool, deleteFolderTool ] }; - Core helper service method that retrieves and constructs the workspace hierarchy tree from ClickUp API endpoints.
async getWorkspaceHierarchy(forceRefresh = false): Promise<WorkspaceTree> { try { // If we have the hierarchy in memory and not forcing refresh, return it if (this.workspaceHierarchy && !forceRefresh) { return this.workspaceHierarchy; } // Start building the workspace tree const workspaceTree: WorkspaceTree = { root: { id: this.teamId, name: 'Workspace', children: [] } }; // Get all spaces const spaces = await this.getSpaces(); // Process each space for (const space of spaces) { const spaceNode: WorkspaceNode = { id: space.id, name: space.name, type: 'space', children: [] }; // Get folders for the space const folders = await this.getFoldersInSpace(space.id); for (const folder of folders) { const folderNode: WorkspaceNode = { id: folder.id, name: folder.name, type: 'folder', parentId: space.id, children: [] }; // Get lists in the folder const listsInFolder = await this.getListsInFolder(folder.id); for (const list of listsInFolder) { folderNode.children?.push({ id: list.id, name: list.name, type: 'list', parentId: folder.id }); } spaceNode.children?.push(folderNode); } // Get lists directly in the space (not in any folder) const listsInSpace = await this.getListsInSpace(space.id); for (const list of listsInSpace) { spaceNode.children?.push({ id: list.id, name: list.name, type: 'list', parentId: space.id }); } workspaceTree.root.children.push(spaceNode); } // Store the hierarchy for later use this.workspaceHierarchy = workspaceTree; return workspaceTree; } catch (error) { throw this.handleError(error, 'Failed to get workspace hierarchy'); } }