Handle keyboard interrupt

This commit is contained in:
Yiorgis Gozadinos 2025-06-20 10:18:07 +02:00
parent 18e1e79598
commit 03b2b20ae2
No known key found for this signature in database

View file

@ -96,12 +96,21 @@ class HaikuRAGApp:
"""Start the MCP server.""" """Start the MCP server."""
async with HaikuRAG(self.db_path) as client: async with HaikuRAG(self.db_path) as client:
monitor = FileWatcher(paths=Config.MONITOR_DIRECTORIES, client=client) monitor = FileWatcher(paths=Config.MONITOR_DIRECTORIES, client=client)
asyncio.create_task(monitor.observe()) monitor_task = asyncio.create_task(monitor.observe())
server = create_mcp_server(self.db_path) server = create_mcp_server(self.db_path)
if transport == "stdio": try:
await server.run_stdio_async() if transport == "stdio":
elif transport == "sse": await server.run_stdio_async()
await server.run_sse_async("sse") elif transport == "sse":
else: await server.run_sse_async("sse")
await server.run_http_async("streamable-http") else:
await server.run_http_async("streamable-http")
except KeyboardInterrupt:
pass
finally:
monitor_task.cancel()
try:
await monitor_task
except asyncio.CancelledError:
pass