/** * 验证 MCP 配置读写链路:往内核里塞一份配置,看能不能连上。 * 用法: node scripts/mcp-smoke.mjs <输出用的json路径> */ const [, , base = 'http://127.0.0.1:5399', outPath] = process.argv; const cfg = { servers: [ { name: 'filesystem', enabled: true, transport: 'stdio', command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '${DOUBAO_DATA}'], env: {}, }, { name: 'memory', enabled: true, transport: 'stdio', command: 'npx', args: ['-y', '@modelcontextprotocol/server-memory'], env: {}, }, ], }; const started = Date.now(); const res = await fetch(`${base}/api/mcp/config`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: JSON.stringify(cfg, null, 2) }), }); const json = await res.json(); console.log(`耗时 ${Math.round((Date.now() - started) / 1000)}s status=${res.status}`); console.log('ok=', json.ok, 'count=', json.count, 'error=', json.error || '无'); for (const r of json.results || []) console.log(' ', r.ok ? '✓' : '✗', r.name, r.error || ''); for (const s of json.servers || []) { console.log(' ->', s.name, s.connected ? `已连接/${s.tools.length} 工具` : '未连接', s.error || ''); if (s.tools.length) console.log(' 工具:', s.tools.map((t) => t.name).join(', ')); } if (outPath) { const fs = await import('node:fs'); fs.writeFileSync(outPath, await (await fetch(`${base}/api/mcp`)).text(), 'utf8'); }