Memory Bank MCP Server

repository·main·Indexed 21 days ago

https://github.com/alioshr/memory-bank-mcp

A Model Context Protocol (MCP) server for remote management of project-based memory banks. It enables AI assistants to access, read, and update project-specific memory files with strict isolation across multiple projects. The server supports integration with Claude Desktop, Claude Code, Cursor, Cline, and Roo Code, and can be deployed via npx or Docker. It implements a structured memory lifecycle including Pre-Flight Validation, Plan Mode, Act Mode, and Documentation Updates using a hierarchical file system (Foundation, Context, and Status files).

Tokens
5K
Snippets
24
Records
28
Agent score
75%

What's inside memory-bank-mcp

  1. Understand the Memory Bank lifecycle

    main

    The Memory Bank operates through a structured lifecycle designed to maintain context and intelligence:

    1. Pre-Flight Validation (*a): Automatic check of project directory existence, core file presence (e.g., projectbrief.md), and custom documentation inventory.
    2. Plan Mode (*b): Uses filesystem/list_directory results to develop a strategy, which is then documented in activeContext.md. Paths must use forward slashes.
    3. Act Mode (*c): Executes tasks based on .clinerules and the current context.
    4. Documentation Updates (*d): Triggered by ≥25% code impact changes, new pattern discovery, user requests, or context ambiguity. Requires a full file re-read.
    5. Learning Process (*e): Identifies patterns, validates them with the user, and updates .clinerules to improve future execution.
  2. Understand the Memory Bank file structure and hierarchy

    main

    The Memory Bank is organized into a hierarchy of core and custom files. Understanding the relationships is critical for correct access and updates.

    Core File Hierarchy

    • Foundation (Purple): projectbrief.md (Core requirements/goals). This feeds into all other context files.
    • Context (Blue):
      • productContext.md (Problem context/solutions)
      • systemPatterns.md (Architecture/patterns)
      • techContext.md (Tech stack/setup)
      • activeContext.md (Current focus/decisions). This file is informed by all other context files.
    • Status (Green): progress.md (Status/roadmap). Tracks implementation based on the active context.

    Custom Files (Dashed)

    You can add custom documentation as needed (e.g., features/*.md, api/*.md, deployment/*.md). These must be referenced in activeContext.md when added.

    Access and Update Patterns

    • Access Pattern: Always read files in hierarchical order (Foundation $\rightarrow$ Context $\rightarrow$ Status).
    • Update Pattern: Always update in reverse order (progress.md $\rightarrow$ activeContext.md $\rightarrow$ others).
  3. Configure .clinerules for Project Intelligence

    main

    The .clinerules file is used for continuous learning and should be updated to capture:

    • Critical implementation paths.
    • User workflow preferences.
    • Tool usage patterns.
    • Project-specific decisions.

    This creates a cycle of continuous validation, updating, and application to improve task execution.

  4. Run Memory Bank MCP via Docker

    main

    If you prefer running the server in a containerized environment, follow these steps:

    1. Build the image: docker build -t memory-bank-mcp:local .

    2. Test the container: Run a command to verify the mount and environment variables.

    3. Configure MCP client (e.g., Roo Code) to use Docker: Map the local memory bank directory to /mnt/memory_bank inside the container and set the MEMORY_BANK_ROOT environment variable to /mnt/memory_bank.

    "allpepper-memory-bank": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", 
        "MEMORY_BANK_ROOT",
        "-v", 
        "/path/to/memory-bank:/mnt/memory_bank",
        "memory-bank-mcp:local"
      ],
      "env": {
        "MEMORY_BANK_ROOT": "/mnt/memory_bank"
      },
      "disabled": false,
      "alwaysAllow": [
        "list_projects",
        "list_project_files",
        "memory_bank_read",
        "memory_bank_update",
        "memory_bank_write"
      ]
    }
  5. Use Key Commands to manage the Memory Bank

    main

    The Memory Bank is managed through specific natural language commands that trigger different operational flows. Use these commands to control the AI's behavior and state:

    • follow your custom instructions: Triggers Pre-Flight Validation, follows the Memory Bank Access Pattern, and executes the appropriate Mode flow (Plan or Act).
    • initialize memory bank: Performs Pre-Flight Validation, creates a new project if necessary, and establishes the core file structure.
    • update memory bank: Triggers Documentation Updates, performs a full file re-read, and updates the bank based on the current state.
    1. "follow your custom instructions"
    2. "initialize memory bank"
    3. "update memory bank"
  6. Configure Memory Bank MCP for Cline or Roo Code

    main

    To use the server with Cline or Roo Code, add the allpepper-memory-bank configuration to your MCP settings file.

    File Locations:

    • Cline extension: ~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
    • Roo Code VS Code extension: ~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/mcp_settings.json

    Configuration Schema:

    • MEMORY_BANK_ROOT: The absolute path to the directory where your project memory banks are stored.
    • disabled: Set to false to enable the server.
    • autoApprove: A list of tools that can run without explicit user confirmation. Recommended tools include memory_bank_read, memory_bank_write, memory_bank_update, list_projects, and list_project_files.
    {
      "allpepper-memory-bank": {
        "command": "npx",
        "args": ["-y", "@allpepper/memory-bank-mcp"],
        "env": {
          "MEMORY_BANK_ROOT": "<path-to-bank>"
        },
        "disabled": false,
        "autoApprove": [
          "memory_bank_read",
          "memory_bank_write",
          "memory_bank_update",
          "list_projects",
          "list_project_files"
        ]
      }
    }
  7. Configure Memory Bank MCP for Claude Desktop or Claude Code

    main

    Locate your Claude configuration file and add the allPepper-memory-bank entry under the mcpServers property.

    File Locations:

    • Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Claude Code: ~/.claude.json

    Configuration: Ensure you replace YOUR PATH with the actual directory where your memory banks reside.

    "allPepper-memory-bank": {
      "type": "stdio",
      "command": "npx",
      "args": [
        "-y",
        "@allpepper/memory-bank-mcp@latest"
      ],
      "env": {
        "MEMORY_BANK_ROOT": "YOUR PATH"
      }
    }
  8. Configure Memory Bank MCP for Cursor

    main

    In Cursor, navigate to Settings -> Features -> Add MCP Server. Use the following command string, replacing <path-to-bank> with your actual directory path:

    env MEMORY_BANK_ROOT=<path-to-bank> npx -y @allpepper/memory-bank-mcp@latest
  9. Install Memory Bank MCP Server via Smithery

    main

    To automatically install the Memory Bank MCP server for Claude Desktop, use the Smithery CLI. This command handles the configuration setup for you.

    npx -y @smithery/cli install @alioshr/memory-bank-mcp --client claude
  10. Format JSON operations for Act Mode

    main

    When performing JSON operations in Act Mode, you must adhere to strict formatting requirements to ensure successful execution:

    • Use \n for newlines.
    • Provide pure JSON (no XML wrappers).
    • Use lowercase for boolean values (true/false).

    Example JSON structure:

    {
      "projectName": "project-id",
      "fileName": "progress.md",
      "content": "Escaped\ncontent"
    }
    {
      "projectName": "project-id",
      "fileName": "progress.md",
      "content": "Escaped\ncontent"
    }
  11. Reference: Memory Bank MCP Operations

    main

    The server provides the following core operations via the MCP protocol. These can be used in autoApprove or alwaysAllow settings to streamline AI workflows.

    - memory_bank_read: Read memory bank files
    - memory_bank_write: Create new memory bank files
    - memory_bank_update: Update existing memory bank files
    - list_projects: List available projects
    - list_project_files: List files within a project
  12. Use McpRouterAdapter to manage MCP tools and routes

    main

    The McpRouterAdapter class is used to register and manage Model Context Protocol (MCP) tools. It maps tool names to their respective schemas (of type Tool) and asynchronous request handlers.

    Key methods for managing tools:

    • setTool({ schema, handler }): Registers a new tool. It accepts an object containing a schema (the Tool definition) and a handler (an async function that processes MCPRequest and returns MCPResponse). This method is chainable.
    • getToolHandler(name): Retrieves the async handler for a specific tool by its name.
    • getToolsSchemas(): Returns an array of all registered Tool schemas.
    • getToolCapabilities(): Returns an object mapping tool names to their corresponding Tool schemas, useful for exposing available capabilities to an MCP client.
    import { McpRouterAdapter } from './path-to-adapter';
    import { Tool } from "@modelcontextprotocol/sdk/types.js";
    
    const adapter = new McpRouterAdapter();
    
    // Define a tool schema
    const myToolSchema: Tool = {
      name: "example_tool",
      description: "An example tool",
      inputSchema: { type: "object", properties: {} }
    };
    
    // Define a handler
    const myHandler = async (request: any) => {
      return { content: [{ type: "text", text: "Hello from tool" }] };
    };
    
    // Register the tool
    adapter.setTool({
      schema: myToolSchema,
      handler: Promise.resolve(myHandler)
    });
    
    // Retrieve capabilities
    const capabilities = adapter.getToolCapabilities();
    // Result: { "example_tool": myToolSchema }