import React, { useState, useRef, useEffect, type ReactNode } from 'react'; import { Button, Row, Col, App, List, Space, } from 'antd'; import { LinkOutlined } from '@ant-design/icons'; import { useTranslation } from 'react-i18next'; import type { ToolItem, Query, McpServiceModalRef } from './types'; import McpServiceModal from './components/McpServiceModal'; import SearchInput from '@/components/SearchInput' import BodyWrapper from '@/components/Empty/BodyWrapper' import RbCard from '@/components/RbCard/Card' import { getTools, deleteTool, testConnection } from '@/api/tools' const Mcp: React.FC<{ getStatusTag: (status: string) => ReactNode }> = ({ getStatusTag }) => { const { t } = useTranslation(); const { message, modal } = App.useApp() const [loading, setLoading] = useState(false); const [data, setData] = useState([]); const [query, setQuery] = useState({ name: undefined, tool_type: 'mcp' }); const addServiceModalRef = useRef(null); useEffect(() => { getData() }, [query.name]) const getData = () => { setLoading(true) getTools(query) .then((res) => { setData(res as ToolItem[]) }) .finally(() => { setLoading(false) }) } const handleSearch = (value?: string) => { setQuery(prev => ({ ...prev, name: value })) } // 打开添加服务弹窗 const handleEdit = (data?: ToolItem) => { addServiceModalRef.current?.handleOpen(data); }; // 测试连接 const handleTestConnection = (item: ToolItem) => { if (!item.id) { return } testConnection(item.id) .then(() => { message.success(t('tool.testConnectionSuccess')); }) .finally(() => { getData() }) }; // 删除服务 const handleDeleteService = (item: ToolItem) => { if (!item.id) { return } modal.confirm({ title: t('common.confirmDeleteDesc', { name: item.name }), okText: t('common.delete'), cancelText: t('common.cancel'), okType: 'danger', onOk: () => { deleteTool(item.id as string) .then(() => { message.success(t('common.deleteSuccess')); getData() }) } }) }; return (
( // {item.name[0]} //
// } title={item.name} extra={getStatusTag(item.status)} >
{[ 'server_url', 'last_health_check', ].map(key => { const value = item.config_data?.[key as keyof typeof item.config_data]; let displayValue: React.ReactNode; if (key === 'last_health_check') { displayValue = value ? new Date(value as number).toLocaleString() : '-'; } else if (typeof value === 'string' || typeof value === 'number') { displayValue = value; } else { displayValue = '-'; } return (
{t(`tool.${key}`)}
{displayValue}
); })}
handleEdit(item)} >
handleDeleteService(item)} >
)} className="rb:h-[calc(100vh-178px)] rb:overflow-y-auto rb:overflow-x-hidden" /> {/* 添加服务弹窗组件 */} ); }; export default Mcp;