How to stream output from mcp-use MCPAgent like LangChain's agent_executor?
I'm using the mcp-use library and its MCPAgent class. I want to stream the agent's output step by step the way LangChain does with
for step in agent_executor.stream(...), but MCPAgent doesn't seem to expose that. Is streaming supported, and if not, what's the recommended workaround? The GitHub issue on this is closed, so I'd like to know the current status before I restructure my code.Originally asked on GitHub: https://github.com/mcp-use/mcp-use/issues/65
2 answers
Status: explained. The GitHub issue is closed as completed, and the maintainer confirmed that streaming is only partially supported:
MCPAgentdoes not expose streaming output directly. No code change or new API is described in the thread.The workaround suggested by the maintainer is to follow the "Build a custom agent" example in the mcp-use README (https://github.com/mcp-use/mcp-use#build-a-custom-agent (opens external site)). Instead of using
MCPAgentdirectly, you build a LangChainagent_executororreact_agentfrom mcp-use's components and then access the stream from that LangChain agent:pythonfor step in agent_executor.stream(...): ...The maintainer also asked whether exposing streaming from
MCPAgentitself would be useful, and two users replied that it would be very useful, so a native streaming API may come later. Until then, the custom-agent example is the path to streaming. The thread does not include a concrete code sample or version details, so start from the README example and adapt it to your setup.Did this work for you?What @pietrozullo tried on GitHub (Outcome unclear)
Maintainer's suggestion: use the "Build a custom agent" example in the mcp-use README to create a LangChain agent_executor or react_agent, then access the stream from that LangChain agent. No one in the thread reported actually testing this, so the outcome is unclear.
Source: https://github.com/mcp-use/mcp-use/issues/65#issuecomment-2835724679 (opens external site)
Did this work for you?
Related questions
- MCPAgent.run() server_name is obsolete: how do I limit a run to specific servers?
- Does mcp-use support the MCP Streamable HTTP transport?
- Can I use mcp-use with Python 3.10?
- mcp-use: tool call with invalid action input fails the whole run and never retries
- How to set the startup timeout for a local MCP server connection in mcp-use?