import React, { useState } from "react"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { PencilAltIcon, TrashIcon } from "@heroicons/react/outline"; import { Modal, Tooltip, message, } from "antd"; import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, Icon, Button, Grid, Col, Title, TextInput, } from "@tremor/react"; import { deleteMCPServer, fetchMCPServers, } from "../networking"; import { MCPServer, MCPServerProps, handleAuth, handleTransport, } from "./types"; import { isAdminRole } from "@/utils/roles"; import { MCPServerView } from "./mcp_server_view"; import CreateMCPServer from "./create_mcp_server"; const displayFriendlyId = (id: string) => { return `${id.slice(0, 7)}...`; }; interface DeleteModalProps { isModalOpen: boolean; title: string; confirmDelete: () => void; cancelDelete: () => void; } const DeleteModal: React.FC = ({ isModalOpen, title, confirmDelete, cancelDelete, }) => { if (!isModalOpen) return null; return ( {title}

Are you sure you want to delete this MCP Server?

); }; const MCPServers: React.FC = ({ accessToken, userRole, userID, }) => { // Query to fetch MCP tools const { data: mcpServers, isLoading: isLoadingServers, refetch, } = useQuery({ queryKey: ["mcpServers"], queryFn: () => { if (!accessToken) throw new Error("Access Token required"); return fetchMCPServers(accessToken); }, enabled: !!accessToken, }); const createMCPServer = (newMcpServer: MCPServer) => { refetch(); }; // state const [serverIdToDelete, setServerToDelete] = useState(null); const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedServerId, setSelectedServerId] = useState(null); const [editServer, setEditServer] = useState(false); const handleDelete = (server_id: string) => { // Set the team to delete and open the confirmation modal setServerToDelete(server_id); setIsDeleteModalOpen(true); }; const confirmDelete = async () => { if (serverIdToDelete == null || accessToken == null) { return; } try { await deleteMCPServer(accessToken, serverIdToDelete); // Successfully completed the deletion. Update the state to trigger a rerender. message.success("Deleted MCP Server successfully"); refetch(); } catch (error) { console.error("Error deleting the mcp server:", error); // Handle any error situations, such as displaying an error message to the user. } // Close the confirmation modal and reset the serverToDelete setIsDeleteModalOpen(false); setServerToDelete(null); }; const cancelDelete = () => { // Close the confirmation modal and reset the serverToDelete setIsDeleteModalOpen(false); setServerToDelete(null); }; if (!accessToken || !userRole || !userID) { return (
Missing required authentication parameters.
); } return (
{selectedServerId ? ( server.server_id === selectedServerId ) || {} } onBack={() => setSelectedServerId(null)} isProxyAdmin={isAdminRole(userRole)} isEditing={editServer} accessToken={accessToken} userID={userID} userRole={userRole} /> ) : (

MCP Servers

Server ID Server Name Description Transport Auth Type Url Created Info {!mcpServers || mcpServers.length == 0 ? [] : mcpServers.map((mcpServer: MCPServer) => (
{mcpServer.alias} {mcpServer.description} {handleTransport(mcpServer.transport)} {handleAuth(mcpServer.auth_type)}
{mcpServer.url}
{mcpServer.created_at ? new Date(mcpServer.created_at).toLocaleDateString() : "N/A"} {isAdminRole(userRole) ? ( <> { setSelectedServerId(mcpServer.server_id); setEditServer(true); }} /> handleDelete(mcpServer.server_id)} icon={TrashIcon} size="sm" /> ) : null}
))}
)}
); }; export default MCPServers;