fix/mcp-json-validation

This commit is contained in:
Faisal Amir 2025-09-16 17:20:14 +07:00
parent fd052149fe
commit bb39cb1e99
3 changed files with 25 additions and 2 deletions

View File

@ -285,9 +285,20 @@ export default function AddEditMCPServer({
setError(t('mcp-servers:editJson.errorFormat'))
return
}
// For each server in the JSON, call onSave
// Check if this looks like a server config object instead of the expected format
if (parsedData.command || parsedData.url) {
setError(t('mcp-servers:editJson.errorMissingServerNameKey'))
return
}
// For each server in the JSON, validate serverName and call onSave
Object.entries(parsedData).forEach(([serverName, config]) => {
onSave(serverName.trim(), config as MCPServerConfig)
const trimmedServerName = serverName.trim()
if (!trimmedServerName) {
setError(t('mcp-servers:editJson.errorServerName'))
return
}
onSave(trimmedServerName, config as MCPServerConfig)
})
onOpenChange(false)
resetForm()

View File

@ -26,6 +26,12 @@
"errorParse": "Failed to parse initial data",
"errorPaste": "Invalid JSON format in pasted content",
"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",
"errorServerConfig": "Invalid server configuration for '{{serverName}}'",
"errorMissingCommand": "Missing required 'command' field for server '{{serverName}}'",
"errorMissingUrl": "Missing required 'url' field for server '{{serverName}}'",
"errorInvalidType": "Invalid transport type for server '{{serverName}}'. Must be 'stdio', 'http', or 'sse'",
"save": "Save"
},
"checkParams": "Please check the parameters according to the tutorial.",

View File

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