get_file_contents
Read and retrieve contents of specified files with custom encoding support for efficient file management and analysis in the Enhanced Directory Context MCP Server.
Instructions
Read contents of specific files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| encoding | No | File encoding (default: utf8) | utf8 |
| files | Yes | Array of file paths to read |
Implementation Reference
- server.js:883-905 (handler)The handler function that implements the get_file_contents tool logic. It reads the contents of the specified files relative to the working directory using fs.readFile, handles errors per file, and returns a JSON object with results.async handleGetFileContents(args) { const { files, encoding = 'utf8' } = args; const results = {}; for (const file of files) { try { const fullPath = path.resolve(this.workingDirectory, file); const content = await fs.readFile(fullPath, encoding); results[file] = content; } catch (error) { results[file] = { error: error.message }; } } return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; }
- server.js:89-108 (schema)The tool definition including name, description, and input schema for get_file_contents, returned by the ListTools handler.{ name: 'get_file_contents', description: 'Read contents of specific files', inputSchema: { type: 'object', properties: { files: { type: 'array', description: 'Array of file paths to read', items: { type: 'string' }, }, encoding: { type: 'string', description: 'File encoding (default: utf8)', default: 'utf8', }, }, required: ['files'], }, },
- server.js:460-461 (registration)The dispatch case in the CallToolRequestSchema handler that routes calls to the get_file_contents tool to its handler function.case 'get_file_contents': return await this.handleGetFileContents(args);