feat: integrate MCP server initialization into app initialization process

- Added useInitMCPServers hook to manage MCP server state and communication with the main process.
- Updated useAppInit to include useInitMCPServers for improved server management during app initialization.
This commit is contained in:
kangfenmao 2025-03-16 21:05:24 +08:00
parent 8c5273d47d
commit 555c5baafa
2 changed files with 11 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import { useEffect } from 'react'
import { useDefaultModel } from './useAssistant'
import useFullScreenNotice from './useFullScreenNotice'
import { useInitMCPServers } from './useMCPServers'
import { useRuntime } from './useRuntime'
import { useSettings } from './useSettings'
import useUpdateHandler from './useUpdateHandler'
@ -22,8 +23,8 @@ export function useAppInit() {
const avatar = useLiveQuery(() => db.settings.get('image://avatar'))
useUpdateHandler()
useFullScreenNotice()
useInitMCPServers()
useEffect(() => {
avatar?.value && dispatch(setAvatar(avatar.value))

View File

@ -10,19 +10,10 @@ ipcRenderer.on('mcp:servers-changed', (_event, servers) => {
store.dispatch(setMCPServers(servers))
})
// Send initial servers state to main process
const initialServers = store.getState().mcp.servers
ipcRenderer.send('mcp:servers-from-renderer', initialServers)
export const useMCPServers = () => {
const mcpServers = useAppSelector((state) => state.mcp.servers)
const dispatch = useAppDispatch()
// Send servers to main process when they change in Redux
useEffect(() => {
ipcRenderer.send('mcp:servers-from-renderer', mcpServers)
}, [mcpServers])
// Initial load of MCP servers from main process
useEffect(() => {
const loadServers = async () => {
@ -90,3 +81,12 @@ export const useMCPServers = () => {
getActiveMCPServers
}
}
export const useInitMCPServers = () => {
const mcpServers = useAppSelector((state) => state.mcp.servers)
// Send servers to main process when they change in Redux
useEffect(() => {
ipcRenderer.send('mcp:servers-from-renderer', mcpServers)
}, [mcpServers])
}