Skip to main content
Glama

list_documents

Retrieve paths to markdown documentation files within specified directories for document management and organization.

Instructions

List all markdown documents in the docs directory or a subdirectory. Returns the relative paths to all documents.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNo
basePathNo
recursiveNo

Implementation Reference

  • The core handler function in DocumentHandler class that lists .md files in the specified basePath using glob, either recursively or not, and returns relative paths.
    async listDocuments(basePath = "", recursive = false): Promise<ToolResponse> {
      try {
        const baseDir = path.join(this.docsDir, basePath);
        const pattern = recursive
          ? path.join(baseDir, "**/*.md")
          : path.join(baseDir, "*.md");
    
        const files = await glob(pattern);
        const relativePaths = files.map((file) =>
          path.relative(this.docsDir, file)
        );
    
        return {
          content: [{ type: "text", text: relativePaths.join("\n") }],
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            { type: "text", text: `Error listing documents: ${errorMessage}` },
          ],
          isError: true,
        };
      }
    }
  • Zod schema defining input for list_documents tool: optional basePath and recursive boolean.
    export const ListDocumentsSchema = ToolInputSchema.extend({
      basePath: z.string().optional(),
      recursive: z.boolean().default(false),
    });
  • src/index.ts:222-227 (registration)
    Tool registration in the ListToolsRequestHandler, defining name, description, and inputSchema.
      name: "list_documents",
      description:
        "List all markdown documents in the docs directory or a subdirectory. " +
        "Returns the relative paths to all documents.",
      inputSchema: zodToJsonSchema(ListDocumentsSchema) as any,
    },
  • src/index.ts:349-360 (registration)
    Dispatch logic in CallToolRequestHandler that validates input with schema and calls documentHandler.listDocuments.
    case "list_documents": {
      const parsed = ListDocumentsSchema.safeParse(args);
      if (!parsed.success) {
        throw new Error(
          `Invalid arguments for list_documents: ${parsed.error}`
        );
      }
      return await documentHandler.listDocuments(
        parsed.data.basePath,
        parsed.data.recursive
      );
    }

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/alekspetrov/mcp-docs-service'

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