@@ -4,6 +4,17 @@ import { Blocks, MoreVertical, Plus, ServerCog } from "lucide-react"
44import { Api , type DomainCreateUserMCPUpstreamReq , type DomainMCPTool , type DomainMCPUpstream } from "@/api/Api"
55import { Badge } from "@/components/ui/badge"
66import { Button } from "@/components/ui/button"
7+ import {
8+ AlertDialog ,
9+ AlertDialogAction ,
10+ AlertDialogCancel ,
11+ AlertDialogContent ,
12+ AlertDialogDescription ,
13+ AlertDialogFooter ,
14+ AlertDialogHeader ,
15+ AlertDialogTitle ,
16+ AlertDialogTrigger ,
17+ } from "@/components/ui/alert-dialog"
718import {
819 DropdownMenu ,
920 DropdownMenuContent ,
@@ -37,6 +48,7 @@ export default function ToolsAndMcp() {
3748 const [ isCreating , setIsCreating ] = useState ( false )
3849 const [ isUpdating , setIsUpdating ] = useState ( false )
3950 const [ syncingServerId , setSyncingServerId ] = useState < string | null > ( null )
51+ const [ deletingServerId , setDeletingServerId ] = useState < string | null > ( null )
4052 const [ togglingToolId , setTogglingToolId ] = useState < string | null > ( null )
4153 const [ editingServer , setEditingServer ] = useState < DomainMCPUpstream | null > ( null )
4254
@@ -140,6 +152,29 @@ export default function ToolsAndMcp() {
140152 }
141153 }
142154
155+ const handleDeleteServer = async ( server : DomainMCPUpstream ) => {
156+ if ( ! server . id ) {
157+ toast . error ( "MCP 服务器信息不完整" )
158+ return
159+ }
160+
161+ setDeletingServerId ( server . id )
162+ try {
163+ const api = new Api ( )
164+ const resp = await api . api . v1UsersMcpUpstreamsDelete ( server . id )
165+ if ( resp . data ?. code === 0 ) {
166+ toast . success ( "MCP 服务器删除成功" )
167+ await loadData ( { silent : true } )
168+ } else {
169+ toast . error ( resp . data ?. message || "MCP 服务器删除失败" )
170+ }
171+ } catch {
172+ toast . error ( "MCP 服务器删除失败" )
173+ } finally {
174+ setDeletingServerId ( null )
175+ }
176+ }
177+
143178 const handleToggleTool = async ( tool : DomainMCPTool , enabled : boolean ) => {
144179 if ( ! tool . id ) {
145180 toast . error ( "工具信息不完整" )
@@ -254,7 +289,9 @@ export default function ToolsAndMcp() {
254289 isPlatform,
255290 onEdit,
256291 onSync,
292+ onDelete,
257293 syncing,
294+ deleting,
258295 toolInteractive = false ,
259296 } : {
260297 key : string
@@ -266,7 +303,9 @@ export default function ToolsAndMcp() {
266303 isPlatform ?: boolean
267304 onEdit ?: ( ) => void
268305 onSync ?: ( ) => void
306+ onDelete ?: ( ) => void
269307 syncing ?: boolean
308+ deleting ?: boolean
270309 toolInteractive ?: boolean
271310 } ) => {
272311 return (
@@ -318,14 +357,36 @@ export default function ToolsAndMcp() {
318357 </ Button >
319358 </ DropdownMenuTrigger >
320359 < DropdownMenuContent align = "end" >
321- < DropdownMenuItem onClick = { onEdit } >
360+ < DropdownMenuItem onClick = { onEdit } disabled = { syncing || deleting } >
322361 < IconPencil />
323362 修改
324363 </ DropdownMenuItem >
325- < DropdownMenuItem className = "text-destructive" >
326- < IconTrash />
327- 删除
328- </ DropdownMenuItem >
364+ < AlertDialog >
365+ < AlertDialogTrigger asChild >
366+ < DropdownMenuItem
367+ className = "text-destructive"
368+ onSelect = { ( e ) => { e . preventDefault ( ) } }
369+ disabled = { syncing || deleting }
370+ >
371+ < IconTrash />
372+ { deleting ? "删除中" : "删除" }
373+ </ DropdownMenuItem >
374+ </ AlertDialogTrigger >
375+ < AlertDialogContent >
376+ < AlertDialogHeader >
377+ < AlertDialogTitle > 确认删除</ AlertDialogTitle >
378+ < AlertDialogDescription >
379+ 确定要删除 MCP 服务器 "{ name } " 吗?此操作不可撤销。
380+ </ AlertDialogDescription >
381+ </ AlertDialogHeader >
382+ < AlertDialogFooter >
383+ < AlertDialogCancel disabled = { deleting } > 取消</ AlertDialogCancel >
384+ < AlertDialogAction onClick = { onDelete } disabled = { deleting } >
385+ { deleting ? "删除中..." : "确认删除" }
386+ </ AlertDialogAction >
387+ </ AlertDialogFooter >
388+ </ AlertDialogContent >
389+ </ AlertDialog >
329390 </ DropdownMenuContent >
330391 </ DropdownMenu >
331392 </ ItemActions >
@@ -420,7 +481,9 @@ export default function ToolsAndMcp() {
420481 setIsEditDialogOpen ( true )
421482 } ,
422483 onSync : ( ) => handleSyncServer ( server ) ,
484+ onDelete : ( ) => handleDeleteServer ( server ) ,
423485 syncing : syncingServerId === server . id ,
486+ deleting : deletingServerId === server . id ,
424487 } )
425488 ) }
426489 </ ItemGroup >
0 commit comments