modelcontextprotocol / modelcontextprotocol/typescript-sdk
Bug Report-2: Missing Periodic Ping Implementation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
Summary
The MCP TypeScript SDK implements a basic ping method but lacks the periodic ping functionality required by the MCP specification. The current implementation only provides manual ping capability, missing the automatic periodic ping feature specified in the protocol.
Problem Description
The current ping implementation only provides a manual ping method but does not implement the periodic ping functionality specified in the MCP protocol.
Current Implementation
Location: src/client/index.ts:332-334
async ping(options?: RequestOptions) {
return this.request({ method: "ping" }, EmptyResultSchema, options);
}
Protocol Requirements
According to the MCP specification:
- "Implementations SHOULD periodically issue pings to detect connection health"
- "The frequency of pings SHOULD be configurable"
Missing Features
- Periodic Ping: No automatic periodic ping functionality
- Configurable Frequency: No way to configure ping interval
Impact
- Connection health cannot be automatically monitored
- Undetected connection failures may occur
- Non-compliance with MCP protocol specification
Proposed Solution
Implement periodic ping functionality with configurable frequency:
export interface PingConfig {
interval: number; // ping interval in milliseconds
enabled: boolean; // whether to enable periodic pings
}
export interface ClientOptions extends ProtocolOptions {
capabilities?: ClientCapabilities;
ping?: PingConfig;
}
// Enhanced Client class
export class Client {
private _pingInterval?: NodeJS.Timeout;
private _pingConfig: PingConfig;
constructor(
private _clientInfo: Implementation,
options?: ClientOptions,
) {
super(options);
this._pingConfig = {
interval: options?.ping?.interval ?? 30000, // 30 seconds default
enabled: options?.ping?.enabled ?? true, // enabled by default
};
}
// Start periodic ping when connected
private startPeriodicPing(): void {
if (!this._pingConfig.enabled || this._pingInterval) {
return;
}
this._pingInterval = setInterval(async () => {
try {
await this.ping();
} catch (error) {
// Handle ping failure
console.warn(`Periodic ping failed: ${error.message}`);
}
}, this._pingConfig.interval);
}
// Stop periodic ping when disconnected
private stopPeriodicPing(): void {
if (this._pingInterval) {
clearInterval(this._pingInterval);
this._pingInterval = undefined;
}
}
// Override connect to start ping
override async connect(transport: Transport, options?: RequestOptions): Promise<void> {
await super.connect(transport, options);
this.startPeriodicPing();
}
// Override close to stop ping
override async close(): Promise<void> {
this.stopPeriodicPing();
await super.close();
}
}
Requested Action
Implement the missing periodic ping functionality as specified in the MCP protocol, including:
- Automatic periodic ping scheduling
- Configurable ping frequency
- Proper lifecycle management (start with connection, stop with disconnection)
Labels
enhancementprotocol-complianceping
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 in src/client/index.ts:332-334 and inspect the Client connection lifecycle around connect and close. Confirm how periodic ping configuration, scheduling, failure handling, and cleanup should fit the existing client API; done means configurable automatic pings operate while connected and stop on disconnection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100