fix(mcp): improve format/submit UX and fix validation errors
Fixes two critical issues with the MCP JSON input:
1. Format button failed with wrapped format like "server": {...}
2. Submit button failed despite input validation passing
Changes:
- Updated formatJSON to use smart parser (supports wrapped format)
- Simplified submit validation logic (removed redundant validateJsonConfig call)
- Improved UX: input preserves original format, cleanup happens on format/submit
* Prevents confusing "instant disappearance" when pasting wrapped JSON
* Auto-fills ID/Name fields while keeping input unchanged
* Format button now strips wrapper key and formats cleanly
* Submit button correctly extracts config regardless of format
Code quality:
- Reduced code by 5 lines (20 changes, 11 insertions, 16 deletions)
- Consistent use of parseSmartMcpJson across all JSON operations
- No type errors introduced
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 格式化 JSON 字符串
|
||||
* @param value - 原始 JSON 字符串
|
||||
* @param value - 原始 JSON 字符串(支持带键名包装的格式)
|
||||
* @returns 格式化后的 JSON 字符串(2 空格缩进)
|
||||
* @throws 如果 JSON 格式无效
|
||||
*/
|
||||
@@ -9,8 +9,9 @@ export function formatJSON(value: string): string {
|
||||
if (!trimmed) {
|
||||
return "";
|
||||
}
|
||||
const parsed = JSON.parse(trimmed);
|
||||
return JSON.stringify(parsed, null, 2);
|
||||
// 使用智能解析器来处理可能的片段格式
|
||||
const result = parseSmartMcpJson(trimmed);
|
||||
return result.formattedConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user