Streaming Output
To enable streaming for a tool, add thestreamingHint annotation and use the streamContent method:
Benefits of Streaming
Streaming provides several advantages for long-running operations:Responsive UIs
Users see results immediately instead of waiting for completion
Progressive Generation
Perfect for AI text generation, data processing, and file operations
Better UX
Users can start reading or acting on partial results
Error Recovery
Users see what was generated before an error occurred
Content Types
Streaming works with all content types:- Text
- Images
- Mixed Content
Progress Reporting
Tools can report numeric progress usingreportProgress in the context object:
Combining Streaming and Progress
You can use both streaming content and progress reporting together:Real-World Examples
AI Text Generation
File Processing
Data Analysis
Tool Annotations
When using streaming, set appropriate annotations:Best Practices
1
Use streamingHint Annotation
Always set
streamingHint: true when using streamContent to inform clients about streaming support:2
Provide Immediate Feedback
Stream the first chunk quickly to show users the tool is working:
3
Update Progress Regularly
Report progress at meaningful intervals (e.g., every 10%):
4
Handle Errors Gracefully
If streaming fails, users still see what was generated:
5
Return vs Stream Final Content
You can either return final content (appended) or stream everything:
Next Steps
Logging
Learn how to add custom logging to your tools
Authentication
Secure your streaming tools with authentication