UNPKG

@allpepper/memory-bank-mcp

Version:

MCP server for remote management of project memory banks

55 lines (54 loc) 1.68 kB
import fs from "fs-extra"; import path from "path"; /** * Filesystem implementation of the ProjectRepository protocol */ export class FsProjectRepository { rootDir; /** * Creates a new FsProjectRepository * @param rootDir The root directory where all projects are stored */ constructor(rootDir) { this.rootDir = rootDir; } /** * Builds a path to a project directory * @param projectName The name of the project * @returns The full path to the project directory * @private */ buildProjectPath(projectName) { return path.join(this.rootDir, projectName); } /** * Lists all available projects * @returns An array of Project objects */ async listProjects() { const entries = await fs.readdir(this.rootDir, { withFileTypes: true }); const projects = entries .filter((entry) => entry.isDirectory()) .map((entry) => entry.name); return projects; } /** * Checks if a project exists * @param name The name of the project * @returns True if the project exists, false otherwise */ async projectExists(name) { const projectPath = this.buildProjectPath(name); // If path doesn't exist, fs.stat will throw an error which will propagate const stat = await fs.stat(projectPath); return stat.isDirectory(); } /** * Ensures a project directory exists, creating it if necessary * @param name The name of the project */ async ensureProject(name) { const projectPath = this.buildProjectPath(name); await fs.ensureDir(projectPath); } }