@@ -2,7 +2,7 @@ import { RouterProvider } from "react-router-dom"
22import { router } from "./router"
33import { useAtom , useAtomValue , useSetAtom } from "jotai"
44import { removeOapConfigAtom , writeOapConfigAtom } from "./atoms/configState"
5- import { useEffect } from "react"
5+ import { useEffect , useRef , useState } from "react"
66import { handleGlobalHotkey } from "./atoms/hotkeyState"
77import { handleWindowResizeAtom } from "./atoms/sidebarState"
88import { systemThemeAtom } from "./atoms/themeState"
@@ -16,8 +16,11 @@ import { setModelSettings } from "./ipc/config"
1616import { oapGetMe , oapGetToken , oapLogout , registBackendEvent } from "./ipc"
1717import { refreshConfig } from "./ipc/host"
1818import { openOverlayAtom } from "./atoms/layerState"
19+ import PopupConfirm from "./components/PopupConfirm"
1920
2021function App ( ) {
22+ const { t } = useTranslation ( )
23+
2124 const setSystemTheme = useSetAtom ( systemThemeAtom )
2225 const handleWindowResize = useSetAtom ( handleWindowResizeAtom )
2326 const setOAPUser = useSetAtom ( oapUserAtom )
@@ -32,7 +35,10 @@ function App() {
3235 const loadMcpConfig = useSetAtom ( loadMcpConfigAtom )
3336 const loadOapTools = useSetAtom ( loadOapToolsAtom )
3437 const openOverlay = useSetAtom ( openOverlayAtom )
38+
3539 const setInstallToolBuffer = useSetAtom ( installToolBufferAtom )
40+ const installToolBuffer = useRef < { name : string , config : any } | null > ( null )
41+ const [ installToolConfirm , setInstallToolConfirm ] = useState ( false )
3642
3743 useEffect ( ( ) => {
3844 console . log ( "set model setting" , modelSetting )
@@ -67,6 +73,21 @@ function App() {
6773 }
6874 }
6975
76+ const openToolPageWithMcpServerJson = ( data ?: { name : string , config : any } ) => {
77+ if ( ! data && ! installToolBuffer . current ) {
78+ return
79+ }
80+
81+ try {
82+ data = data || installToolBuffer . current !
83+ const { name, config } = data
84+ setInstallToolBuffer ( prev => [ ...prev , { name, config } ] )
85+ openOverlay ( "Tools" )
86+ } catch ( e ) {
87+ console . error ( "mcp install error" , e )
88+ }
89+ }
90+
7091 // handle backend event
7192 useEffect ( ( ) => {
7293 const unregistLogin = registBackendEvent ( "login" , ( ) => {
@@ -100,15 +121,18 @@ function App() {
100121 } )
101122
102123 const unlistenMcpInstall = registBackendEvent ( "mcp.install" , ( data : { name : string , config : string } ) => {
103- try {
104- const { name } = data
105- const config = JSON . parse ( atob ( data . config ) )
106- console . log ( config )
107- setInstallToolBuffer ( prev => [ ...prev , { name, config } ] )
108- openOverlay ( "Tools" )
109- } catch ( e ) {
110- console . error ( "oap mcp install error" , e )
124+ const _config = JSON . parse ( atob ( data . config ) )
125+ if ( ! _config . transport ) {
126+ return
111127 }
128+
129+ if ( _config . transport === "stdio" ) {
130+ setInstallToolConfirm ( true )
131+ installToolBuffer . current = { name : data . name , config : _config }
132+ return
133+ }
134+
135+ openToolPageWithMcpServerJson ( { name : data . name , config : _config } )
112136 } )
113137
114138 return ( ) => {
@@ -161,10 +185,35 @@ function App() {
161185 document . documentElement . lang = langCode
162186 } , [ i18n . language ] )
163187
188+ const closeInstallTool = ( ) => {
189+ setInstallToolConfirm ( false )
190+ installToolBuffer . current = null
191+ }
192+
164193 return (
165194 < >
166195 < RouterProvider router = { router } />
167196 < Updater />
197+
198+ { installToolConfirm &&
199+ < PopupConfirm
200+ confirmText = { t ( "common.confirm" ) }
201+ cancelText = { t ( "common.cancel" ) }
202+ onConfirm = { ( ) => {
203+ openToolPageWithMcpServerJson ( )
204+ closeInstallTool ( )
205+ } }
206+ onCancel = { closeInstallTool }
207+ onClickOutside = { closeInstallTool }
208+ noBorder
209+ footerType = "center"
210+ zIndex = { 1000 }
211+ className = "mcp-install-confirm-modal"
212+ >
213+ { t ( "deeplink.mcpInstallConfirm" ) }
214+ < pre > { installToolBuffer . current ! . config . command } { installToolBuffer . current ! . config . args . join ( " " ) } </ pre >
215+ </ PopupConfirm >
216+ }
168217 </ >
169218 )
170219}
0 commit comments