fix(mcp): clean up connections on exit in interactive and gateway modes
This commit is contained in:
parent
61e9f7f58a
commit
d30523f460
@ -387,6 +387,8 @@ def gateway(
|
|||||||
)
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console.print("\nShutting down...")
|
console.print("\nShutting down...")
|
||||||
|
finally:
|
||||||
|
await agent._close_mcp()
|
||||||
heartbeat.stop()
|
heartbeat.stop()
|
||||||
cron.stop()
|
cron.stop()
|
||||||
agent.stop()
|
agent.stop()
|
||||||
@ -465,30 +467,33 @@ def agent(
|
|||||||
signal.signal(signal.SIGINT, _exit_on_sigint)
|
signal.signal(signal.SIGINT, _exit_on_sigint)
|
||||||
|
|
||||||
async def run_interactive():
|
async def run_interactive():
|
||||||
while True:
|
try:
|
||||||
try:
|
while True:
|
||||||
_flush_pending_tty_input()
|
try:
|
||||||
user_input = await _read_interactive_input_async()
|
_flush_pending_tty_input()
|
||||||
command = user_input.strip()
|
user_input = await _read_interactive_input_async()
|
||||||
if not command:
|
command = user_input.strip()
|
||||||
continue
|
if not command:
|
||||||
|
continue
|
||||||
|
|
||||||
if _is_exit_command(command):
|
if _is_exit_command(command):
|
||||||
|
_restore_terminal()
|
||||||
|
console.print("\nGoodbye!")
|
||||||
|
break
|
||||||
|
|
||||||
|
with _thinking_ctx():
|
||||||
|
response = await agent_loop.process_direct(user_input, session_id)
|
||||||
|
_print_agent_response(response, render_markdown=markdown)
|
||||||
|
except KeyboardInterrupt:
|
||||||
_restore_terminal()
|
_restore_terminal()
|
||||||
console.print("\nGoodbye!")
|
console.print("\nGoodbye!")
|
||||||
break
|
break
|
||||||
|
except EOFError:
|
||||||
with _thinking_ctx():
|
_restore_terminal()
|
||||||
response = await agent_loop.process_direct(user_input, session_id)
|
console.print("\nGoodbye!")
|
||||||
_print_agent_response(response, render_markdown=markdown)
|
break
|
||||||
except KeyboardInterrupt:
|
finally:
|
||||||
_restore_terminal()
|
await agent_loop._close_mcp()
|
||||||
console.print("\nGoodbye!")
|
|
||||||
break
|
|
||||||
except EOFError:
|
|
||||||
_restore_terminal()
|
|
||||||
console.print("\nGoodbye!")
|
|
||||||
break
|
|
||||||
|
|
||||||
asyncio.run(run_interactive())
|
asyncio.run(run_interactive())
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user