smoke-mcp.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env node
  2. const path = require('path');
  3. const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
  4. const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
  5. async function main() {
  6. const cwd = path.resolve(__dirname, '..');
  7. const client = new Client({
  8. name: 'voc-intelligence-smoke',
  9. version: '0.1.2'
  10. });
  11. const transport = new StdioClientTransport({
  12. command: process.execPath,
  13. args: ['mcp/src/server.js'],
  14. cwd,
  15. stderr: 'pipe'
  16. });
  17. const stderr = transport.stderr;
  18. if (stderr) {
  19. stderr.on('data', chunk => {
  20. process.stderr.write(chunk);
  21. });
  22. }
  23. await client.connect(transport);
  24. try {
  25. const tools = await client.listTools();
  26. const toolNames = tools.tools.map(tool => tool.name);
  27. if (!toolNames.includes('voc_xiaohongshu_trend_run')) {
  28. throw new Error(`Expected tool voc_xiaohongshu_trend_run, got: ${toolNames.join(', ')}`);
  29. }
  30. if (!toolNames.includes('voc_xiaohongshu_preference_update')) {
  31. throw new Error(`Expected tool voc_xiaohongshu_preference_update, got: ${toolNames.join(', ')}`);
  32. }
  33. const preferenceResult = await client.callTool({
  34. name: 'voc_xiaohongshu_preference_update',
  35. arguments: {
  36. message: '保留奶油风和全屋定制翻车方向,不要纯风格美图,下一版更偏门店转化话术',
  37. memory: '../outputs/claude-code-xhs-mcp-smoke/xiaohongshu-trend-memory.json'
  38. }
  39. });
  40. const preferenceStructured = preferenceResult.structuredContent || {};
  41. if (preferenceStructured.status !== 'ok') {
  42. throw new Error(`Expected ok preference result, got: ${JSON.stringify(preferenceStructured)}`);
  43. }
  44. const result = await client.callTool({
  45. name: 'voc_xiaohongshu_trend_run',
  46. arguments: {
  47. collectionMode: 'sample',
  48. profile: 'memory-templates/xiaohongshu-trend-profile.json',
  49. memory: '../outputs/claude-code-xhs-mcp-smoke/xiaohongshu-trend-memory.json',
  50. output: '../outputs/claude-code-xhs-mcp-smoke'
  51. }
  52. });
  53. const structured = result.structuredContent || {};
  54. if (structured.status !== 'ok') {
  55. throw new Error(`Expected ok result, got: ${JSON.stringify(structured)}`);
  56. }
  57. console.log(JSON.stringify({
  58. status: 'ok',
  59. tools: toolNames,
  60. assistantMessagePreview: String(structured.assistantMessage || '').slice(0, 120),
  61. preferenceMemoryApplied: Boolean(structured.summary && structured.summary.preferenceMemoryApplied),
  62. files: structured.files || []
  63. }, null, 2));
  64. } finally {
  65. await client.close();
  66. }
  67. }
  68. main().catch(error => {
  69. console.error(error);
  70. process.exit(1);
  71. });