MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / close

Method close

src/client/stdio.ts:204–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202 }
203
204 async close(): Promise<void> {
205 if (this._process) {
206 const processToClose = this._process;
207 this._process = undefined;
208
209 const closePromise = new Promise<void>(resolve => {
210 processToClose.once('close', () => {
211 resolve();
212 });
213 });
214
215 try {
216 processToClose.stdin?.end();
217 } catch {
218 // ignore
219 }
220
221 await Promise.race([closePromise, new Promise(resolve => setTimeout(resolve, 2_000).unref())]);
222
223 if (processToClose.exitCode === null) {
224 try {
225 processToClose.kill('SIGTERM');
226 } catch {
227 // ignore
228 }
229
230 await Promise.race([closePromise, new Promise(resolve => setTimeout(resolve, 2_000).unref())]);
231 }
232
233 if (processToClose.exitCode === null) {
234 try {
235 processToClose.kill('SIGKILL');
236 } catch {
237 // ignore
238 }
239 }
240 }
241
242 this._readBuffer.clear();
243 }
244
245 send(message: JSONRPCMessage): Promise<void> {
246 return new Promise(resolve => {

Callers

nothing calls this directly

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected