-
Notifications
You must be signed in to change notification settings - Fork 781
Second pass at implementing the mcp-agent CLI #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
2cbe913
f547c2d
804b23f
0116cbc
90901dc
c73be69
4c68f92
814451e
1f7e626
7454582
458f462
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -191,6 +191,8 @@ async def _run(): | |||||||||||||||||||||||||||||||||||||||
| info_table.add_row("Address", f"http://{address}") | ||||||||||||||||||||||||||||||||||||||||
| if transport == "sse": | ||||||||||||||||||||||||||||||||||||||||
| info_table.add_row("SSE Endpoint", f"http://{address}/sse") | ||||||||||||||||||||||||||||||||||||||||
| elif transport == "http": | ||||||||||||||||||||||||||||||||||||||||
| info_table.add_row("HTTP Endpoint", f"http://{address}/mcp") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Show registered components | ||||||||||||||||||||||||||||||||||||||||
| if hasattr(app_obj, "workflows") and app_obj.workflows: | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -251,6 +253,7 @@ async def _run(): | |||||||||||||||||||||||||||||||||||||||
| def signal_handler(sig, frame): | ||||||||||||||||||||||||||||||||||||||||
| console.print("\n[yellow]Shutting down server...[/yellow]") | ||||||||||||||||||||||||||||||||||||||||
| shutdown_event.set() | ||||||||||||||||||||||||||||||||||||||||
| os._exit(0) | ||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t call os._exit(0) in signal handler. It bypasses cleanup and can corrupt logs/metrics. Immediate exit prevents graceful shutdown, resource cleanup, and OTEL/exporter flushes. Use a cooperative shutdown signal instead. - def signal_handler(sig, frame):
+ # Keep a reference to the uvicorn server for cooperative shutdown
+ server_ref = {"srv": None}
+
+ def signal_handler(sig, frame):
console.print("\n[yellow]Shutting down server...[/yellow]")
shutdown_event.set()
- os._exit(0)
+ # For HTTP/SSE, ask uvicorn to exit if running
+ srv = server_ref.get("srv")
+ if srv is not None:
+ try:
+ srv.should_exit = True
+ except Exception:
+ pass
@@
- server = uvicorn.Server(uvicorn_config)
+ server = uvicorn.Server(uvicorn_config)
+ server_ref["srv"] = server📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| signal.signal(signal.SIGINT, signal_handler) | ||||||||||||||||||||||||||||||||||||||||
| signal.signal(signal.SIGTERM, signal_handler) | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -284,7 +287,7 @@ def signal_handler(sig, frame): | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Configure uvicorn | ||||||||||||||||||||||||||||||||||||||||
| uvicorn_config = uvicorn.Config( | ||||||||||||||||||||||||||||||||||||||||
| mcp.app, | ||||||||||||||||||||||||||||||||||||||||
| mcp.streamable_http_app if transport == "http" else mcp.sse_app, | ||||||||||||||||||||||||||||||||||||||||
| host=host, | ||||||||||||||||||||||||||||||||||||||||
| port=port or 8000, | ||||||||||||||||||||||||||||||||||||||||
| log_level="debug" if debug else "info", | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -307,6 +310,10 @@ def signal_handler(sig, frame): | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if transport == "sse": | ||||||||||||||||||||||||||||||||||||||||
| console.print(f"[bold]SSE:[/bold] http://{host}:{port or 8000}/sse") | ||||||||||||||||||||||||||||||||||||||||
| elif transport == "http": | ||||||||||||||||||||||||||||||||||||||||
| console.print( | ||||||||||||||||||||||||||||||||||||||||
| f"[bold]HTTP:[/bold] http://{host}:{port or 8000}/mcp" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| console.print("\n[dim]Press Ctrl+C to stop the server[/dim]\n") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.