-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Feature Request: Add disconnect() method to MCP SDK Client
Summary
Add a disconnect()
method to the MCP SDK Client class to enable proper connection cleanup and resource management.
Problem
Currently, the MCP SDK Client only has a connect()
method but lacks a corresponding disconnect()
method. This creates several issues:
- Resource Leaks: Connections remain open until process termination
- Poor Resource Management: No way to explicitly close connections
- Connection Pooling Issues: Difficult to implement proper connection lifecycle management
- Memory Leaks: Long-running applications accumulate open connections
Current Workaround
Developers currently have to rely on process termination for connection cleanup:
// Current approach - no explicit disconnect
const client = new Client({ name: "my-client", version: "1.0.0" });
await client.connect(transport);
// Connection remains open until process ends
Proposed Solution
Add a disconnect()
method to the Client class:
interface Client {
// ... existing methods
disconnect(): Promise<void>;
}
Implementation Details
- Close the underlying transport connection
- Clean up any pending requests
- Release associated resources
- Mark the client as disconnected
- Allow reconnection after disconnect
Benefits
- Explicit Resource Management: Developers can control connection lifecycle
- Better Connection Pooling: Enable proper connection reuse and cleanup
- Memory Efficiency: Prevent connection accumulation in long-running apps
- Testing: Easier to test connection scenarios
- Graceful Shutdown: Proper cleanup during application shutdown
Use Cases
- Connection pooling implementations
- Long-running applications
- Testing frameworks
- Graceful application shutdown
- Resource management in multi-tenant environments
Priority
Medium - This would improve the developer experience and enable better resource management patterns.
shellRaining
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request