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
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | ||
| basePath | No | ||
| recursive | No |
Implementation Reference
- src/handlers/documents.ts:286-311 (handler)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, }; } }
- src/schemas/tools.ts:13-16 (schema)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 ); }