mcp-extended-tools
Version:
Extended tools for command execution
37 lines (33 loc) • 1.04 kB
JavaScript
import fs from 'fs/promises';
class FileManager {
async readFile(path) {
try {
const content = await fs.readFile(path, 'utf8');
return content;
} catch (error) {
console.error(`Error reading file: ${path}`, error);
throw error;
}
}
async writeFile(path, content) {
try {
await fs.writeFile(path, content, 'utf8');
} catch (error) {
console.error(`Error writing file: ${path}`, error);
throw error;
}
}
async listDirectory(path) {
try {
const files = await fs.readdir(path);
return files.map(file => {
const isDirectory = fs.statSync(`${path}/${file}`).isDirectory();
return `${isDirectory ? '[DIR] ' : '[FILE] '}${file}`;
});
} catch (error) {
console.error(`Error listing directory: ${path}`, error);
throw error;
}
}
}
export const fileManager = new FileManager();