Skip to main content
Glama

list_files

View all documents stored in your local vector database with file paths and chunk counts to manage your private document collection.

Instructions

List all ingested files in the vector database. Returns file paths and chunk counts for each document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_files' MCP tool. It calls vectorStore.listFiles() and formats the result as MCP content block.
    /** * list_files tool handler (Phase 1: basic implementation) */ async handleListFiles(): Promise<{ content: [{ type: 'text'; text: string }] }> { try { const files = await this.vectorStore.listFiles() return { content: [ { type: 'text', text: JSON.stringify(files, null, 2), }, ], } } catch (error) { console.error('Failed to list files:', error) throw error } }
  • Input schema definition for the list_files tool (empty object as it takes no parameters).
    inputSchema: { type: 'object', properties: {} },
  • Registration of the 'list_files' tool in the ListToolsRequestHandler response, including name, description, and input schema.
    { name: 'list_files', description: 'List all ingested files in the vector database. Returns file paths and chunk counts for each document.', inputSchema: { type: 'object', properties: {} }, },
  • The VectorStore.listFiles() helper method that queries the database, groups chunks by filePath, and returns aggregated file information (path, chunk count, latest timestamp). Called by the tool handler.
    /** * Get list of ingested files * * @returns Array of file information */ async listFiles(): Promise<{ filePath: string; chunkCount: number; timestamp: string }[]> { if (!this.table) { return [] // Return empty array if table doesn't exist } try { // Retrieve all records const allRecords = await this.table.query().toArray() // Group by file path const fileMap = new Map<string, { chunkCount: number; timestamp: string }>() for (const record of allRecords) { const filePath = record.filePath as string const timestamp = record.timestamp as string if (fileMap.has(filePath)) { const fileInfo = fileMap.get(filePath) if (fileInfo) { fileInfo.chunkCount += 1 // Keep most recent timestamp if (timestamp > fileInfo.timestamp) { fileInfo.timestamp = timestamp } } } else { fileMap.set(filePath, { chunkCount: 1, timestamp }) } } // Convert Map to array of objects return Array.from(fileMap.entries()).map(([filePath, info]) => ({ filePath, chunkCount: info.chunkCount, timestamp: info.timestamp, })) } catch (error) { throw new DatabaseError('Failed to list files', error as Error) } }

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/shinpr/mcp-local-rag'

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