| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /* Local runtime check: list tools and read the bundled API catalog.
- * No credential discovery, API calls, browser launch or business writes.
- */
- const path = require('node:path');
- const fs = require('node:fs');
- const {createRequire} = require('node:module');
- const vocDir = path.resolve(process.argv[2] || '.');
- const fromVoc = createRequire(path.join(vocDir, 'package.json'));
- const timeout = setTimeout(() => { console.error('VOC_CHECK_TIMEOUT'); process.exit(1); }, 30000);
- process.env.VOC_SKILL_NO_UPDATE_CHECK = '1';
- async function main() {
- const {Client} = fromVoc('@modelcontextprotocol/sdk/client/index.js');
- const {InMemoryTransport} = fromVoc('@modelcontextprotocol/sdk/inMemory.js');
- const {createServer} = fromVoc('./mcp/src/server.js');
- const {searchVocApis, getVocApiDoc} = fromVoc('./mcp/src/tools/voc-api-catalog-run.js');
- const client = new Client({name: 'ksf-local-onboarding-check', version: '1.0.0'});
- const server = createServer();
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
- try {
- await server.connect(serverTransport);
- await client.connect(clientTransport);
- const {tools} = await client.listTools();
- const names = tools.map(t => t.name).sort();
- for (const required of ['voc_api_search', 'voc_api_doc', 'voc_api_call']) {
- if (!names.includes(required)) throw Error('REQUIRED_TOOL_MISSING');
- }
- const found = await searchVocApis({platform: 'jd', limit: 5});
- const endpoints = found.data?.endpoints || [];
- if (found.status !== 'ok' || !endpoints.length) throw Error('LOCAL_CATALOG_SEARCH_FAILED');
- const doc = await getVocApiDoc({id: endpoints[0].id});
- if (doc.status !== 'ok' || !doc.data?.callTemplate) throw Error('LOCAL_CATALOG_DOCUMENT_FAILED');
- const manifest = JSON.parse(fs.readFileSync(path.join(vocDir, 'skill-package-manifest.json')));
- for (const name of manifest.skills) {
- if (!fs.statSync(path.join(vocDir, 'skills', name, 'SKILL.md')).isFile()) throw Error('SUBSKILL_MISSING');
- }
- console.log(JSON.stringify({ok: true, version: manifest.version, tools: names, subskills: manifest.skills.length,
- catalogSearch: {platform: 'jd', matched: endpoints.length}, localParameterDocumentRead: true,
- hostRegistrationVerified: false, liveAccessVerified: false, collectionRequests: 0}));
- } finally {
- await client.close();
- await server.close();
- clearTimeout(timeout);
- }
- }
- main().catch(() => { clearTimeout(timeout); console.error('VOC_LOCAL_RUNTIME_CHECK_FAILED'); process.exitCode = 1; });
|