file_read
Read file contents to access local documents and notes for developer operational tasks. Provide the file path to retrieve text and data.
Instructions
Читать содержимое файла
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Путь к файлу |
Implementation Reference
- src/connectors/file-service.ts:12-28 (handler)Core handler function that implements the file_read tool logic: sanitizes the file path, reads the file using fs.promises.readFile, and returns the content.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:86-98 (schema)Schema definition for the file_read tool, including input schema for path parameter, provided in the ListTools response.name: 'file_read', description: 'Читать содержимое файла', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Путь к файлу', }, }, required: ['path'], }, },
- src/server.ts:196-199 (handler)Handler dispatch in the MCP server's CallToolRequest handler that invokes the FileService.readFile method for file_read tool calls.case 'file_read': return { content: await this.fileService.readFile(args.path as string) };
- src/connectors/file-service.ts:79-96 (helper)Helper function used by readFile to sanitize and validate the file path, preventing path traversal by restricting to notes directory.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;