'use client'; import { useEffect, useState } from 'react'; import styles from '@/app/home/plugins/plugins.module.css'; import MCPCardComponent from '@/app/home/plugins/mcp/mcp-card/MCPCardComponent'; import { MCPCardVO } from '@/app/home/plugins/mcp/MCPCardVO'; import { useTranslation } from 'react-i18next'; import { httpClient } from '@/app/infra/http/HttpClient'; export default function MCPMarketComponent({ onEditServer, toolsCountCache = {}, }: { askInstallServer?: (githubURL: string) => void; onEditServer?: (serverName: string) => void; toolsCountCache?: Record; }) { const { t } = useTranslation(); const [installedServers, setInstalledServers] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { initData(); }, []); useEffect(() => { fetchInstalledServers(); }, [toolsCountCache]); function initData() { fetchInstalledServers(); } function fetchInstalledServers() { setLoading(true); httpClient .getMCPServers() .then((resp) => { const servers = resp.servers.map((server) => { const vo = new MCPCardVO(server); if (toolsCountCache[server.name] !== undefined) { vo.tools = toolsCountCache[server.name]; } return vo; }); setInstalledServers(servers); setLoading(false); }) .catch((error) => { console.error('Failed to fetch MCP servers:', error); setLoading(false); }); } return (
{/* 已安装的服务器列表 */}
{loading ? (
{t('mcp.loading')}
) : installedServers.length === 0 ? (
{t('mcp.noServerInstalled')}
) : ( installedServers.map((server, index) => (
{ if (onEditServer) { onEditServer(server.name); } }} onRefresh={fetchInstalledServers} />
)) )}
); }