MCPcopy Create free account
hub / github.com/ShipSecAI/studio / handleSave

Function handleSave

frontend/src/pages/McpLibraryPage.tsx:773–874  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

771 };
772
773 const handleSave = async () => {
774 setIsSaving(true);
775 try {
776 // Build headers from headerEntries - include entries with value OR secretId
777 const headersPayload = headerEntries
778 .filter((e) => e.key.trim() && (e.value.trim() || e.secretId))
779 .reduce(
780 (acc, entry) => {
781 const key = entry.key.trim();
782 // Use secret reference format if secretId is set, otherwise use the value
783 const value = entry.secretId ? `{{secret:${entry.secretId}}}` : entry.value.trim();
784 acc[key] = value;
785 return acc;
786 },
787 {} as Record<string, string>,
788 );
789
790 const payload: CreateMcpServer = {
791 name: formData.name.trim(),
792 description: formData.description.trim() || undefined,
793 transportType: formData.transportType,
794 endpoint: formData.transportType === 'http' ? formData.endpoint.trim() : undefined,
795 command: formData.transportType === 'stdio' ? formData.command.trim() : undefined,
796 args:
797 formData.transportType === 'stdio' && formData.args.trim()
798 ? formData.args
799 .split('\n')
800 .map((a) => a.trim())
801 .filter(Boolean)
802 : undefined,
803 headers: Object.keys(headersPayload).length > 0 ? headersPayload : undefined,
804 enabled: true, // Always enabled on create, can toggle from list
805 };
806
807 if (editingServer) {
808 // Mark as checking BEFORE the update to prevent "Unknown" flash
809 setCheckingServers((prev) => new Set([...prev, editingServer]));
810 await updateServer(editingServer, payload);
811 // Run health check after update to refresh status and tools
812 testConnection(editingServer)
813 .then(async () => {
814 // Fetch all tools after health check to update tool counts
815 await fetchAllTools();
816 // Refresh health status in store before clearing checking state
817 await fetchServers();
818 })
819 .catch(() => {
820 // Silently ignore health check errors on update
821 })
822 .finally(() => {
823 setCheckingServers((prev) => {
824 const next = new Set(prev);
825 next.delete(editingServer);
826 return next;
827 });
828 });
829 toast({ title: 'Server updated', description: `${payload.name} has been updated.` });
830 } else {

Callers 1

handleKeyDownFunction · 0.50

Calls 2

fetchServersFunction · 0.85
deleteMethod · 0.45

Tested by

no test coverage detected