get_file_contents
Read contents of specific files to access their data directly, supporting multiple file paths and configurable encoding options for file analysis.
Instructions
Read contents of specific files
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | Array of file paths to read | |
| encoding | No | File encoding (default: utf8) | utf8 |
Implementation Reference
- server.js:883-905 (handler)The main execution function for the 'get_file_contents' tool. It reads contents from multiple specified files relative to the server's working directory using Node.js fs.readFile, handles encoding, manages errors per file, and returns a standardized MCP response with JSON-stringified 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:92-107 (schema)JSON Schema defining the input parameters for the tool: an object with 'files' (required array of relative file paths) and optional 'encoding' (string, defaults to 'utf8'). Used for validation in MCP tool calls.
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:89-108 (registration)The tool definition object registered with the MCP server via setTools(), specifying name, description, and input schema for 'get_file_contents'.
{ 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)Dispatch logic in the CallToolRequest handler switch statement that maps the tool name to its handler method.
case 'get_file_contents': return await this.handleGetFileContents(args);