import React, { useState } from "react"; import { Plus, Server, Wifi, WifiOff, Trash2, TestTube } from "lucide-react"; import { useMCP } from "../hooks/useMCP"; import type { MCPServerConfig } from "../types/mcp"; interface MCPServerManagerProps { isOpen: boolean; onClose: () => void; } export const MCPServerManager: React.FC = ({ isOpen, onClose, }) => { const { mcpState, addServer, removeServer, connectToServer, disconnectFromServer, testConnection, } = useMCP(); const [showAddForm, setShowAddForm] = useState(false); const [testingConnection, setTestingConnection] = useState( null ); const [newServer, setNewServer] = useState>({ name: "", url: "", enabled: true, transport: "streamable-http", auth: { type: "bearer", }, }); if (!isOpen) return null; const handleAddServer = async () => { if (!newServer.name || !newServer.url) return; const serverConfig: MCPServerConfig = { ...newServer, id: `server_${Date.now()}`, }; try { await addServer(serverConfig); setNewServer({ name: "", url: "", enabled: true, transport: "streamable-http", auth: { type: "bearer", }, }); setShowAddForm(false); } catch (error) { console.error("Failed to add server:", error); } }; const handleTestConnection = async (config: MCPServerConfig) => { setTestingConnection(config.id); try { const success = await testConnection(config); if (success) { alert("Connection test successful!"); } else { alert("Connection test failed. Please check your configuration."); } } catch (error) { alert(`Connection test failed: ${error}`); } finally { setTestingConnection(null); } }; const handleToggleConnection = async ( serverId: string, isConnected: boolean ) => { try { if (isConnected) { await disconnectFromServer(serverId); } else { await connectToServer(serverId); } } catch (error) { console.error("Failed to toggle connection:", error); } }; return (

MCP Server Manager

{/* Add Server Button */}
{/* Add Server Form */} {showAddForm && (

Add New MCP Server

setNewServer({ ...newServer, name: e.target.value }) } className="w-full bg-gray-600 text-white rounded px-3 py-2" placeholder="My MCP Server" />
setNewServer({ ...newServer, url: e.target.value }) } className="w-full bg-gray-600 text-white rounded px-3 py-2" placeholder="http://localhost:3000/mcp" />
{/* Auth-specific fields */} {newServer.auth?.type === "bearer" && (
setNewServer({ ...newServer, auth: { ...newServer.auth!, token: e.target.value }, }) } className="w-full bg-gray-600 text-white rounded px-3 py-2" placeholder="your-bearer-token" />
)} {newServer.auth?.type === "basic" && ( <>
setNewServer({ ...newServer, auth: { ...newServer.auth!, username: e.target.value, }, }) } className="w-full bg-gray-600 text-white rounded px-3 py-2" placeholder="username" />
setNewServer({ ...newServer, auth: { ...newServer.auth!, password: e.target.value, }, }) } className="w-full bg-gray-600 text-white rounded px-3 py-2" placeholder="password" />
)} {newServer.auth?.type === "oauth" && (
setNewServer({ ...newServer, auth: { ...newServer.auth!, token: e.target.value }, }) } className="w-full bg-gray-600 text-white rounded px-3 py-2" placeholder="your-oauth-token" />
)}
setNewServer({ ...newServer, enabled: e.target.checked }) } className="rounded" />
)} {/* Server List */}

Configured Servers

{Object.values(mcpState.servers).length === 0 ? (
No MCP servers configured. Add one to get started!
) : ( Object.values(mcpState.servers).map((config) => (
{config.config.name} {config.config.url}
{/* Test Connection */} {/* Connect/Disconnect */} {/* Remove Server */}
{config.lastError && (
Error: {config.lastError}
)} {config.isConnected && config.tools.length > 0 && (
Available Tools ({config.tools.length})
{config.tools.map((tool) => (
• {tool.name} -{" "} {tool.description || "No description"}
))}
)}
)) )}
{mcpState.error && (
Error: {mcpState.error}
)}
); };