import { useState, useEffect } from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { MCPServerConfig } from '@/hooks/useMCPServers' import CodeEditor from '@uiw/react-textarea-code-editor' import '@uiw/react-textarea-code-editor/dist.css' interface EditJsonMCPserverProps { open: boolean onOpenChange: (open: boolean) => void serverName: string | null // null means editing all servers initialData: MCPServerConfig | Record onSave: (data: MCPServerConfig | Record) => void } export default function EditJsonMCPserver({ open, onOpenChange, serverName, initialData, onSave, }: EditJsonMCPserverProps) { const [jsonContent, setJsonContent] = useState('') const [error, setError] = useState(null) // Initialize the editor with the provided data useEffect(() => { if (open && initialData) { try { setJsonContent(JSON.stringify(initialData, null, 2)) setError(null) } catch { setError('Failed to parse initial data') } } }, [open, initialData]) const handleSave = () => { try { const parsedData = JSON.parse(jsonContent) onSave(parsedData) onOpenChange(false) setError(null) } catch { setError('Invalid JSON format') } } return ( {serverName ? `Edit JSON for MCP Server: ${serverName}` : 'Edit All MCP Servers JSON'}
setJsonContent(e.target.value)} style={{ fontFamily: 'ui-monospace', backgroundColor: 'transparent', }} className="w-full !text-sm " />
{error &&
{error}
}
) }