Skip to main content
Glama
diaz3618

memory-bank-mcp

initialize_memory_bank

Set up persistent project memory by initializing a Memory Bank in a specified directory, enabling AI assistants to retain context, decisions, and progress across sessions.

Instructions

Initialize a Memory Bank in the specified directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath where the Memory Bank will be initialized

Implementation Reference

  • Handler function for the initialize_memory_bank tool. Calls memoryBankManager.setCustomPath(), then memoryBankManager.initialize(true) to create core template files, and initializes the mode manager.
    export async function handleInitializeMemoryBank(
      memoryBankManager: MemoryBankManager,
      dirPath: string
    ) {
      try {
        // If dirPath is not provided, use the project path
        const basePath = dirPath || memoryBankManager.getProjectPath();
        
        // Ensure the path is absolute
        const absolutePath = path.isAbsolute(basePath) ? basePath : path.resolve(process.cwd(), basePath);
        console.error('Using absolute path:', absolutePath);
        
        try {
          // Set the custom path first
          await memoryBankManager.setCustomPath(absolutePath);
          
          // Initialize the Memory Bank with createIfNotExists = true
          await memoryBankManager.initialize(true);
          
          // Initialize mode manager (creates missing .mcprules files)
          await memoryBankManager.initializeModeManager();
          
          // Get the Memory Bank directory
          const memoryBankDir = memoryBankManager.getMemoryBankDir();
          
          return {
            content: [
              {
                type: 'text',
                text: `Memory Bank initialized at ${memoryBankDir}`,
              },
            ],
          };
        } catch (initError) {
          // Check if the error is related to .mcprules files
          const errorMessage = String(initError);
          if (errorMessage.includes('.mcprules')) {
            console.warn('Warning: Error related to .mcprules files:', initError);
            console.warn('Continuing with Memory Bank initialization despite .mcprules issues.');
            
            // Use the provided path directly as the memory bank directory
            const memoryBankDir = absolutePath;
            try {
              await FileUtils.ensureDirectory(memoryBankDir);
              memoryBankManager.setMemoryBankDir(memoryBankDir);
              
              return {
                content: [
                  {
                    type: 'text',
                    text: `Memory Bank initialized at ${memoryBankDir} (with warnings about .mcprules files)`,
                  },
                ],
              };
            } catch (dirError) {
              console.error('Failed to create memory-bank directory:', dirError);
              
              // Try to use an existing memory-bank directory if it exists
              if (await FileUtils.fileExists(memoryBankDir) && await FileUtils.isDirectory(memoryBankDir)) {
                memoryBankManager.setMemoryBankDir(memoryBankDir);
                
                return {
                  content: [
                    {
                      type: 'text',
                      text: `Memory Bank initialized at ${memoryBankDir} (with warnings)`,
                    },
                  ],
                };
              }
              
              // If we can't create or find a memory-bank directory, return an error
              return {
                content: [
                  {
                    type: 'text',
                    text: `Failed to initialize Memory Bank: ${dirError}`,
                  },
                ],
              };
            }
          }
          
          // For other errors, return the error message
          return {
            content: [
              {
                type: 'text',
                text: `Failed to initialize Memory Bank: ${initError}`,
              },
            ],
          };
        }
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error initializing Memory Bank: ${error}`,
            },
          ],
        };
      }
    }
  • Tool schema definition for initialize_memory_bank, defining the 'path' string parameter as required.
      name: 'initialize_memory_bank',
      description: 'Initialize a Memory Bank in the specified directory',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path where the Memory Bank will be initialized',
          },
        },
        required: ['path'],
      },
    },
  • Registration of the tool name 'initialize_memory_bank' in the switch/case dispatch inside setupToolHandlers. Extracts the 'path' argument and delegates to the handler.
    case 'initialize_memory_bank': {
      const { path: dirPath } = request.params.arguments as { path: string };
      if (!dirPath) {
        throw new McpError(ErrorCode.InvalidParams, 'Path not specified');
      }
      console.error('Initializing Memory Bank at path:', dirPath);
      return handleInitializeMemoryBank(memoryBankManager, dirPath);
    }
  • Core helper method on MemoryBankManager that sets the custom path and calls initialize(true) to create the memory-bank directory and template files.
    async initializeMemoryBank(dirPath: string): Promise<string> {
      try {
        // Set the custom path
        await this.setCustomPath(dirPath);
        
        // Initialize the Memory Bank
        return await this.initialize(true);
      } catch (error) {
        logger.error('MemoryBankManager', `Failed to initialize Memory Bank: ${error}`);
        throw new Error(`Failed to initialize Memory Bank: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose side effects but only says 'Initialize a Memory Bank'. It does not mention what happens if the bank already exists, permissions needed, or any destructive potential.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence with no wasted words. It is concise, though very brief; it could expand slightly without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one parameter and no output schema, the description is minimally adequate. However, it lacks context about prerequisites or post-conditions, leaving some gaps for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with a clear description for the 'path' parameter. The tool description adds no extra semantic value beyond what the schema already provides, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Initialize' and resource 'Memory Bank', with the specific directory. It is specific enough to distinguish from sibling tools like 'set_memory_bank_path' which implies an existing bank, but does not explicitly state this distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'set_memory_bank_path' or what prerequisites exist. The description gives no context about appropriate scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/diaz3618/memory-bank-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server