fix: validat type mcp json

This commit is contained in:
Faisal Amir 2025-09-16 22:35:51 +07:00
parent 703b44558c
commit a3c2c1aa3b
8 changed files with 24 additions and 4 deletions

View File

@ -291,15 +291,28 @@ export default function AddEditMCPServer({
return
}
// For each server in the JSON, validate serverName and call onSave
Object.entries(parsedData).forEach(([serverName, config]) => {
// For each server in the JSON, validate serverName and config
for (const [serverName, config] of Object.entries(parsedData)) {
const trimmedServerName = serverName.trim()
if (!trimmedServerName) {
setError(t('mcp-servers:editJson.errorServerName'))
return
}
onSave(trimmedServerName, config as MCPServerConfig)
})
// Validate the config object
const serverConfig = config as MCPServerConfig
// Validate type field if present
if (serverConfig.type && !['stdio', 'http', 'sse'].includes(serverConfig.type)) {
setError(t('mcp-servers:editJson.errorInvalidType', {
serverName: trimmedServerName,
type: serverConfig.type
}))
return
}
onSave(trimmedServerName, serverConfig as MCPServerConfig)
}
onOpenChange(false)
resetForm()
setError(null)

View File

@ -28,6 +28,7 @@
"errorFormat": "Ungültiges JSON Format",
"errorServerName": "Servername ist erforderlich und darf nicht leer sein",
"errorMissingServerNameKey": "JSON muss als {\"serverName\": {config}} strukturiert sein - fehlender Servername-Schlüssel",
"errorInvalidType": "Ungültiger Typ '{{type}}' für Server '{{serverName}}'. Typ muss 'stdio', 'http' oder 'sse' sein",
"save": "Speichern"
},
"checkParams": "Bitte überprüfe die Parameter gemäß dem Tutorial.",

View File

@ -28,6 +28,7 @@
"errorFormat": "Invalid JSON format",
"errorServerName": "Server name is required and cannot be empty",
"errorMissingServerNameKey": "JSON must be structured as {\"serverName\": {config}} - missing server name key",
"errorInvalidType": "Invalid type '{{type}}' for server '{{serverName}}'. Type must be 'stdio', 'http', or 'sse'",
"save": "Save"
},
"checkParams": "Please check the parameters according to the tutorial.",

View File

@ -28,6 +28,7 @@
"errorFormat": "Format JSON tidak valid",
"errorServerName": "Nama server wajib diisi dan tidak boleh kosong",
"errorMissingServerNameKey": "JSON harus berstruktur sebagai {\"serverName\": {config}} - kunci nama server hilang",
"errorInvalidType": "Tipe '{{type}}' untuk server '{{serverName}}' tidak valid. Tipe harus 'stdio', 'http', atau 'sse'",
"save": "Simpan"
},
"checkParams": "Silakan periksa parameter sesuai dengan tutorial.",

View File

@ -28,6 +28,7 @@
"errorFormat": "Niepoprawny format JSON",
"errorServerName": "Nazwa serwera jest wymagana i nie może być pusta",
"errorMissingServerNameKey": "JSON musi być w formacie {\"serverName\": {config}} - brakuje klucza nazwy serwera",
"errorInvalidType": "Niepoprawny typ '{{type}}' dla serwera '{{serverName}}'. Typ musi być 'stdio', 'http' lub 'sse'",
"save": "Zapisz"
},
"checkParams": "Proszę sprawdzić parametry we wprowadzeniu.",

View File

@ -28,6 +28,7 @@
"errorFormat": "Định dạng JSON không hợp lệ",
"errorServerName": "Tên máy chủ là bắt buộc và không được để trống",
"errorMissingServerNameKey": "JSON phải có cấu trúc {\"serverName\": {config}} - thiếu khóa tên máy chủ",
"errorInvalidType": "Loại '{{type}}' cho máy chủ '{{serverName}}' không hợp lệ. Loại phải là 'stdio', 'http' hoặc 'sse'",
"save": "Lưu"
},
"checkParams": "Vui lòng kiểm tra các tham số theo hướng dẫn.",

View File

@ -28,6 +28,7 @@
"errorFormat": "JSON 格式无效",
"errorServerName": "服务器名称为必填项,不能为空",
"errorMissingServerNameKey": "JSON 必须按 {\"serverName\": {config}} 格式结构化 - 缺少服务器名称键",
"errorInvalidType": "服务器 '{{serverName}}' 的类型 '{{type}}' 无效。类型必须是 'stdio'、'http' 或 'sse'",
"save": "保存"
},
"checkParams": "请根据教程检查参数。",

View File

@ -28,6 +28,7 @@
"errorFormat": "JSON 格式無效",
"errorServerName": "伺服器名稱為必填項目,不能為空",
"errorMissingServerNameKey": "JSON 必須依照 {\"serverName\": {config}} 結構 - 缺少伺服器名稱鍵值",
"errorInvalidType": "伺服器 '{{serverName}}' 的類型 '{{type}}' 無效。類型必須是 'stdio'、'http' 或 'sse'",
"save": "儲存"
},
"checkParams": "請根據教學檢查參數。",