read_file
View existing code files by reading contents from the local file system. Access files using relative or absolute paths to examine project code.
Instructions
Read the contents of a file from the local file system. Use this to view existing code files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the file (relative to projects directory or absolute) |
Implementation Reference
- index.js:215-226 (handler)The readFile method implements the core logic of the 'read_file' tool. It resolves the file path using resolvePath, reads the file contents with fs.readFile, and returns the content formatted as MCP response.async readFile(filePath) { const resolvedPath = this.resolvePath(filePath); const content = await fs.readFile(resolvedPath, 'utf-8'); return { content: [ { type: 'text', text: content, }, ], }; }
- index.js:50-59 (schema)The input schema for the 'read_file' tool, defining the required 'path' parameter as a string.inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file (relative to projects directory or absolute)', }, }, required: ['path'], },
- index.js:47-60 (registration)Registration of the 'read_file' tool in the ListToolsRequest handler, providing name, description, and input schema.{ name: 'read_file', description: 'Read the contents of a file from the local file system. Use this to view existing code files.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the file (relative to projects directory or absolute)', }, }, required: ['path'], }, },
- index.js:163-164 (registration)Dispatch handler in the CallToolRequest switch statement that routes 'read_file' calls to the readFile method.case 'read_file': return await this.readFile(args.path);
- index.js:205-213 (helper)Helper method resolvePath used by readFile to handle relative and absolute paths relative to PROJECTS_DIR.resolvePath(inputPath) { if (!inputPath || inputPath === '.') { return PROJECTS_DIR; } if (path.isAbsolute(inputPath)) { return inputPath; } return path.join(PROJECTS_DIR, inputPath); }