Skip to main content
Glama

aps_get_folder_tree

Retrieve a recursive folder tree for any project folder, displaying subfolder hierarchy and file counts per folder to quickly understand project organization while avoiding rate limits by controlling depth.

Instructions

Build a recursive folder‑tree structure showing subfolder hierarchy and file counts per folder. Useful for understanding a project's organisation at a glance. ⚠️ Each level makes an API call, so keep max_depth low (default 3) to avoid rate limits.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID – starts with 'b.'.
folder_idYesRoot folder URN – starts with 'urn:'.
max_depthNoMaximum recursion depth (1‑5). Default 3.

Implementation Reference

  • src/index.ts:335-360 (registration)
    Tool registration (schema + name) for 'aps_get_folder_tree' in the TOOLS array. Defines inputSchema with project_id, folder_id, max_depth.
    // 8 ── aps_get_folder_tree
    {
      name: "aps_get_folder_tree",
      description:
        "Build a recursive folder‑tree structure showing subfolder hierarchy and file counts per folder. " +
        "Useful for understanding a project's organisation at a glance. " +
        "⚠️ Each level makes an API call, so keep max_depth low (default 3) to avoid rate limits.",
      inputSchema: {
        type: "object" as const,
        properties: {
          project_id: {
            type: "string",
            description: "Project ID – starts with 'b.'.",
          },
          folder_id: {
            type: "string",
            description: "Root folder URN – starts with 'urn:'.",
          },
          max_depth: {
            type: "number",
            description: "Maximum recursion depth (1‑5). Default 3.",
          },
        },
        required: ["project_id", "folder_id"],
      },
    },
  • Handler for 'aps_get_folder_tree' in handleTool(). Validates project_id and folder_id, calls buildFolderTree(), and returns JSON.
    // ── aps_get_folder_tree ──────────────────────────────────────
    if (name === "aps_get_folder_tree") {
      const projectId = args.project_id as string;
      const folderId = args.folder_id as string;
      const e1 = validateProjectId(projectId);
      if (e1) return fail(e1);
      const e2 = validateFolderId(folderId);
      if (e2) return fail(e2);
    
      const maxDepth = Math.min(Math.max(Number(args.max_depth) || 3, 1), 5);
      const t = await token();
      const tree = await buildFolderTree(projectId, folderId, t, maxDepth);
      return json(tree);
    }
  • Core recursive folder tree builder (buildFolderTree). Fetches folder contents, recurses into subfolders up to max_depth, returns FolderTreeNode structure.
    export async function buildFolderTree(
      projectId: string,
      folderId: string,
      token: string,
      maxDepth: number = 3,
      _currentDepth: number = 0,
    ): Promise<FolderTreeNode> {
      const path = `data/v1/projects/${projectId}/folders/${encodeURIComponent(folderId)}/contents`;
      const raw = (await apsDmRequest("GET", path, token, {
        query: { "page[limit]": "200" },
      })) as Record<string, unknown>;
      const data = Array.isArray(raw.data) ? (raw.data as Record<string, unknown>[]) : [];
    
      const childFolders: FolderTreeNode[] = [];
      let fileCount = 0;
    
      for (const item of data) {
        const attrs = item.attributes as Record<string, unknown> | undefined;
        if (item.type === "folders") {
          if (_currentDepth < maxDepth - 1) {
            const child = await buildFolderTree(
              projectId,
              item.id as string,
              token,
              maxDepth,
              _currentDepth + 1,
            );
            child.name = (attrs?.displayName as string) ?? "(unknown)";
            childFolders.push(child);
          } else {
            childFolders.push({
              name: (attrs?.displayName as string) ?? "(unknown)",
              id: item.id as string,
              type: "folder",
              // max depth reached – children not fetched
            });
          }
        } else {
          fileCount++;
        }
      }
    
      // Resolve folder name at the root level of the call
      let folderName = folderId;
      if (_currentDepth === 0) {
        try {
          const folderRaw = (await apsDmRequest(
            "GET",
            `data/v1/projects/${projectId}/folders/${encodeURIComponent(folderId)}`,
            token,
          )) as Record<string, unknown>;
          const fAttrs = (folderRaw.data as Record<string, unknown>)?.attributes as
            | Record<string, unknown>
            | undefined;
          folderName = (fAttrs?.displayName as string) ?? folderId;
        } catch {
          // keep folderId as name
        }
      }
    
      return {
        name: folderName,
        id: folderId,
        type: "folder",
        children: childFolders.length > 0 ? childFolders : undefined,
        file_count: fileCount,
      };
    }
  • FolderTreeNode interface used as the return type for buildFolderTree. Contains name, id, type, children, and file_count.
    export interface FolderTreeNode {
      name: string;
      id: string;
      type: "folder";
      children?: FolderTreeNode[];
      file_count?: number;
    }
Behavior4/5

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

No annotations provided, but description discloses that each recursion level makes an API call and warns about rate limits, adding critical behavioral context beyond the schema.

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?

Two concise sentences plus a critical warning, all front-loaded with purpose and usage, no wasted words.

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

Completeness4/5

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

Given no output schema, description adequately explains the tool's output (tree with hierarchy and file counts) and key behavioral trait (API calls per level). Lacks error handling info but is otherwise complete.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. Description adds format hints for project_id and folder_id, and repeats the max_depth default with range and rate limit implication, providing added value.

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

Purpose5/5

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

The description states a specific verb ('Build') and resource ('recursive folder‑tree structure'), clearly distinguishing it from siblings like aps_get_folder_contents which returns flat contents.

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

Usage Guidelines4/5

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

Explicitly says it's useful for understanding project organization and warns about API call costs per depth level, implying when to use and when to avoid deep recursion.

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/EverseDevelopment/APS.MCP'

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