disconnect
This commit is contained in:
parent
bbc5002a57
commit
1ec10a3cbb
2 changed files with 14 additions and 4 deletions
|
|
@ -207,10 +207,13 @@ describe("MCPConnection", () => {
|
|||
},
|
||||
});
|
||||
|
||||
const abortController = new AbortController();
|
||||
await conn.connectClient(false, abortController.signal);
|
||||
expect(conn.status).toBe("connected");
|
||||
await conn.client.close();
|
||||
try {
|
||||
const abortController = new AbortController();
|
||||
await conn.connectClient(false, abortController.signal);
|
||||
expect(conn.status).toBe("connected");
|
||||
} finally {
|
||||
await conn.disconnect();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ class MCPConnection {
|
|||
this.abortController = new AbortController();
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
this.abortController.abort();
|
||||
await this.client.close();
|
||||
await this.transport.close();
|
||||
}
|
||||
|
||||
private constructTransport(options: MCPOptions): Transport {
|
||||
switch (options.transport.type) {
|
||||
case "stdio":
|
||||
|
|
@ -133,6 +139,7 @@ class MCPConnection {
|
|||
this.transport = this.constructTransport(this.options);
|
||||
try {
|
||||
await this.client.connect(this.transport);
|
||||
await this.client.close();
|
||||
} catch (error) {
|
||||
// Allow the case where for whatever reason is already connected
|
||||
if (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue