Merge pull request #6478 from menloresearch/fix/mcp-json-validation

fix: mcp json  validation structure and serverName
This commit is contained in:
Faisal Amir 2025-09-17 09:01:01 +07:00 committed by GitHub
commit 7fc3afd0ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 49 additions and 4 deletions

View File

@ -285,10 +285,34 @@ export default function AddEditMCPServer({
setError(t('mcp-servers:editJson.errorFormat')) setError(t('mcp-servers:editJson.errorFormat'))
return return
} }
// For each server in the JSON, call onSave // Check if this looks like a server config object instead of the expected format
Object.entries(parsedData).forEach(([serverName, config]) => { if (parsedData.command || parsedData.url) {
onSave(serverName.trim(), config as MCPServerConfig) setError(t('mcp-servers:editJson.errorMissingServerNameKey'))
}) return
}
// 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
}
// 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) onOpenChange(false)
resetForm() resetForm()
setError(null) setError(null)

View File

@ -26,6 +26,9 @@
"errorParse": "Fehler beim Parsen der initialen Daten", "errorParse": "Fehler beim Parsen der initialen Daten",
"errorPaste": "Ungültiges JSON Format in dem eingefügten Inhalt", "errorPaste": "Ungültiges JSON Format in dem eingefügten Inhalt",
"errorFormat": "Ungültiges JSON Format", "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" "save": "Speichern"
}, },
"checkParams": "Bitte überprüfe die Parameter gemäß dem Tutorial.", "checkParams": "Bitte überprüfe die Parameter gemäß dem Tutorial.",

View File

@ -26,6 +26,9 @@
"errorParse": "Failed to parse initial data", "errorParse": "Failed to parse initial data",
"errorPaste": "Invalid JSON format in pasted content", "errorPaste": "Invalid JSON format in pasted content",
"errorFormat": "Invalid JSON format", "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" "save": "Save"
}, },
"checkParams": "Please check the parameters according to the tutorial.", "checkParams": "Please check the parameters according to the tutorial.",

View File

@ -26,6 +26,9 @@
"errorParse": "Gagal mengurai data awal", "errorParse": "Gagal mengurai data awal",
"errorPaste": "Format JSON tidak valid pada konten yang ditempel", "errorPaste": "Format JSON tidak valid pada konten yang ditempel",
"errorFormat": "Format JSON tidak valid", "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" "save": "Simpan"
}, },
"checkParams": "Silakan periksa parameter sesuai dengan tutorial.", "checkParams": "Silakan periksa parameter sesuai dengan tutorial.",

View File

@ -26,6 +26,9 @@
"errorParse": "Błąd parsowania wstępnych danych", "errorParse": "Błąd parsowania wstępnych danych",
"errorPaste": "Wprowadzono JSON o niepoprawnym formacie", "errorPaste": "Wprowadzono JSON o niepoprawnym formacie",
"errorFormat": "Niepoprawny format JSON", "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" "save": "Zapisz"
}, },
"checkParams": "Proszę sprawdzić parametry we wprowadzeniu.", "checkParams": "Proszę sprawdzić parametry we wprowadzeniu.",

View File

@ -26,6 +26,9 @@
"errorParse": "Không thể phân tích cú pháp dữ liệu ban đầu", "errorParse": "Không thể phân tích cú pháp dữ liệu ban đầu",
"errorPaste": "Định dạng JSON không hợp lệ trong nội dung đã dán", "errorPaste": "Định dạng JSON không hợp lệ trong nội dung đã dán",
"errorFormat": "Định dạng JSON không hợp lệ", "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" "save": "Lưu"
}, },
"checkParams": "Vui lòng kiểm tra các tham số theo hướng dẫn.", "checkParams": "Vui lòng kiểm tra các tham số theo hướng dẫn.",

View File

@ -26,6 +26,9 @@
"errorParse": "解析初始数据失败", "errorParse": "解析初始数据失败",
"errorPaste": "粘贴内容中的 JSON 格式无效", "errorPaste": "粘贴内容中的 JSON 格式无效",
"errorFormat": "JSON 格式无效", "errorFormat": "JSON 格式无效",
"errorServerName": "服务器名称为必填项,不能为空",
"errorMissingServerNameKey": "JSON 必须按 {\"serverName\": {config}} 格式结构化 - 缺少服务器名称键",
"errorInvalidType": "服务器 '{{serverName}}' 的类型 '{{type}}' 无效。类型必须是 'stdio'、'http' 或 'sse'",
"save": "保存" "save": "保存"
}, },
"checkParams": "请根据教程检查参数。", "checkParams": "请根据教程检查参数。",

View File

@ -26,6 +26,9 @@
"errorParse": "解析初始資料失敗", "errorParse": "解析初始資料失敗",
"errorPaste": "貼上內容的 JSON 格式無效", "errorPaste": "貼上內容的 JSON 格式無效",
"errorFormat": "JSON 格式無效", "errorFormat": "JSON 格式無效",
"errorServerName": "伺服器名稱為必填項目,不能為空",
"errorMissingServerNameKey": "JSON 必須依照 {\"serverName\": {config}} 結構 - 缺少伺服器名稱鍵值",
"errorInvalidType": "伺服器 '{{serverName}}' 的類型 '{{type}}' 無效。類型必須是 'stdio'、'http' 或 'sse'",
"save": "儲存" "save": "儲存"
}, },
"checkParams": "請根據教學檢查參數。", "checkParams": "請根據教學檢查參數。",