file_read
Read file contents from local storage to access documents, notes, or operational data for AI-assisted analysis and task management.
Instructions
Читать содержимое файла
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Путь к файлу |
Implementation Reference
- src/connectors/file-service.ts:12-27 (handler)Core handler function for the 'file_read' tool. Sanitizes the file path to prevent directory traversal, reads the file content using Node.js fs.promises.readFile, logs the operation, and returns the content as a string. Handles errors appropriately.async readFile(filePath: string): Promise<string> { try { // Проверяем безопасность пути const safePath = this.sanitizePath(filePath); console.log(`📖 Чтение файла: ${safePath}`); const content = await fs.readFile(safePath, 'utf-8'); console.log(`✅ Файл прочитан: ${safePath} (${content.length} символов)`); return content; } catch (error) { console.error('Ошибка чтения файла:', error); throw new Error(`Ошибка чтения файла: ${error}`); }
- src/server.ts:85-98 (schema)Input schema definition for the 'file_read' tool, requiring a 'path' string parameter. Part of the tool list returned by ListToolsRequestSchema handler.{ name: 'file_read', description: 'Читать содержимое файла', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Путь к файлу', }, }, required: ['path'], }, },
- src/server.ts:196-199 (registration)Registration of the 'file_read' tool handler in the main CallToolRequestSchema switch statement in the stdio server transport. Delegates execution to FileService.readFile.case 'file_read': return { content: await this.fileService.readFile(args.path as string) };
- src/connectors/file-service.ts:79-96 (helper)Helper method used by readFile to sanitize the file path, preventing path traversal attacks by restricting to the notes directory and removing dangerous characters.private sanitizePath(filePath: string): string { // Убираем потенциально опасные символы const cleanPath = filePath.replace(/[<>:"|?*]/g, ''); // Разрешаем только относительные пути if (path.isAbsolute(cleanPath)) { throw new Error('Абсолютные пути не разрешены'); } // Разрешаем только файлы в notes директории const resolvedPath = path.resolve(this.notesDir, cleanPath); const notesDirResolved = path.resolve(this.notesDir); if (!resolvedPath.startsWith(notesDirResolved)) { throw new Error('Доступ к файлу вне notes директории запрещен'); } return resolvedPath;