@@ -5,7 +5,7 @@ import { POLL_INTERVAL } from '../Constants';
5
5
6
6
interface MCPClientContextType {
7
7
// State
8
- mcpClientStates : { [ name : string ] : MCPClientState } ;
8
+ mcpClientStates : { [ name : string ] : MCPClientState } | undefined ;
9
9
buttonsLoading : { [ name : string ] : boolean } ;
10
10
11
11
// Actions
@@ -30,22 +30,28 @@ interface MCPClientProviderProps {
30
30
31
31
export function MCPClientProvider ( { children, client } : MCPClientProviderProps ) {
32
32
// State
33
- const [ mcpClientStates , setMcpClientStates ] = useState < { [ name : string ] : MCPClientState } > ( { } ) ;
33
+ const [ mcpClientStates , setMcpClientStates ] = useState < { [ name : string ] : MCPClientState } | undefined > ( undefined ) ;
34
34
const [ buttonsLoading , setButtonsLoading ] = useState < { [ name : string ] : boolean } > ( { } ) ;
35
35
36
36
// Update MCP client states
37
37
const updateMCPClientStates = async ( ) => {
38
- const oldStates = mcpClientStates ;
38
+ const hasExistingState = mcpClientStates !== undefined ;
39
39
const states = await getMCPClientStates ( client )
40
40
setMcpClientStates ( states ) ;
41
+ if ( ! hasExistingState ) {
42
+ return
43
+ }
44
+ const oldStates = { ...mcpClientStates } ;
45
+
46
+ console . log ( 'oldStates' , oldStates , 'states' , states )
41
47
// Whenever a client connection changes, show toast to user
42
- const connectedClient = Object . values ( states ) . find ( state => state . exists && state . configured ) ;
43
- const disconnectedClient = Object . values ( oldStates ) . find ( state => state . exists && ! state . configured && states [ state . client . name ] . configured ) ;
44
- if ( connectedClient && connectedClient . client . name !== 'Gordon' ) {
45
- client . desktopUI . toast . success ( 'MCP Client Connected: ' + connectedClient . client . name + '. Restart it to load the Catalog.' ) ;
48
+ const newlyConnectedClient = Object . values ( states ) . find ( state => state . exists && state . configured && ! oldStates [ state . client . name ] . configured ) ;
49
+ const newlyDisconnectedClient = Object . values ( states ) . find ( state => state . exists && ! state . configured && oldStates [ state . client . name ] . configured ) ;
50
+ if ( newlyConnectedClient ) {
51
+ client . desktopUI . toast . success ( 'Client Connected: ' + newlyConnectedClient . client . name + '. Restart it to load the Catalog.' ) ;
46
52
}
47
- if ( disconnectedClient && disconnectedClient . client . name !== 'Gordon' ) {
48
- client . desktopUI . toast . error ( 'MCP Client Disconnected: ' + disconnectedClient . client . name + '. Restart it to remove the Catalog.' ) ;
53
+ if ( newlyDisconnectedClient ) {
54
+ client . desktopUI . toast . error ( 'Client Disconnected: ' + newlyDisconnectedClient . client . name + '. Restart it to remove the Catalog.' ) ;
49
55
}
50
56
}
51
57
0 commit comments