check-voc.cjs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Local runtime check: list tools and read the bundled API catalog.
  2. * No credential discovery, API calls, browser launch or business writes.
  3. */
  4. const path = require('node:path');
  5. const fs = require('node:fs');
  6. const {createRequire} = require('node:module');
  7. const vocDir = path.resolve(process.argv[2] || '.');
  8. const fromVoc = createRequire(path.join(vocDir, 'package.json'));
  9. const timeout = setTimeout(() => { console.error('VOC_CHECK_TIMEOUT'); process.exit(1); }, 30000);
  10. process.env.VOC_SKILL_NO_UPDATE_CHECK = '1';
  11. async function main() {
  12. const {Client} = fromVoc('@modelcontextprotocol/sdk/client/index.js');
  13. const {InMemoryTransport} = fromVoc('@modelcontextprotocol/sdk/inMemory.js');
  14. const {createServer} = fromVoc('./mcp/src/server.js');
  15. const {searchVocApis, getVocApiDoc} = fromVoc('./mcp/src/tools/voc-api-catalog-run.js');
  16. const client = new Client({name: 'ksf-local-onboarding-check', version: '1.0.0'});
  17. const server = createServer();
  18. const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
  19. try {
  20. await server.connect(serverTransport);
  21. await client.connect(clientTransport);
  22. const {tools} = await client.listTools();
  23. const names = tools.map(t => t.name).sort();
  24. for (const required of ['voc_api_search', 'voc_api_doc', 'voc_api_call']) {
  25. if (!names.includes(required)) throw Error('REQUIRED_TOOL_MISSING');
  26. }
  27. const found = await searchVocApis({platform: 'jd', limit: 5});
  28. const endpoints = found.data?.endpoints || [];
  29. if (found.status !== 'ok' || !endpoints.length) throw Error('LOCAL_CATALOG_SEARCH_FAILED');
  30. const doc = await getVocApiDoc({id: endpoints[0].id});
  31. if (doc.status !== 'ok' || !doc.data?.callTemplate) throw Error('LOCAL_CATALOG_DOCUMENT_FAILED');
  32. const manifest = JSON.parse(fs.readFileSync(path.join(vocDir, 'skill-package-manifest.json')));
  33. for (const name of manifest.skills) {
  34. if (!fs.statSync(path.join(vocDir, 'skills', name, 'SKILL.md')).isFile()) throw Error('SUBSKILL_MISSING');
  35. }
  36. console.log(JSON.stringify({ok: true, version: manifest.version, tools: names, subskills: manifest.skills.length,
  37. catalogSearch: {platform: 'jd', matched: endpoints.length}, localParameterDocumentRead: true,
  38. hostRegistrationVerified: false, liveAccessVerified: false, collectionRequests: 0}));
  39. } finally {
  40. await client.close();
  41. await server.close();
  42. clearTimeout(timeout);
  43. }
  44. }
  45. main().catch(() => { clearTimeout(timeout); console.error('VOC_LOCAL_RUNTIME_CHECK_FAILED'); process.exitCode = 1; });