Skip to main content
Glama

get_shelf_tree

Retrieve the complete file structure and contents of a shelf to access and organize stored files efficiently.

Instructions

Get the full file tree and file contents for a shelf

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
shelf_idYes

Implementation Reference

  • Main implementation of get_shelf_tree tool. The registerGetShelfTreeTool function contains the handler logic that calls the shelv client's getTree method and formats the response with shelf_id, name, file_count, and files.
    export function registerGetShelfTreeTool(
      server: McpServer,
      context: ToolContext,
    ): void {
      server.registerTool(
        "get_shelf_tree",
        {
          title: "Get Shelf Tree",
          description: "Get the full file tree and file contents for a shelf",
          inputSchema,
          outputSchema,
          annotations: { readOnlyHint: true },
        },
        async (input, extra) => {
          try {
            const apiKey = context.getApiKey(extra);
            const client = context.createShelvClient(apiKey);
            const tree = await client.getTree(input.shelf_id);
    
            return successResult(
              `Loaded ${tree.fileCount} files for shelf ${tree.shelfPublicId}`,
              {
                shelf_id: tree.shelfPublicId,
                name: tree.name,
                file_count: tree.fileCount,
                files: tree.files,
              },
            );
          } catch (error) {
            return errorResult(error);
          }
        },
      );
    }
  • Input and output schema definitions for the get_shelf_tree tool. Input requires shelf_id (string), output returns shelf_id, name, file_count, and a record of files.
    const inputSchema = {
      shelf_id: z.string().min(1),
    };
    
    const outputSchema = {
      shelf_id: z.string(),
      name: z.string(),
      file_count: z.number(),
      files: z.record(z.string()),
    };
  • src/tools/index.ts:4-4 (registration)
    Import statement for registerGetShelfTreeTool function from get-shelf-tree module.
    import { registerGetShelfTreeTool } from "./get-shelf-tree";
  • registerShelvTools function that registers all tools including get_shelf_tree. The get_shelf_tree tool is always registered on line 15.
    export function registerShelvTools(
      server: McpServer,
      context: ToolContext,
    ): void {
      registerListShelvesTool(server, context);
      registerGetShelfTreeTool(server, context);
      registerReadShelfFileTool(server, context);
      registerSearchShelfTool(server, context);
    
      if (context.config.enableWriteTools) {
        registerCreateShelfTool(server, context);
        registerHydrateShelfTool(server, context);
      }
    }
  • Helper functions successResult and errorResult used by the get_shelf_tree handler to format tool execution responses.
    export function successResult(
      text: string,
      structuredContent: Record<string, unknown>,
    ): CallToolResult {
      return {
        content: [{ type: "text", text }],
        structuredContent,
      };
    }
    
    export function errorResult(error: unknown): CallToolResult {
      const normalized = toMcpToolError(error, "Tool execution failed");
    
      return {
        isError: true,
        content: [{ type: "text", text: normalized.message }],
        structuredContent: {
          error: serializeToolError(normalized),
        },
      };
    }

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/shelv-dev/shelv-mcp'

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