/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/agents/dialogs/MCPDialog.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ "use client"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { MCPServer } from "@/types/mcpServer"; import { Server } from "lucide-react"; import { useState, useEffect } from "react"; interface MCPDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSave: (mcpConfig: { id: string; envs: Record; tools: string[]; }) => void; availableMCPs: MCPServer[]; selectedMCP?: MCPServer | null; initialEnvs?: Record; initialTools?: string[]; clientId: string; } export function MCPDialog({ open, onOpenChange, onSave, availableMCPs, selectedMCP: initialSelectedMCP = null, initialEnvs = {}, initialTools = [], clientId, }: MCPDialogProps) { const [selectedMCP, setSelectedMCP] = useState(null); const [mcpEnvs, setMcpEnvs] = useState>({}); const [selectedMCPTools, setSelectedMCPTools] = useState([]); useEffect(() => { if (open) { if (initialSelectedMCP) { setSelectedMCP(initialSelectedMCP); setMcpEnvs(initialEnvs); setSelectedMCPTools(initialTools); } else { setSelectedMCP(null); setMcpEnvs({}); setSelectedMCPTools([]); } } }, [open, initialSelectedMCP, initialEnvs, initialTools]); const handleSelectMCP = (value: string) => { const mcp = availableMCPs.find((m) => m.id === value); if (mcp) { setSelectedMCP(mcp); const initialEnvs: Record = {}; Object.keys(mcp.environments || {}).forEach((key) => { initialEnvs[key] = ""; }); setMcpEnvs(initialEnvs); setSelectedMCPTools([]); } }; const toggleMCPTool = (tool: string) => { if (selectedMCPTools.includes(tool)) { setSelectedMCPTools(selectedMCPTools.filter((t) => t !== tool)); } else { setSelectedMCPTools([...selectedMCPTools, tool]); } }; const handleSave = () => { if (!selectedMCP) return; onSave({ id: selectedMCP.id, envs: mcpEnvs, tools: selectedMCPTools, }); onOpenChange(false); }; return ( Configure MCP Server Select a MCP server and configure its tools.
{selectedMCP && ( <>

{selectedMCP.name}

{selectedMCP.description?.substring(0, 100)}...

Type: {selectedMCP.type}

Configuration:{" "} {selectedMCP.config_type === "sse" ? "SSE" : "Studio"}

{selectedMCP.environments && Object.keys(selectedMCP.environments).length > 0 && (

Environment Variables

{Object.entries(selectedMCP.environments || {}).map( ([key, value]) => (
setMcpEnvs({ ...mcpEnvs, [key]: e.target.value, }) } className="col-span-2 bg-[#222] border-[#444] text-white" placeholder={value as string} />
) )}
)} {selectedMCP.tools && selectedMCP.tools.length > 0 && (

Available Tools

{selectedMCP.tools.map((tool: any) => (
toggleMCPTool(tool.id)} className="data-[state=checked]:bg-emerald-400 data-[state=checked]:border-emerald-400" />
))}
)} )}
); }