From 8dc9ed929998b66869c7b3d61e93fc0ae3690595 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 8 Apr 2025 01:16:37 +0000 Subject: [PATCH] feat: add support for insecure mode in Gitea client configuration (#20) - Add `GITEA_INTERACTIVE` configuration example in README files - Add `insecure` flag to ignore TLS certificate errors in `cmd.go` - Set insecure mode based on `GITEA_INSECURE` environment variable in `cmd.go` - Add `Insecure` boolean variable in `pkg/flag/flag.go` - Import `crypto/tls` and `net/http` in `pkg/gitea/gitea.go` - Modify Gitea client creation to support insecure HTTP client in `pkg/gitea/gitea.go` Signed-off-by: Bo-Yi Wu Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/20 Reviewed-by: Lunny Xiao Co-authored-by: Bo-Yi Wu Co-committed-by: Bo-Yi Wu --- README.md | 1 + README.zh-cn.md | 1 + README.zh-tw.md | 1 + cmd/cmd.go | 11 +++++++++++ pkg/flag/flag.go | 3 ++- pkg/gitea/gitea.go | 26 +++++++++++++++++++++----- 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a97851..a2b26db 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ To configure the MCP server for Gitea, add the following to your MCP configurati ], "env": { // "GITEA_HOST": "https://gitea.com", + // "GITEA_INTERACTIVE": "true", "GITEA_ACCESS_TOKEN": "" } } diff --git a/README.zh-cn.md b/README.zh-cn.md index 6abca53..af8187b 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -109,6 +109,7 @@ cp gitea-mcp /usr/local/bin/ ], "env": { // "GITEA_HOST": "https://gitea.com", + // "GITEA_INTERACTIVE": "true", "GITEA_ACCESS_TOKEN": "" } } diff --git a/README.zh-tw.md b/README.zh-tw.md index 79af63a..ad1346d 100644 --- a/README.zh-tw.md +++ b/README.zh-tw.md @@ -109,6 +109,7 @@ cp gitea-mcp /usr/local/bin/ ], "env": { // "GITEA_HOST": "https://gitea.com", + // "GITEA_INTERACTIVE": "true", "GITEA_ACCESS_TOKEN": "" } } diff --git a/cmd/cmd.go b/cmd/cmd.go index 4ee9dc1..30730a7 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -62,6 +62,12 @@ func init() { true, "debug mode", ) + flag.BoolVar( + &flagPkg.Insecure, + "insecure", + false, + "ignore TLS certificate errors", + ) flag.Parse() @@ -88,6 +94,11 @@ func init() { if !debug { flagPkg.Debug = os.Getenv("GITEA_DEBUG") == "true" } + + // Set insecure mode based on environment variable + if os.Getenv("GITEA_INSECURE") == "true" { + flagPkg.Insecure = true + } } func Execute(version string) { diff --git a/pkg/flag/flag.go b/pkg/flag/flag.go index 20b032a..0c6d4a6 100644 --- a/pkg/flag/flag.go +++ b/pkg/flag/flag.go @@ -7,5 +7,6 @@ var ( Version string Mode string - Debug bool + Insecure bool + Debug bool ) diff --git a/pkg/gitea/gitea.go b/pkg/gitea/gitea.go index daa9728..3aff2bd 100644 --- a/pkg/gitea/gitea.go +++ b/pkg/gitea/gitea.go @@ -1,6 +1,8 @@ package gitea import ( + "crypto/tls" + "net/http" "sync" "gitea.com/gitea/gitea-mcp/pkg/flag" @@ -16,12 +18,26 @@ var ( func Client() *gitea.Client { clientOnce.Do(func() { - if client == nil { - c, err := gitea.NewClient(flag.Host, gitea.SetToken(flag.Token)) - if err != nil { - log.Fatalf("create gitea client err: %v", err) + var err error + if client != nil { + return + } + opts := []gitea.ClientOption{ + gitea.SetToken(flag.Token), + } + if flag.Insecure { + httpClient := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, } - client = c + opts = append(opts, gitea.SetHTTPClient(httpClient)) + } + client, err = gitea.NewClient(flag.Host, opts...) + if err != nil { + log.Fatalf("create gitea client err: %v", err) } }) return client