Files
gitea-mcp/cmd/cmd.go
appleboy c900e6b4c3 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>
2025-03-16 14:20:55 +08:00

68 lines
1002 B
Go

package cmd
import (
"context"
"flag"
"gitea.com/gitea/gitea-mcp/operation"
flagPkg "gitea.com/gitea/gitea-mcp/pkg/flag"
"gitea.com/gitea/gitea-mcp/pkg/log"
)
var (
transport string
host string
token string
debug bool
)
func init() {
flag.StringVar(
&transport,
"t",
"stdio",
"Transport type (stdio or sse)",
)
flag.StringVar(
&transport,
"transport",
"stdio",
"Transport type (stdio or sse)",
)
flag.StringVar(
&host,
"host",
"https://gitea.com",
"Gitea host",
)
flag.StringVar(
&token,
"token",
"",
"Your personal access token",
)
flag.BoolVar(
&debug,
"debug",
false,
"debug mode",
)
flag.Parse()
flagPkg.Host = host
flagPkg.Token = token
}
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)
}
}