feat: mcp configuration extraction logic optimization (#4918)
Co-authored-by: 寇佳龙 <koujialong@bonc.com.cn>
This commit is contained in:
parent
30309c29ff
commit
32c96daf1f
@ -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 {
|
||||
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)
|
||||
}
|
||||
console.log('getMcpConfigSampleFromReadme', e)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export { classNames }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user