Skip to content

🐛 FastAgent Chain Times Out in MCP Server Mode but Works in Interactive Mode #171

@pablotoledo

Description

@pablotoledo

🐛 Bug Description

When running a FastAgent chain with multiple agents in MCP Server mode, requests time out with error -32001. However, the same code works perfectly in interactive mode.

🔍 Expected Behavior

The multi-agent chain should process requests and return results successfully when running in MCP Server mode, just as it does in interactive mode.

🚫 Actual Behavior

In MCP Server mode, the chain starts processing (fetches URLs successfully) but then fails with:

  • Client error @modelcontextprotocol/inspector: MCP error -32001: Request timed out
  • Server error: RuntimeError: Unexpected ASGI message 'http.response.start' sent, after response already completed

🧪 Reproduction Steps

  1. Create a FastAgent with multiple agents in a chain (code below)
  2. Run in server mode with: poetry run python testing_fastagent/multiagent.py --server --transport sse --port 8081 --http-timeout 60
  3. Connect to the server via MCP/inspector
  4. Send a request that requires both agents to process
  5. Observe the timeout error

📋 Code Sample

import asyncio  
from mcp_agent.core.fastagent import FastAgent  
import argparse  
  
fast = FastAgent("Collaborative Agents Example")  
  
# Agent to search for information on the web  
@fast.agent(  
    "web_agent",  
    instruction="You are an assistant that searches for information on the web and processes it. Obtain the content from the provided URLs and create a comparative summary.",  
    servers=["fetch"]  
)  
  
# Agent to save files locally  
@fast.agent(  
    "file_agent",  
    instruction="You are an assistant that saves information to local files in /home/basf/agentes/alpha_repos/testing_fastagent.",  
    servers=["filesystem"]  
)  
  
# Sequential workflow that runs the agents in order  
@fast.chain(  
    name="sequential_search",  
    sequence=["web_agent", "file_agent"],  
    instruction="First obtain information from the URLs and then save it to a local file."  
)  
  
async def main():  
    async with fast.run() as agent:
        # Interactive chat session
        await agent.interactive()
  
asyncio.run(main())

Input message

Obtain the following sources and create a comparative summary of them:  
1. https://raw.githubusercontent.com/pablotoledo/Readium/refs/heads/main/README.md
2. https://raw.githubusercontent.com/pablotoledo/Readium-MCP/refs/heads/main/README.md
Save this summary in a file called "summary.txt" in the directory you can see

💻 Environment Information

  • FastAgent version: v0.2.25
  • Python version: 3.10
  • OS: macOS
  • Transport: SSE
  • Additional flags: --http-timeout 60

poetry run python testing_fastagent/agent.py --server --transport sse --port 8081 --http-timeout 60

🔎 Debugging Information

Server logs show the chain starts running successfully:

  • URLs are fetched correctly by the web_agent
  • The web_agent processes the results
  • Then an ASGI error occurs: RuntimeError: Unexpected ASGI message 'http.response.start' sent, after response already completed

📝 Additional Notes

  1. The issue only occurs when running in MCP Server mode
  2. Interactive mode works perfectly with the exact same code
  3. Increasing the HTTP timeout doesn't resolve the issue
  4. The error seems to occur during the transition between agents in the chain

📎 Attachments

Server logs showing the error trace (attached separately)

logs.txt

Metadata

Metadata

Assignees

Labels

defectSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions