fix(mcp): clean up connections on exit in interactive and gateway modes

This commit is contained in:
Sergio Sánchez Vallés 2026-02-12 10:44:25 +01:00
parent 61e9f7f58a
commit d30523f460
No known key found for this signature in database

View File

@ -387,6 +387,8 @@ def gateway(
)
except KeyboardInterrupt:
console.print("\nShutting down...")
finally:
await agent._close_mcp()
heartbeat.stop()
cron.stop()
agent.stop()
@ -465,30 +467,33 @@ def agent(
signal.signal(signal.SIGINT, _exit_on_sigint)
async def run_interactive():
while True:
try:
_flush_pending_tty_input()
user_input = await _read_interactive_input_async()
command = user_input.strip()
if not command:
continue
try:
while True:
try:
_flush_pending_tty_input()
user_input = await _read_interactive_input_async()
command = user_input.strip()
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()
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()
console.print("\nGoodbye!")
break
except EOFError:
_restore_terminal()
console.print("\nGoodbye!")
break
except EOFError:
_restore_terminal()
console.print("\nGoodbye!")
break
finally:
await agent_loop._close_mcp()
asyncio.run(run_interactive())