import React, { useState } from 'react'; import { Box, Typography, Card, CardContent, Grid, Button, Switch, FormControlLabel, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Chip, IconButton, Menu, MenuItem, TextField, Dialog, DialogTitle, DialogContent, DialogActions, Alert, Tabs, Tab, } from '@mui/material'; import { Add as AddIcon, MoreVert as MoreVertIcon, Settings as SettingsIcon, Link as LinkIcon, Security as SecurityIcon, Speed as SpeedIcon, CheckCircle as CheckCircleIcon, Error as ErrorIcon, } from '@mui/icons-material'; import { styled } from '@mui/material/styles'; const PageContainer = styled(Box)(({ theme }) => ({ padding: '1.5rem', backgroundColor: '#F8F9FA', minHeight: 'calc(100vh - 60px)', })); const PageHeader = styled(Box)(({ theme }) => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '1.5rem', })); const StatusCard = styled(Card)(({ theme }) => ({ height: '100%', border: '1px solid #E5E5E5', transition: 'all 0.2s ease-in-out', '&:hover': { boxShadow: '0 4px 12px rgba(0,0,0,0.1)', }, })); const StatusChip = styled(Chip)<{ status: string }>(({ status, theme }) => ({ fontSize: '0.75rem', height: '24px', backgroundColor: status === 'connected' ? '#E8F5E8' : status === 'connecting' ? '#FFF3CD' : status === 'error' ? '#F8D7DA' : '#F8F9FA', color: status === 'connected' ? '#155724' : status === 'connecting' ? '#856404' : status === 'error' ? '#721C24' : '#666', })); const mockMCPServers = [ { id: 1, name: 'File System Server', description: '文件系统操作服务器', url: 'mcp://localhost:3001', status: 'connected', version: '1.0.0', tools: ['read_file', 'write_file', 'list_directory'], lastPing: '2024-01-15 14:30:25', }, { id: 2, name: 'Database Server', description: '数据库查询服务器', url: 'mcp://db.example.com:3002', status: 'connected', version: '1.2.1', tools: ['query_sql', 'execute_sql', 'get_schema'], lastPing: '2024-01-15 14:30:20', }, { id: 3, name: 'Web Scraper', description: '网页抓取服务器', url: 'mcp://scraper.example.com:3003', status: 'connecting', version: '0.9.5', tools: ['scrape_url', 'extract_text', 'get_links'], lastPing: '2024-01-15 14:28:15', }, { id: 4, name: 'API Gateway', description: 'API网关服务器', url: 'mcp://api.example.com:3004', status: 'error', version: '2.1.0', tools: ['call_api', 'auth_token', 'rate_limit'], lastPing: '2024-01-15 14:25:10', }, ]; const MCP: React.FC = () => { const [tabValue, setTabValue] = useState(0); const [anchorEl, setAnchorEl] = useState(null); const [selectedServer, setSelectedServer] = useState(null); const [dialogOpen, setDialogOpen] = useState(false); const [newServer, setNewServer] = useState({ name: '', url: '', description: '', }); const handleTabChange = (event: React.SyntheticEvent, newValue: number) => { setTabValue(newValue); }; const handleMenuClick = (event: React.MouseEvent, serverId: number) => { setAnchorEl(event.currentTarget); setSelectedServer(serverId); }; const handleMenuClose = () => { setAnchorEl(null); setSelectedServer(null); }; const handleAddServer = () => { setDialogOpen(true); }; const handleDialogClose = () => { setDialogOpen(false); setNewServer({ name: '', url: '', description: '' }); }; const handleSaveServer = () => { // 保存服务器逻辑 console.log('添加服务器:', newServer); handleDialogClose(); }; const connectedServers = mockMCPServers.filter(s => s.status === 'connected').length; const totalTools = mockMCPServers.reduce((acc, server) => acc + server.tools.length, 0); return ( MCP 协议管理 Model Context Protocol - 模型上下文协议服务器管理 {tabValue === 0 && ( <> {/* 状态概览 */} 连接服务器 {connectedServers} 总服务器数 {mockMCPServers.length} 可用工具 {totalTools} 平均延迟 45ms {/* 服务器列表 */} MCP 服务器列表 服务器名称 URL 状态 版本 工具数量 最后心跳 操作 {mockMCPServers.map((server) => ( {server.name} {server.description} {server.url} {server.tools.length} 个工具 {server.lastPing} handleMenuClick(e, server.id)} > ))}
)} {tabValue === 1 && ( 工具配置 配置各个 MCP 服务器提供的工具和权限设置 {mockMCPServers.map((server) => ( {server.name} {server.tools.map((tool, index) => ( } label={ {tool} } /> ))} ))} )} {tabValue === 2 && ( 安全监控 SSL/TLS 加密 身份验证 访问控制 审计日志 性能监控 平均响应时间 45ms 过去24小时内的平均值 成功率 99.2% 过去24小时内的成功率 )} {/* 菜单 */} 配置 测试连接 查看日志 断开连接 {/* 添加服务器对话框 */} 添加 MCP 服务器 setNewServer(prev => ({ ...prev, name: e.target.value }))} /> setNewServer(prev => ({ ...prev, url: e.target.value }))} /> setNewServer(prev => ({ ...prev, description: e.target.value }))} />
); }; export default MCP;