You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have you searched for related issues? Others may have faced similar issues. YES
Describe the bug
I use agent with a single MCP server I've created for it and all works great.
but when I restart my MCP server and the agent tries to do something with it, it get 400 error code because the session ID does not exist (which make sense because the MCP server does not hold it anymore) but the agent stop working without any exception that I can handle.
Ideally provide a minimal python script that can be run to reproduce the bug.
importasynciofromcoloramaimportFore, Back, StyleimportosimportshutilimportsubprocessimporttimefromtypingimportAnyfromdotenvimportload_dotenvfromagentsimportAgent, Runner, gen_trace_id, tracefromagents.mcpimportMCPServer, MCPServerSsefromagents.model_settingsimportModelSettingsimportnest_asyncionest_asyncio.apply()
definit_agent(mcp_server: MCPServer) ->Agent:
agent=Agent(
name="Assistant",
instructions="use your provided tools and MCPs to help the user" ,
mcp_servers=[mcp_server],
model="gpt-4.1",
model_settings=ModelSettings(tool_choice="auto"), )
returnagentdefassemble_conversation(result, new_input) ->Agent:
ifresult!=None:
returnresult.to_input_list() + [{'content': new_input,
'role': 'user'}]
else:
returnnew_inputasyncdefrun(mcp_server: MCPServer):
result=Noneagent=init_agent(mcp_server)
whileTrue:
# Get user inputuser_input=input("You: ").strip()
# Check if user wants to exitifuser_input.lower() =="exit":
print("Ending conversation.")
breaktry:
result=Runner.run_sync(agent, assemble_conversation(result, user_input))
print(Fore.GREEN+f"Assistant: {result.final_output}")
exceptExceptionase:
print(Fore.RED+f"Error:: {str(e)}")
finally:
print(Fore.RESET+"-"*60)
asyncdefmain():
load_dotenv()
asyncwithMCPServerSse(
name="SSE Python Server",
params={
"url": "http://localhost:8181/sse",
},
) asserver:
awaitrun(server)
if__name__=="__main__":
print("starting conversation.")
asyncio.run(main())
Expected behavior
The code works fine. But as I've mentioned, the agent fails to recover after the MCP server is restarted (which can happen naturally). and I just get the error:
Uh oh!
There was an error while loading. Please reload this page.
Please read this first
Describe the bug
I use agent with a single MCP server I've created for it and all works great.
but when I restart my MCP server and the agent tries to do something with it, it get 400 error code because the session ID does not exist (which make sense because the MCP server does not hold it anymore) but the agent stop working without any exception that I can handle.
example error:
Error in post_writer: Client error '400 Bad Request' for url 'http://localhost:8181/message?sessionId=72ca14a0-731b-4db1-a21a-b2212e285g94'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
Debug information
v0.0.3
) v0.0.14Repro steps
Ideally provide a minimal python script that can be run to reproduce the bug.
Expected behavior
The code works fine. But as I've mentioned, the agent fails to recover after the MCP server is restarted (which can happen naturally). and I just get the error:
I think there should be a way to do recover with new session ID
The text was updated successfully, but these errors were encountered: