inspect-review-access.cjs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Read-only inspection through the already installed VOC MCP. No collection calls.
  2. const fs = require('node:fs');
  3. const path = require('node:path');
  4. const { createRequire } = require('node:module');
  5. const root = 'C:/Users/JSHY/AppData/Roaming/npm/node_modules/@vocmarket/voc-skill';
  6. const req = createRequire(path.join(root, 'mcp/src/server.js'));
  7. const { Client } = req('@modelcontextprotocol/sdk/client/index.js');
  8. const { StdioClientTransport } = req('@modelcontextprotocol/sdk/client/stdio.js');
  9. const { readCredentialContext } = req('./core/credentials.js');
  10. const credentials = readCredentialContext({});
  11. const out = path.resolve('work/product-reviews');
  12. fs.mkdirSync(out, { recursive: true });
  13. const transport = new StdioClientTransport({command:process.execPath,args:[path.join(root,'mcp/src/server.js')],cwd:root,stderr:'pipe',env:{...process.env,VOC_SKILL_NO_UPDATE_CHECK:'1'}});
  14. transport.stderr?.on('data',()=>{});
  15. const client = new Client({name:'ksf-review-readonly-access',version:'1.0.0'});
  16. function sanitize(value) {
  17. let raw=JSON.stringify(value);
  18. for(const secret of [credentials.newApiToken,credentials.sessionToken])if(secret)raw=raw.split(secret).join('[REDACTED]');
  19. return JSON.parse(raw);
  20. }
  21. (async()=>{
  22. try{
  23. await client.connect(transport,{timeout:15000});
  24. const calls=[
  25. {name:'voc_api_search',arguments:{query:'评论',platform:'jd',limit:20}},
  26. {name:'voc_api_search',arguments:{query:'评论',platform:'taobao',limit:20}},
  27. {name:'voc_billing_query',arguments:{operations:[{model:'voc-e-commerce',path:'jd/get-item-comments/v1',count:1},{model:'voc-e-commerce',path:'taobao/get-item-comment/v3',count:1}],createPaymentQr:false}},
  28. {name:'voc_usage_report',arguments:{from:'2026-11-06T00:00:00+08:00',to:'2026-11-07T00:00:00+08:00',groupBy:['usageTraceId','module'],limit:1000,pageSize:200,refresh:true}},
  29. ];
  30. for(let i=0;i<calls.length;i++){
  31. const result=sanitize(await client.callTool(calls[i],undefined,{timeout:30000}));
  32. fs.writeFileSync(path.join(out,'access-'+i+'.json'),JSON.stringify({request:calls[i],response:result},null,2));
  33. console.log(JSON.stringify({tool:calls[i].name,isError:result.isError,status:result.structuredContent?.status,summary:result.structuredContent?.summary,errors:result.structuredContent?.errors}));
  34. }
  35. }finally{await client.close();await transport.close();}
  36. })().catch(e=>{console.log(JSON.stringify({ok:false,error:e.name}));process.exitCode=1;});