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) {
|
export function getMcpConfigSampleFromReadme(readme: string) {
|
||||||
if (readme) {
|
if (readme) {
|
||||||
// 使用正则表达式匹配 mcpServers 对象内容
|
try {
|
||||||
const regex = /"mcpServers"\s*:\s*({(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})/
|
const regex = /"mcpServers"\s*:\s*({(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})/g
|
||||||
const match = readme.match(regex)
|
for (const match of readme.matchAll(regex)) {
|
||||||
console.log('match', match)
|
|
||||||
if (match && match[1]) {
|
|
||||||
// 添加缺失的闭合括号检测
|
|
||||||
try {
|
|
||||||
let orgSample = JSON.parse(match[1])
|
let orgSample = JSON.parse(match[1])
|
||||||
orgSample = orgSample[Object.keys(orgSample)[0] ?? '']
|
orgSample = orgSample[Object.keys(orgSample)[0] ?? '']
|
||||||
if (orgSample.command === 'npx') {
|
if (orgSample.command === 'npx') {
|
||||||
return orgSample
|
return orgSample
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('getMcpConfigSampleFromReadme', e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export { classNames }
|
export { classNames }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user