Skip to main content
Glama
angrysky56

Advanced Reasoning MCP Server

switch_memory_library

Change memory libraries to organize project data, saving current session state before switching contexts.

Instructions

Switch to a different memory library.

Allows you to switch between different memory libraries for different contexts or projects. Current session state is saved before switching.

Parameters:

  • library_name: Name of the library to switch to (required)

Returns success status and message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
library_nameYesName of the library to switch to

Implementation Reference

  • Core handler logic in CognitiveMemory class: validates library existence via file check, saves current library state if modified, loads the target library JSON file, returns success/failure with message.
    async switchLibrary(libraryName: string): Promise<{ success: boolean; message: string }> {
      try {
        const fileName = `${libraryName}.json`;
        const filePath = path.join(this.memoryDataPath, fileName);
    
        // Check if library exists
        try {
          await fs.access(filePath);
        } catch {
          return { success: false, message: `Library "${libraryName}" does not exist` };
        }
    
        // Save current state if we have unsaved changes
        if (this.nodes.size > 0 || this.sessions.size > 0) {
          await this.saveToFile();
        }
    
        // Load the new library
        await this.loadFromFile(libraryName);
    
        return { success: true, message: `Switched to library: ${libraryName}` };
      } catch (error) {
        return { success: false, message: `Failed to switch library: ${error}` };
      }
    }
  • MCP tool handler in AdvancedReasoningServer: delegates to CognitiveMemory.switchLibrary, formats response as MCP content with JSON including stats and sets isError flag.
    public async switchLibrary(libraryName: string): Promise<{ content: Array<{ type: string; text: string }>; isError?: boolean }> {
      try {
        const result = await this.memory.switchLibrary(libraryName);
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              libraryName,
              success: result.success,
              message: result.message,
              currentLibrary: this.memory.getCurrentLibraryName(),
              memoryStats: this.memory.getMemoryStats()
            }, null, 2)
          }],
          isError: !result.success
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              error: error instanceof Error ? error.message : String(error),
              status: 'failed'
            }, null, 2)
          }],
          isError: true
        };
      }
    }
  • Tool schema definition with name, description, and inputSchema requiring 'library_name' string parameter.
    const SWITCH_LIBRARY_TOOL: Tool = {
      name: "switch_memory_library",
      description: `Switch to a different memory library.
    
    Allows you to switch between different memory libraries for different contexts or projects.
    Current session state is saved before switching.
    
    Parameters:
    - library_name: Name of the library to switch to (required)
    
    Returns success status and message.`,
      inputSchema: {
        type: "object",
        properties: {
          library_name: { type: "string", description: "Name of the library to switch to" }
        },
        required: ["library_name"]
      }
    };
  • src/index.ts:1396-1406 (registration)
    Registration of the tool in the ListToolsRequestSchema handler's tools array.
      ADVANCED_REASONING_TOOL,
      QUERY_MEMORY_TOOL,
      CREATE_LIBRARY_TOOL,
      LIST_LIBRARIES_TOOL,
      SWITCH_LIBRARY_TOOL,
      GET_LIBRARY_INFO_TOOL,
      CREATE_SYSTEM_JSON_TOOL,
      GET_SYSTEM_JSON_TOOL,
      SEARCH_SYSTEM_JSON_TOOL,
      LIST_SYSTEM_JSON_TOOL
    ],
  • src/index.ts:1427-1430 (registration)
    Tool dispatch registration in the CallToolRequestSchema switch statement.
    case "switch_memory_library":
      const { library_name: switchLibName } = args as { library_name: string };
      return await reasoningServer.switchLibrary(switchLibName);

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/angrysky56/advanced-reasoning-mcp'

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