feat: add context management and cancellation handling in Execute function

- Import the `context` package
- Add context cancellation handling with log message and return in `Execute` function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2025-03-16 14:20:55 +08:00
parent c52f8649a2
commit c900e6b4c3

View File

@@ -1,6 +1,7 @@
package cmd
import (
"context"
"flag"
"gitea.com/gitea/gitea-mcp/operation"
@@ -57,6 +58,10 @@ func init() {
func Execute(version string) {
defer log.Default().Sync()
if err := operation.Run(transport, version); err != nil {
if err == context.Canceled {
log.Info("Server shutdown due to context cancellation")
return
}
log.Fatalf("Run Gitea MCP Server Error: %v", err)
}
}