smoke-mcp-client.mjs
sha256:bd1eb24434d281fe65142038c1bf217493421f5a86880c22dff7e6037d2d4700
feat(companion): add production macOS distribution path
Human
minor
⚠ breaking
24 days ago
| 1 | #!/usr/bin/env node |
| 2 | import { spawn } from 'node:child_process'; |
| 3 | |
| 4 | const helperIndex = process.argv.indexOf('--helper'); |
| 5 | if (helperIndex < 0 || !process.argv[helperIndex + 1]) throw new Error('missing --helper'); |
| 6 | const child = spawn(process.argv[helperIndex + 1], [], { |
| 7 | stdio: ['pipe', 'pipe', 'inherit'], |
| 8 | env: { PATH: '/usr/bin:/bin:/usr/sbin:/sbin', HOME: process.env.HOME, LANG: 'en_US.UTF-8' }, |
| 9 | }); |
| 10 | let output = ''; |
| 11 | const timeout = setTimeout(() => { |
| 12 | child.kill('SIGTERM'); |
| 13 | throw new Error('MCP provisioning smoke test timed out'); |
| 14 | }, 20_000); |
| 15 | |
| 16 | try { |
| 17 | child.stdout.setEncoding('utf8'); |
| 18 | child.stdout.on('data', (chunk) => { output += chunk; }); |
| 19 | child.stdin.write(`${JSON.stringify({ |
| 20 | jsonrpc: '2.0', |
| 21 | id: 1, |
| 22 | method: 'initialize', |
| 23 | params: { |
| 24 | protocolVersion: '2025-06-18', |
| 25 | capabilities: {}, |
| 26 | clientInfo: { name: 'knowtation-release-smoke', version: '1.0.0' }, |
| 27 | }, |
| 28 | })}\n`); |
| 29 | await new Promise((resolve, reject) => { |
| 30 | const poll = setInterval(() => { |
| 31 | if (!output.includes('"id":1')) return; |
| 32 | clearInterval(poll); |
| 33 | resolve(); |
| 34 | }, 25); |
| 35 | child.once('error', (error) => { clearInterval(poll); reject(error); }); |
| 36 | child.once('exit', (code) => { |
| 37 | clearInterval(poll); |
| 38 | reject(new Error(`MCP helper exited before initialize response: ${code}`)); |
| 39 | }); |
| 40 | }); |
| 41 | const response = output.split('\n').filter(Boolean).map((line) => JSON.parse(line)) |
| 42 | .find((message) => message.id === 1); |
| 43 | if (!response?.result?.protocolVersion) throw new Error('MCP initialize response missing'); |
| 44 | console.log(JSON.stringify({ ok: true, protocolVersion: response.result.protocolVersion })); |
| 45 | } finally { |
| 46 | clearTimeout(timeout); |
| 47 | child.kill('SIGTERM'); |
| 48 | } |
File History
1 commit
sha256:bd1eb24434d281fe65142038c1bf217493421f5a86880c22dff7e6037d2d4700
feat(companion): add production macOS distribution path
Human
minor
⚠
24 days ago