🔄 fix: Improve MCP Connection Cleanup (#7400)

* chore: linting for mcp related modules

* fix: update `isConnected` method to return a Promise and handle connection state asynchronously to properly handle/cleanup disconnected user connections
This commit is contained in:
Danny Avila 2025-05-15 12:17:17 -04:00 committed by GitHub
parent 535e7798b3
commit fe311df969
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 12 deletions

View file

@ -567,8 +567,14 @@ export class MCPConnection extends EventEmitter {
return this.connectionState;
}
public isConnected(): boolean {
return this.connectionState === 'connected';
public async isConnected(): Promise<boolean> {
try {
await this.client.ping();
return this.connectionState === 'connected';
} catch (error) {
this.logger?.error(`${this.getLogPrefix()} Ping failed:`, error);
return false;
}
}
public getLastError(): Error | null {