Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🪟 fix: Tab Isolation for Agent Favorites + MCP Selections (#11786)
Danny Aviladc489e7b251d
diff --git a/client/src/hooks/MCP/useMCPSelect.ts b/client/src/hooks/MCP/useMCPSelect.tsindex ec9dfe0bbb..e0118b8be1 100644--- a/client/src/hooks/MCP/useMCPSelect.ts+++ b/client/src/hooks/MCP/useMCPSelect.ts@@ -28,7 +28,7 @@ export function useMCPSelect({const mcps = ephemeralAgent?.mcp ?? [];if (mcps.length === 1 && mcps[0] === Constants.mcp_clear) {setMCPValuesRaw([]);- } else if (mcps.length > 0) {+ } else if (mcps.length > 0 && configuredServers.size > 0) {// Strip out servers that are not available in the startup configconst activeMcps = mcps.filter((mcp) => configuredServers.has(mcp));setMCPValuesRaw(activeMcps);diff --git a/client/src/store/favorites.ts b/client/src/store/favorites.tsindex b3744f52b0..9065f1ca4e 100644--- a/client/src/store/favorites.ts+++ b/client/src/store/favorites.ts@@ -1,4 +1,4 @@-import { createStorageAtom } from './jotai-utils';+import { createTabIsolatedAtom } from './jotai-utils';export type Favorite = {agentId?: string;@@ -16,4 +16,4 @@ export type FavoritesState = Favorite[];/*** This atom stores the user's favorite models/agents*/-export const favoritesAtom = createStorageAtom<FavoritesState>('favorites', []);+export const favoritesAtom = createTabIsolatedAtom<FavoritesState>('favorites', []);diff --git a/client/src/store/jotai-utils.ts b/client/src/store/jotai-utils.tsindex d3ca9d817c..5d2769d7e9 100644--- a/client/src/store/jotai-utils.ts+++ b/client/src/store/jotai-utils.ts@@ -1,5 +1,6 @@import { atom } from 'jotai';import { atomWithStorage } from 'jotai/utils';+import type { SyncStorage } from 'jotai/vanilla/utils/atomWithStorage';/*** Create a simple atom with localStorage persistence@@ -42,6 +43,68 @@ export function createStorageAtomWithEffect<T>();}+/**+ * Create a SyncStorage adapter that reads/writes to localStorage but does NOT+ * subscribe to browser `storage` events. This prevents cross-tab synchronization+ * for atoms where each tab should maintain independent state.+ *+ * Use this for atoms that represent per-tab working state (e.g., favorites toggle,+ * MCP server selections) rather than user preferences.+ */+export function createTabIsolatedStorage<Value>(): SyncStorage<Value> {+ return {+ getItem(key: string, initialValue: Value): Value {+ if (typeof window === 'undefined') {+ return initialValue;+ }+ try {+ const stored = localStorage.getItem(key);+ if (stored === null) {+ return initialValue;+ }+ return JSON.parse(stored) as Value;+ } catch {+ return initialValue;+ }+ },+ setItem(key: string, newValue: Value): void {+ if (typeof window === 'undefined') {+ return;+ }+ try {+ localStorage.setItem(key, JSON.stringify(newValue));+ } catch {+ // quota exceeded or other write error — silently ignore+ }+ },+ removeItem(key: string): void {+ if (typeof window === 'undefined') {+ return;+ }+ try {+ localStorage.removeItem(key);+ } catch {+ // silently ignore+ }+ },+ // subscribe intentionally omitted — prevents cross-tab sync via storage events+ };+}++/**+ * Create an atom with localStorage persistence that does NOT sync across tabs.+ * Parallels `createStorageAtom` but uses tab-isolated storage.+ *+ * @param key - localStorage key+ * @param defaultValue - default value if no saved value exists+ * @returns Jotai atom with localStorage persistence, isolated per tab+ */+export function createTabIsolatedAtom<T>(key: string, defaultValue: T) {+ return atomWithStorage<T>(key, defaultValue, createTabIsolatedStorage<T>(), {+ getOnInit: true,+ });+}+/*** Initialize a value from localStorage and optionally apply it* Useful for applying saved values on app startup (e.g., theme, fontSize)diff --git a/client/src/store/mcp.ts b/client/src/store/mcp.tsindex e540b167e4..793e1cebd0 100644--- a/client/src/store/mcp.ts+++ b/client/src/store/mcp.ts@@ -1,6 +1,14 @@import { atom } from 'jotai';import { atomFamily, atomWithStorage } from 'jotai/utils';import { Constants, LocalStorageKeys } from 'librechat-data-provider';+import { createTabIsolatedStorage } from './jotai-utils';++/**+ * Tab-isolated storage for MCP values — prevents cross-tab sync so that+ * each tab's MCP server selections are independent (especially for new chats+ * which all share the same `LAST_MCP_new` localStorage key).+ */+const mcpTabIsolatedStorage = createTabIsolatedStorage<string[]>();/*** Creates a storage atom for MCP values per conversation@@ -10,7 +18,7 @@ export const mcpValuesAtomFamily = atomFamily((conversationId: string | null) =>const key = conversationId ?? Constants.NEW_CONVO;const storageKey = `${LocalStorageKeys.LAST_MCP_}${key}`;- return atomWithStorage<string[]>(storageKey, [], undefined, { getOnInit: true });+ return atomWithStorage<string[]>(storageKey, [], mcpTabIsolatedStorage, { getOnInit: true });});/**