(method: string, params: Record<string, unknown>)
| 149 | } |
| 150 | |
| 151 | private async request(method: string, params: Record<string, unknown>): Promise<unknown> { |
| 152 | for (let attempt = 0; attempt < 2; attempt++) { |
| 153 | await this.ensureProcessReady(); |
| 154 | if (!this.proc) throw new Error("Process missing"); |
| 155 | try { |
| 156 | return await this.internalRequest(this.proc, method, params); |
| 157 | } catch (err) { |
| 158 | const msg = String(err); |
| 159 | const isChannelError = msg.includes("Channel has been closed") || |
| 160 | msg.includes("stdin is not writable") || |
| 161 | msg.includes("process exited"); |
| 162 | if (isChannelError && attempt === 0) { |
| 163 | this.output.appendLine(`MCP channel error, restarting (${msg})`); |
| 164 | this.proc?.kill(); |
| 165 | this.proc = undefined; |
| 166 | await this.ensureStarted(); |
| 167 | continue; |
| 168 | } |
| 169 | throw err; |
| 170 | } |
| 171 | } |
| 172 | throw new Error("MCP request failed after retry"); |
| 173 | } |
| 174 | |
| 175 | private notify(method: string, params: Record<string, unknown>): void { |
| 176 | if (!this.proc) return; |
no test coverage detected