smoke-mcp.mjs 1.6 KB

1234567891011121314151617181920212223242526
  1. import path from 'node:path';
  2. import { Client } from '@modelcontextprotocol/sdk/client/index.js';
  3. import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
  4. import manifest from '../skill-package-manifest.json' with { type: 'json' };
  5. const root = path.resolve(import.meta.dirname, '..');
  6. const transport = new StdioClientTransport({ command: process.execPath, args: [path.join(root, 'mcp', 'src', 'server.mjs')], cwd: root, stderr: 'pipe' });
  7. const client = new Client({ name: 'fmode-image-set-smoke', version: '0.1.0' });
  8. try {
  9. await client.connect(transport);
  10. const listed = await client.listTools();
  11. const names = listed.tools.map(tool => tool.name).sort();
  12. const expected = [...manifest.mcpTools].sort();
  13. if (JSON.stringify(names) !== JSON.stringify(expected)) throw new Error(`Tool mismatch: ${JSON.stringify(names)}`);
  14. for (const tool of listed.tools) {
  15. if (!tool.inputSchema) throw new Error(`Missing input schema: ${tool.name}`);
  16. if (!tool.outputSchema) throw new Error(`Missing output schema: ${tool.name}`);
  17. if (!tool.annotations) throw new Error(`Missing annotations: ${tool.name}`);
  18. }
  19. const response = await client.callTool({ name: 'fmode_image_set_plan', arguments: { request: '规划七张测试套图' } });
  20. const parsed = JSON.parse(response.content[0].text);
  21. if (parsed.status !== 'ok' || parsed.data.plan.items.length !== 7) throw new Error('MCP planning call failed.');
  22. console.log(JSON.stringify({ status: 'ok', tools: names.length, planId: parsed.data.plan.planId }, null, 2));
  23. } finally {
  24. await client.close();
  25. }