modelcontextprotocol / modelcontextprotocol/typescript-sdk
disconnect method for MCP client
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the MCP SDK Client class and its existing connect() method, then trace how the underlying transport and pending requests are managed. Define done as an awaitable disconnect() that closes the transport, cleans up pending requests, marks the client disconnected, and permits reconnection; add coverage for these lifecycle cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100