smoke-mcp.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 serverPath = path.resolve(__dirname, '..', 'mcp', 'src', 'server.js');
  7. const client = new Client({
  8. name: 'tihao-smoke-client',
  9. version: '0.1.0'
  10. });
  11. const transport = new StdioClientTransport({
  12. command: process.execPath,
  13. args: [serverPath]
  14. });
  15. await client.connect(transport);
  16. try {
  17. const tools = await client.listTools();
  18. const names = tools.tools.map(tool => tool.name).sort();
  19. for (const required of ['fmode_image_analysis', 'tihao_brief_sourcing_run', 'tihao_preference_update', 'tihao_token_check']) {
  20. if (!names.includes(required)) throw new Error(`Missing MCP tool: ${required}`);
  21. }
  22. const tokenCheck = await client.callTool({
  23. name: 'tihao_token_check',
  24. arguments: {}
  25. });
  26. if (!tokenCheck.structuredContent || !['ok', 'needs_token'].includes(tokenCheck.structuredContent.status)) {
  27. throw new Error('token check returned unexpected structured content');
  28. }
  29. const imageNoToken = await client.callTool({
  30. name: 'fmode_image_analysis',
  31. arguments: {
  32. images: ['data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII='],
  33. prompt: '识别这张测试图片',
  34. allowEnvToken: false
  35. }
  36. });
  37. if (!imageNoToken.structuredContent || imageNoToken.structuredContent.status !== 'needs_token') {
  38. throw new Error('image analysis no-token path returned unexpected structured content');
  39. }
  40. if (Array.isArray(imageNoToken.structuredContent.errors) && imageNoToken.structuredContent.errors.length !== 0) {
  41. throw new Error('image analysis no-token path should keep errors empty');
  42. }
  43. const sample = await client.callTool({
  44. name: 'tihao_brief_sourcing_run',
  45. arguments: {
  46. collectionMode: 'sample',
  47. briefText: '客户名称:花漾肌研\n小红书 2人\n粉丝量范围:2万-30万\n预算范围:¥3000-¥18000\n偏好真实体验和敏感肌修护',
  48. output: path.join(process.env.TEMP || process.cwd(), `tihao-mcp-smoke-${Date.now()}`)
  49. }
  50. });
  51. if (sample.structuredContent?.status !== 'ok') throw new Error('sample MCP tool did not return ok');
  52. if (!sample.structuredContent.assistantMessage.includes('商务可用名单')) {
  53. throw new Error('sample MCP tool did not return business-ready report body');
  54. }
  55. } finally {
  56. await client.close();
  57. }
  58. console.log('tihao mcp protocol smoke ok');
  59. }
  60. main().catch(error => {
  61. console.error(error && error.stack ? error.stack : String(error));
  62. process.exit(1);
  63. });