Skip to main content
Glama

list_shelves

Retrieve available shelves for authenticated users to manage and access stored files through paginated results.

Instructions

List shelves available to the authenticated user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNo
limitNo

Implementation Reference

  • Main tool registration and handler for list_shelves. This function registers the tool with the MCP server and implements the async handler that calls the HTTP client and formats the response.
    export function registerListShelvesTool(
      server: McpServer,
      context: ToolContext,
    ): void {
      server.registerTool(
        "list_shelves",
        {
          title: "List Shelves",
          description: "List shelves available to the authenticated user",
          inputSchema,
          outputSchema,
          annotations: { readOnlyHint: true },
        },
        async (input, extra) => {
          try {
            const apiKey = context.getApiKey(extra);
            const client = context.createHttpClient(apiKey);
            const result = await client.listShelves({
              page: input.page,
              limit: input.limit,
            });
    
            return successResult(
              `Loaded ${result.data.length} shelves (page ${result.pagination.page}/${result.pagination.totalPages})`,
              {
                shelves: result.data,
                pagination: result.pagination,
              },
            );
          } catch (error) {
            return errorResult(error);
          }
        },
      );
    }
  • Input and output Zod schemas for the list_shelves tool. Defines the structure for pagination parameters (page, limit) and the response format with shelves array and pagination metadata.
    const inputSchema = {
      page: z.number().int().min(1).optional(),
      limit: z.number().int().min(1).max(100).optional(),
    };
    
    const outputSchema = {
      shelves: z.array(
        z.object({
          publicId: z.string(),
          name: z.string(),
          status: z.string(),
          template: z.string().nullable(),
          pageCount: z.number().nullable(),
          reviewMode: z.boolean(),
          createdAt: z.string(),
          updatedAt: z.string(),
        }),
      ),
      pagination: z.object({
        page: z.number(),
        limit: z.number(),
        total: z.number(),
        totalPages: z.number(),
      }),
    };
  • Tool registration entry point. Imports registerListShelvesTool and calls it within registerShelvTools to add the tool to the MCP server.
    import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
    import type { ToolContext } from "./context";
    import { registerCreateShelfTool } from "./create-shelf";
    import { registerGetShelfTreeTool } from "./get-shelf-tree";
    import { registerHydrateShelfTool } from "./hydrate-shelf";
    import { registerListShelvesTool } from "./list-shelves";
    import { registerReadShelfFileTool } from "./read-shelf-file";
    import { registerSearchShelfTool } from "./search-shelf";
    
    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);
      }
    }
  • HTTP client method that makes the actual API request to list shelves. Handles pagination parameters and constructs the request URL.
    async listShelves(params?: {
      page?: number;
      limit?: number;
    }): Promise<ListShelvesResponse> {
      const search = new URLSearchParams();
      if (params?.page) search.set("page", String(params.page));
      if (params?.limit) search.set("limit", String(params.limit));
    
      const path =
        search.size > 0 ? `/v1/shelves?${search.toString()}` : "/v1/shelves";
    
      return this.requestJson<ListShelvesResponse>("GET", path);
    }
  • Helper functions used by the list_shelves handler to format success and error responses in the MCP tool result format.
    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