MCPAgent provides two streaming APIs. Use stream() for tool-step progress and a final string. Use streamEvents() for provider-neutral token, tool, usage, error, and completion events.
Stream tool steps
Read the generator directly when you need both yielded steps and its final return value.stream() can yield an initial step with an empty observation, followed by another step containing the tool result. A for await loop receives the steps but does not expose the generator’s final return value.
Stream provider-neutral events
streamEvents() uses the same LlmStreamEvent variants for every supported provider.
text-delta values when your UI needs the complete final answer. streamEvents() itself returns no result and does not write the streamed turn to conversation memory.
Handle every event variant
Tool execution failures are emitted as
tool-result with isError: true. Other streaming failures can appear as error. Decide whether your UI should show a partial answer, retry, or fail the request.
Cancel a stream
Pass anAbortSignal through the run options: