Skip to main content
Glama

switch_memory_library

Switch between memory libraries to manage data for different contexts or projects. The current session state is saved before the switch, ensuring continuity. Input the library name to activate the desired memory structure.

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

  • Tool definition with input schema for validating the library_name 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:1302-1315 (registration)
    Registers SWITCH_LIBRARY_TOOL in the MCP server's tool list.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ 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 ], }));
  • MCP CallToolRequestSchema dispatch case that extracts arguments and delegates to AdvancedReasoningServer.switchLibrary.
    case "switch_memory_library": const { library_name: switchLibName } = args as { library_name: string }; return await reasoningServer.switchLibrary(switchLibName);
  • AdvancedReasoningServer.switchLibrary: Calls CognitiveMemory.switchLibrary and formats the response for MCP protocol with additional stats.
    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 }; } }
  • CognitiveMemory.switchLibrary: Core implementation - verifies library file exists, saves current state to disk if needed, loads the target library file.
    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}` }; } }

Other Tools

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

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