Error when using agent.run(stream=True) dealing with MCP client session

Hi, I’m receiving this error when I try to show the response from the agent using:agent.run(message, stream=True)

When I use await agent.aprint_response(message, stream=True) it works perfectly but i don’t want to show in terminal the response, i want to stream it to my web application.

If you guys can help me with a good approach to stream the agent responses to an web application

the error:

part of the code:

async def run_agent(message: str) → None:
“”“Run the filesystem agent with the given message.”“”
server_params = StdioServerParameters(
command=“python”,
args=[
“/home/hz/dev/mcp/server.py”,
],
)

# Create a client session to connect to the MCP server
async with stdio_client(server_params) as (read, write):
    async with ClientSession(read, write) as session:
        agent = await create_r_agent(session)

        # Run the agent
        # await agent.aprint_response(message, stream=True)

        run_response = agent.run(message, stream=True)
        for chunk in run_response:
            print(chunk.content)

obs: is the same template as this example: Model Context Protocol - Agno

Hi @hazzen
Thanks for reaching out and for using Agno! I’ve looped in the right engineers to help with your question. We usually respond within 48 hours, but if this is urgent, just let us know, and we’ll do our best to prioritize it.
Appreciate your patience—we’ll get back to you soon! :smile:

Hey @hazzen I am guessing since it’s async- we need to await for the response:

response = await agent.arun(message)
                return response.content

something like this should work. Please let me know if it does.