mirror of
https://gitea.com/gitea/gitea-mcp.git
synced 2025-08-23 14:23:05 +00:00
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 <appleboy.tw@gmail.com> Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/20 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -109,6 +109,7 @@ To configure the MCP server for Gitea, add the following to your MCP configurati
|
|||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
// "GITEA_HOST": "https://gitea.com",
|
// "GITEA_HOST": "https://gitea.com",
|
||||||
|
// "GITEA_INTERACTIVE": "true",
|
||||||
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -109,6 +109,7 @@ cp gitea-mcp /usr/local/bin/
|
|||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
// "GITEA_HOST": "https://gitea.com",
|
// "GITEA_HOST": "https://gitea.com",
|
||||||
|
// "GITEA_INTERACTIVE": "true",
|
||||||
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -109,6 +109,7 @@ cp gitea-mcp /usr/local/bin/
|
|||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
// "GITEA_HOST": "https://gitea.com",
|
// "GITEA_HOST": "https://gitea.com",
|
||||||
|
// "GITEA_INTERACTIVE": "true",
|
||||||
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
"GITEA_ACCESS_TOKEN": "<your personal access token>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
cmd/cmd.go
11
cmd/cmd.go
@@ -62,6 +62,12 @@ func init() {
|
|||||||
true,
|
true,
|
||||||
"debug mode",
|
"debug mode",
|
||||||
)
|
)
|
||||||
|
flag.BoolVar(
|
||||||
|
&flagPkg.Insecure,
|
||||||
|
"insecure",
|
||||||
|
false,
|
||||||
|
"ignore TLS certificate errors",
|
||||||
|
)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -88,6 +94,11 @@ func init() {
|
|||||||
if !debug {
|
if !debug {
|
||||||
flagPkg.Debug = os.Getenv("GITEA_DEBUG") == "true"
|
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) {
|
func Execute(version string) {
|
||||||
|
@@ -7,5 +7,6 @@ var (
|
|||||||
Version string
|
Version string
|
||||||
Mode string
|
Mode string
|
||||||
|
|
||||||
Debug bool
|
Insecure bool
|
||||||
|
Debug bool
|
||||||
)
|
)
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
"gitea.com/gitea/gitea-mcp/pkg/flag"
|
||||||
@@ -16,12 +18,26 @@ var (
|
|||||||
|
|
||||||
func Client() *gitea.Client {
|
func Client() *gitea.Client {
|
||||||
clientOnce.Do(func() {
|
clientOnce.Do(func() {
|
||||||
if client == nil {
|
var err error
|
||||||
c, err := gitea.NewClient(flag.Host, gitea.SetToken(flag.Token))
|
if client != nil {
|
||||||
if err != nil {
|
return
|
||||||
log.Fatalf("create gitea client err: %v", err)
|
}
|
||||||
|
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
|
return client
|
||||||
|
Reference in New Issue
Block a user