/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/agents/dialogs/CustomMCPDialog.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 { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { X, Plus } from "lucide-react"; import { useState, useEffect } from "react"; interface CustomMCPHeader { id: string; key: string; value: string; } interface CustomMCPServer { url: string; headers: Record; } interface CustomMCPDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSave: (customMCP: CustomMCPServer) => void; initialCustomMCP?: CustomMCPServer | null; clientId: string; } export function CustomMCPDialog({ open, onOpenChange, onSave, initialCustomMCP = null, clientId, }: CustomMCPDialogProps) { const [customMCP, setCustomMCP] = useState>({ url: "", headers: {}, }); const [headersList, setHeadersList] = useState([]); useEffect(() => { if (open) { if (initialCustomMCP) { setCustomMCP(initialCustomMCP); const headersList = Object.entries(initialCustomMCP.headers || {}).map( ([key, value], index) => ({ id: `header-${index}`, key, value, }) ); setHeadersList(headersList); } else { setCustomMCP({ url: "", headers: {} }); setHeadersList([]); } } }, [open, initialCustomMCP]); const handleAddHeader = () => { setHeadersList([ ...headersList, { id: `header-${Date.now()}`, key: "", value: "" }, ]); }; const handleRemoveHeader = (id: string) => { setHeadersList(headersList.filter((header) => header.id !== id)); }; const handleHeaderChange = ( id: string, field: "key" | "value", value: string ) => { setHeadersList( headersList.map((header) => header.id === id ? { ...header, [field]: value } : header ) ); }; const handleSave = () => { if (!customMCP.url) return; const headersObject: Record = {}; headersList.forEach((header) => { if (header.key.trim()) { headersObject[header.key] = header.value; } }); onSave({ url: customMCP.url, headers: headersObject, }); onOpenChange(false); }; return ( Configure Custom MCP Configure the URL and HTTP headers for the custom MCP.
setCustomMCP({ ...customMCP, url: e.target.value, }) } className="bg-[#222] border-[#444] text-white" placeholder="https://meu-servidor-mcp.com/api" />

HTTP Headers

{headersList.map((header) => (
handleHeaderChange(header.id, "key", e.target.value) } className="col-span-2 bg-[#333] border-[#444] text-white" placeholder="Header Name" /> handleHeaderChange(header.id, "value", e.target.value) } className="col-span-2 bg-[#333] border-[#444] text-white" placeholder="Header Value" />
))}
); }