Skip to main content
Glama

list_documents

Retrieve relative paths of markdown documents in specified directories or subdirectories. Enables efficient document management and organization within MCP Documentation Service.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
basePathNo
pathNo
recursiveNo

Implementation Reference

  • The listDocuments method in the DocumentHandler class implements the core logic of the 'list_documents' tool. It lists markdown files (.md) in the specified basePath (default empty), optionally recursively using glob, and returns relative paths joined by newlines as ToolResponse.
    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 the input parameters for the list_documents tool: optional basePath (string) and recursive (boolean, defaults to false). Extends ToolInputSchema.
    export const ListDocumentsSchema = ToolInputSchema.extend({ basePath: z.string().optional(), recursive: z.boolean().default(false), });
  • src/index.ts:222-227 (registration)
    Registration of the 'list_documents' tool in the MCP server's listTools response, including name, description, and JSON schema derived from ListDocumentsSchema.
    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 handler in the CallToolRequestSchema for 'list_documents': validates input using ListDocumentsSchema, then calls documentHandler.listDocuments with parsed basePath and recursive parameters.
    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