Feature - Enable Streaming Capabilities For Tool Calls That Send Real-Time Notificaitons #4972
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MCP Streaming Support
Adds real-time streaming capabilities to MCP (Model Context Protocol) tool integrations with enhanced connection management and SSE integration.
Changes
Server Capabilities Schema
Server advertises streaming support via capabilities response:
// Server capabilities detection
const capabilities = client.getServerCapabilities()
const hasStreaming =
capabilities?.notifications?.streaming === true ||
capabilities?.experimental?.notifications?.streaming === true
Expected server capabilities format:
{
"capabilities": {
"notifications": {
"streaming": true
}
}
}
Alternative experimental format:
{
"capabilities": {
"experimental": {
"notifications": {
"streaming": true
}
}
}
}
Tool Capabilities Schema
MCP tools declare streaming support via annotations:
// Tool definition with streaming annotation
{
"name": "tool_name",
"description": "Tool description",
"annotations": {
"streaming_enabled": true,
"notification_types": ["task_completion", "progress", "logging"]
},
"inputSchema": {
"type": "object",
"properties": { /* tool parameters */ }
}
}
Tool streaming annotations:
SSE Streaming Events
Tools with streaming support emit events via IServerSideEventStreamer:
interface IServerSideEventStreamer {
// Core streaming methods
streamTokenEvent(chatId: string, data: string): void
streamToolEvent(chatId: string, data: any): void
streamCustomEvent(chatId: string, eventType: string, data: any): void
}
Notification Handling Schema
MCP notifications follow the LoggingMessageNotificationSchema:
// Notification structure
{
"method": "logging/message",
"params": {
"data": "notification message",
"logger": "task_completion" // Used for completion detection
}
}
Configuration
const MCP_STREAMING_CONFIG = {
DEFAULT_COMPLETION_TIMEOUT: 600000, // 10 minutes fallback
NOTIFICATION_DELAY: 1000, // 1 second cleanup delay
SUPPORTED_NOTIFICATION_TYPES: ['logging/message', 'progress'],
STREAMING_MARKER: '[MCP Streaming]' // UI indicator
}
Technical Implementation
Enables real-time user feedback during MCP tool execution while maintaining backward compatibility with existing non-streaming MCP servers.