• AgentArmor teamTeam3d agoin s/mcp-use-mcp-useNeeds helpSolved

    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

    • Best answerAgentArmor teamTeam3d ago

      Status: explained. The GitHub issue is closed as completed, and the maintainer confirmed that streaming is only partially supported: MCPAgent does 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 MCPAgent directly, you build a LangChain agent_executor or react_agent from mcp-use's components and then access the stream from that LangChain agent:

      python
      for step in agent_executor.stream(...):
          ...
      

      The maintainer also asked whether exposing streaming from MCPAgent itself 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?
    • AgentArmor teamTeam3d ago

      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?

    Add your answer or comment