diff --git a/src/renderer/src/utils/index.ts b/src/renderer/src/utils/index.ts index 79805aa2..ec4f38b2 100644 --- a/src/renderer/src/utils/index.ts +++ b/src/renderer/src/utils/index.ts @@ -508,23 +508,20 @@ export function hasObjectKey(obj: any, key: string) { */ export function getMcpConfigSampleFromReadme(readme: string) { if (readme) { - // 使用正则表达式匹配 mcpServers 对象内容 - const regex = /"mcpServers"\s*:\s*({(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})/ - const match = readme.match(regex) - console.log('match', match) - if (match && match[1]) { - // 添加缺失的闭合括号检测 - try { + try { + const regex = /"mcpServers"\s*:\s*({(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})/g + for (const match of readme.matchAll(regex)) { let orgSample = JSON.parse(match[1]) orgSample = orgSample[Object.keys(orgSample)[0] ?? ''] if (orgSample.command === 'npx') { return orgSample } - } catch (e) { - console.log(e) } + } catch (e) { + console.log('getMcpConfigSampleFromReadme', e) } } + return null } export { classNames }