mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-16 12:46:34 +01:00
🔧 fix: MCP Selection Persist and UI Flicker Issues (#9324)
* refactor: useMCPSelect
- Add useGetMCPTools to use in useMCPSelect and elsewhere hooks for fetching MCP tools
- remove memoized key
- remove use of `useChatContext` and require conversationId as prop
* feat: Add MCPPanelContext and integrate conversationId as prop for useMCPSelect across components
- Introduced MCPPanelContext to manage conversationId state.
- Updated MCPSelect, MCPSubMenu, and MCPConfigDialog to accept conversationId as a prop.
- Modified ToolsDropdown and BadgeRow to pass conversationId to relevant components.
- Refactored MCPPanel to utilize MCPPanelProvider for context management.
* fix: remove nested ternary in ServerInitializationSection
- Replaced conditional operator with if-else statements for better readability in determining button text based on server initialization state and reinitialization status.
* refactor: wrap setValueWrap in useCallback for performance optimization
* refactor: streamline useMCPSelect by consolidating storageKey definition
* fix: prevent clearing selections on page refresh by tracking initial load completion
* refactor: simplify concern of useMCPSelect hook
* refactor: move ConfigFieldDetail interface to common types for better reusability, isolate usage of `useGetMCPTools`
* refactor: integrate mcpServerNames into BadgeRowContext and update ToolsDropdown and MCPSelect components
This commit is contained in:
parent
2483623c88
commit
c0511b9a5f
19 changed files with 270 additions and 206 deletions
31
client/src/Providers/MCPPanelContext.tsx
Normal file
31
client/src/Providers/MCPPanelContext.tsx
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import React, { createContext, useContext, useMemo } from 'react';
|
||||
import { Constants } from 'librechat-data-provider';
|
||||
import { useChatContext } from './ChatContext';
|
||||
|
||||
interface MCPPanelContextValue {
|
||||
conversationId: string;
|
||||
}
|
||||
|
||||
const MCPPanelContext = createContext<MCPPanelContextValue | undefined>(undefined);
|
||||
|
||||
export function MCPPanelProvider({ children }: { children: React.ReactNode }) {
|
||||
const { conversation } = useChatContext();
|
||||
|
||||
/** Context value only created when conversationId changes */
|
||||
const contextValue = useMemo<MCPPanelContextValue>(
|
||||
() => ({
|
||||
conversationId: conversation?.conversationId ?? Constants.NEW_CONVO,
|
||||
}),
|
||||
[conversation?.conversationId],
|
||||
);
|
||||
|
||||
return <MCPPanelContext.Provider value={contextValue}>{children}</MCPPanelContext.Provider>;
|
||||
}
|
||||
|
||||
export function useMCPPanelContext() {
|
||||
const context = useContext(MCPPanelContext);
|
||||
if (!context) {
|
||||
throw new Error('useMCPPanelContext must be used within MCPPanelProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue