Skip to main content
Glama

getFiles

Retrieve content and metadata for multiple files by specifying their paths to enable file analysis and processing.

Instructions

Retrieve multiple files by their paths, returning content and metadata for each file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathListYesThe list of file paths for the file content to return.

Implementation Reference

  • The handler function for the 'getFiles' tool. It processes a list of file paths, validates access for each, reads metadata and content, handles individual file errors without failing the entire request, and returns a JSON response with file details including content, size, and last modified time.
    private async handleGetFiles(args: any) { const { filePathList } = args; await this.loggingService.debug('Getting files', { fileCount: filePathList?.length || 0, operation: 'get_files' }); if (!Array.isArray(filePathList)) { throw new McpError(ErrorCode.InvalidParams, 'filePathList must be an array'); } const results: any[] = []; // Process each file, handling errors gracefully for (const fileItem of filePathList) { const filePath = fileItem.fileName; try { // PATTERN: Use existing security validation const resolvedPath = await this.validateAccess(filePath); // PATTERN: Use existing file reading methods const metadata = await this.getFileMetadata(resolvedPath); const { content } = await this.readFileWithEncoding(resolvedPath, 'utf8'); // TRANSFORM: Match required response schema results.push({ fileName: filePath, content: content, fileSize: metadata.size, lastModifiedDateTime: metadata.modifiedTime }); } catch (error) { // GOTCHA: Don't fail entire request - log error and continue await this.loggingService.error('Error reading file', error as Error, { filePath, operation: 'get_files' }); // Include error info in response but continue processing results.push({ fileName: filePath, content: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`, fileSize: 0, lastModifiedDateTime: new Date().toISOString() }); } } // PATTERN: Use existing response format method return this.createJsonResponse(results); }
  • src/index.ts:1559-1583 (registration)
    Registration of the 'getFiles' tool in the ListTools response, including name, description, and input schema definition.
    { name: 'getFiles', description: 'Retrieve multiple files by their paths, returning content and metadata for each file', inputSchema: { type: 'object', properties: { filePathList: { type: 'array', description: 'The list of file paths for the file content to return.', minItems: 1, items: { type: 'object', properties: { fileName: { type: 'string', description: 'Path and file name for the file to be retrieved.' } }, required: ['fileName'] } } }, required: ['filePathList'] } }
  • src/index.ts:1619-1620 (registration)
    Registration of the 'getFiles' tool handler in the CallToolRequestSchema switch statement.
    case 'getFiles': return await this.handleGetFiles(request.params.arguments);

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/bsmi021/mcp-file-context-server'

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