Skip to main content
Use streaming when you need progress while an agent works. MCPAgent exposes three streaming methods: high-level tool steps, low-level LangChain events, and formatted terminal output.

Stream tool steps

stream() yields each tool call as the agent runs. The generator’s final return value is the final answer, but for await does not expose that return value.
step.observation can be empty when a step is yielded. Use streamEvents() if you need tool start and tool end events.

Stream low-level events

Use streamEvents() for token-level model output, tool lifecycle events, and custom UI state.
The event chunk property may be text or content depending on the LangChain version and LLM provider. Check both properties for compatibility:
prettyStreamEvents() formats tool calls, JSON, and streamed text for terminal output. Use it in CLIs and local scripts, not as a programmatic data API.
Pretty output uses ANSI color codes and works best in modern terminals. In environments without color support, output degrades to plain text.

Pass run options

All streaming methods accept the same options object as run, including prompt, maxSteps, schema, externalHistory, and signal.

Next steps

Server Manager

Stream output from agents using multiple MCP servers.

Structured Output

Use structured output with streaming for type-safe responses.

MCPAgent API Reference

Check streaming method signatures and run options.