fix/mcp-json-validation
This commit is contained in:
parent
fd052149fe
commit
bb39cb1e99
@ -285,9 +285,20 @@ 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
|
||||||
|
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]) => {
|
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)
|
onOpenChange(false)
|
||||||
resetForm()
|
resetForm()
|
||||||
|
|||||||
@ -26,6 +26,12 @@
|
|||||||
"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",
|
||||||
|
"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"
|
"save": "Save"
|
||||||
},
|
},
|
||||||
"checkParams": "Please check the parameters according to the tutorial.",
|
"checkParams": "Please check the parameters according to the tutorial.",
|
||||||
|
|||||||
@ -26,6 +26,12 @@
|
|||||||
"errorParse": "解析初始数据失败",
|
"errorParse": "解析初始数据失败",
|
||||||
"errorPaste": "粘贴内容中的 JSON 格式无效",
|
"errorPaste": "粘贴内容中的 JSON 格式无效",
|
||||||
"errorFormat": "JSON 格式无效",
|
"errorFormat": "JSON 格式无效",
|
||||||
|
"errorServerName": "服务器名称为必填项,不能为空",
|
||||||
|
"errorMissingServerNameKey": "JSON 必须按 {\"serverName\": {config}} 格式结构化 - 缺少服务器名称键",
|
||||||
|
"errorServerConfig": "服务器 '{{serverName}}' 的配置无效",
|
||||||
|
"errorMissingCommand": "服务器 '{{serverName}}' 缺少必需的 'command' 字段",
|
||||||
|
"errorMissingUrl": "服务器 '{{serverName}}' 缺少必需的 'url' 字段",
|
||||||
|
"errorInvalidType": "服务器 '{{serverName}}' 的传输类型无效。必须为 'stdio'、'http' 或 'sse'",
|
||||||
"save": "保存"
|
"save": "保存"
|
||||||
},
|
},
|
||||||
"checkParams": "请根据教程检查参数。",
|
"checkParams": "请根据教程检查参数。",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user