Add new 'network' transport mode that serves both HTTP and SSE protocols on the same port with different URL paths: - HTTP endpoint: /mcp - SSE endpoint: /sse Changes: - Add network mode to operation/operation.go using http.ServeMux routing - Update cmd/cmd.go flag descriptions to include network option - Update README.md with network mode documentation and examples - Update config.json with network mode configuration examples The network mode allows clients to choose between HTTP or SSE protocols without requiring separate server instances or ports. This provides better resource utilization and simpler deployment. Backward compatibility maintained - all existing modes (stdio, http, sse) work unchanged. Based on v0.3.0 for clean upstream compatibility.
111 lines
1.8 KiB
Go
111 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"os"
|
|
|
|
"gitea.com/gitea/gitea-mcp/operation"
|
|
flagPkg "gitea.com/gitea/gitea-mcp/pkg/flag"
|
|
"gitea.com/gitea/gitea-mcp/pkg/log"
|
|
)
|
|
|
|
var (
|
|
host string
|
|
port int
|
|
token string
|
|
)
|
|
|
|
func init() {
|
|
flag.StringVar(
|
|
&flagPkg.Mode,
|
|
"t",
|
|
"stdio",
|
|
"Transport type (stdio, sse, http, or network)",
|
|
)
|
|
flag.StringVar(
|
|
&flagPkg.Mode,
|
|
"transport",
|
|
"stdio",
|
|
"Transport type (stdio, sse, http, or network)",
|
|
)
|
|
flag.StringVar(
|
|
&host,
|
|
"host",
|
|
os.Getenv("GITEA_HOST"),
|
|
"Gitea host",
|
|
)
|
|
flag.IntVar(
|
|
&port,
|
|
"port",
|
|
8080,
|
|
"see or http port",
|
|
)
|
|
flag.StringVar(
|
|
&token,
|
|
"token",
|
|
"",
|
|
"Your personal access token",
|
|
)
|
|
flag.BoolVar(
|
|
&flagPkg.ReadOnly,
|
|
"read-only",
|
|
false,
|
|
"Read-only mode",
|
|
)
|
|
flag.BoolVar(
|
|
&flagPkg.Debug,
|
|
"d",
|
|
false,
|
|
"debug mode (If -d flag is provided, debug mode will be enabled by default)",
|
|
)
|
|
flag.BoolVar(
|
|
&flagPkg.Insecure,
|
|
"insecure",
|
|
false,
|
|
"ignore TLS certificate errors",
|
|
)
|
|
|
|
flag.Parse()
|
|
|
|
flagPkg.Host = host
|
|
if flagPkg.Host == "" {
|
|
flagPkg.Host = "https://gitea.com"
|
|
}
|
|
|
|
flagPkg.Port = port
|
|
|
|
flagPkg.Token = token
|
|
if flagPkg.Token == "" {
|
|
flagPkg.Token = os.Getenv("GITEA_ACCESS_TOKEN")
|
|
}
|
|
|
|
if os.Getenv("MCP_MODE") != "" {
|
|
flagPkg.Mode = os.Getenv("MCP_MODE")
|
|
}
|
|
|
|
if os.Getenv("GITEA_READONLY") == "true" {
|
|
flagPkg.ReadOnly = true
|
|
}
|
|
|
|
if os.Getenv("GITEA_DEBUG") == "true" {
|
|
flagPkg.Debug = true
|
|
}
|
|
|
|
// Set insecure mode based on environment variable
|
|
if os.Getenv("GITEA_INSECURE") == "true" {
|
|
flagPkg.Insecure = true
|
|
}
|
|
}
|
|
|
|
func Execute() {
|
|
defer log.Default().Sync()
|
|
if err := operation.Run(); err != nil {
|
|
if err == context.Canceled {
|
|
log.Info("Server shutdown due to context cancellation")
|
|
return
|
|
}
|
|
log.Fatalf("Run Gitea MCP Server Error: %v", err)
|
|
}
|
|
}
|