| 433 | |
| 434 | return { |
| 435 | request(method: string, params: unknown): Promise<JsonRpcResponse> { |
| 436 | const id = nextId++; |
| 437 | const payload = `${JSON.stringify({ jsonrpc: '2.0', id, method, params })}\n`; |
| 438 | return new Promise((resolve, reject) => { |
| 439 | const timeout = setTimeout(() => { |
| 440 | pending.delete(id); |
| 441 | reject(new Error(`Timed out waiting for MCP response ${id}. stderr: ${stderr.join('')}`)); |
| 442 | }, 5_000); |
| 443 | pending.set(id, { resolve, reject, timeout }); |
| 444 | child.stdin.write(payload); |
| 445 | }); |
| 446 | }, |
| 447 | }; |
| 448 | } |
| 449 | |