Skip to main content
Glama

getFiles

Retrieve file content and metadata by specifying multiple file paths, enabling efficient access and analysis of stored files through the MCP File Context Server.

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 that implements the getFiles tool logic. It processes a list of file paths, validates access, reads content and metadata for each, handles errors per file, and returns JSON with file contents and metadata.
    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); }
  • The input schema definition for the getFiles tool, specifying an array of file objects with fileName property.
    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-1621 (registration)
    Registration of the getFiles handler in the CallToolRequestSchema switch statement.
    case 'getFiles': return await this.handleGetFiles(request.params.arguments); default:
  • src/index.ts:1441-1585 (registration)
    Registration of the getFiles tool in the ListToolsRequestSchema response, including name, description, and schema.
    tools: [ { name: 'read_context', description: 'Read and analyze code files with advanced filtering and chunking. The server automatically ignores common artifact directories and files:\n- Version Control: .git/\n- Python: .venv/, __pycache__/, *.pyc, etc.\n- JavaScript/Node.js: node_modules/, bower_components/, .next/, dist/, etc.\n- IDE/Editor: .idea/, .vscode/, .env, etc.\n\nFor large files or directories, use get_chunk_count first to determine total chunks, then request specific chunks using chunkNumber parameter.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to file or directory to read' }, maxSize: { type: 'number', description: 'Maximum file size in bytes. Files larger than this will be chunked.', default: 1048576 }, encoding: { type: 'string', description: 'File encoding (e.g., utf8, ascii, latin1)', default: 'utf8' }, recursive: { type: 'boolean', description: 'Whether to read directories recursively (includes subdirectories)', default: true }, fileTypes: { type: ['array', 'string'], items: { type: 'string' }, description: 'File extension(s) to include WITHOUT dots (e.g. ["ts", "js", "py"] or just "ts"). Empty/undefined means all files.', default: [] }, chunkNumber: { type: 'number', description: 'Which chunk to return (0-based). Use with get_chunk_count to handle large files/directories.', default: 0 } }, required: ['path'] } }, { name: 'get_chunk_count', description: 'Get the total number of chunks that will be returned for a read_context request.\nUse this tool FIRST before reading content to determine how many chunks you need to request.\nThe parameters should match what you\'ll use in read_context.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to file or directory' }, encoding: { type: 'string', description: 'File encoding (e.g., utf8, ascii, latin1)', default: 'utf8' }, maxSize: { type: 'number', description: 'Maximum file size in bytes. Files larger than this will be chunked.', default: 1048576 }, recursive: { type: 'boolean', description: 'Whether to read directories recursively (includes subdirectories)', default: true }, fileTypes: { type: ['array', 'string'], items: { type: 'string' }, description: 'File extension(s) to include WITHOUT dots (e.g. ["ts", "js", "py"] or just "ts"). Empty/undefined means all files.', default: [] } }, required: ['path'] } }, { name: 'set_profile', description: 'Set the active profile for context generation', inputSchema: { type: 'object', properties: { profile_name: { type: 'string', description: 'Name of the profile to activate' } }, required: ['profile_name'] } }, { name: 'get_profile_context', description: 'Get repository context based on current profile settings', inputSchema: { type: 'object', properties: { refresh: { type: 'boolean', description: 'Whether to refresh file selection before generating context', default: false } } } }, { name: 'generate_outline', description: 'Generate a code outline for a file, showing its structure (classes, functions, imports, etc). Supports TypeScript/JavaScript and Python files.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file to analyze' } }, required: ['path'] } }, { 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'] } } ] }));

Other Tools

Related Tools

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