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
| Name | Required | Description | Default |
|---|---|---|---|
| library_name | Yes | Name of the library to switch to |
Implementation Reference
- src/index.ts:456-480 (handler)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}` }; } }
- src/index.ts:912-941 (handler)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 }; } }
- src/index.ts:1273-1291 (schema)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);