This repository has been archived on 2025-12-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gitea-mcp/cmd/cmd.go
b3nw e3f7405cd8 feat: add network mode with combined HTTP and SSE endpoints
- Add new 'network' transport mode that serves both HTTP and SSE endpoints simultaneously
- HTTP endpoint available on specified port (/mcp)
- SSE endpoint available on port+1 (/sse)
- Maintain backward compatibility with stdio, http, sse modes
- Update documentation and examples for new network mode
- Default to network mode for improved user experience

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-13 17:26:12 +00:00

111 lines
1.9 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",
"network",
"Transport type (stdio, http, sse, or network). Network mode starts both HTTP and SSE servers",
)
flag.StringVar(
&flagPkg.Mode,
"transport",
"network",
"Transport type (stdio, http, sse, or network). Network mode starts both HTTP and SSE servers",
)
flag.StringVar(
&host,
"host",
os.Getenv("GITEA_HOST"),
"Gitea host",
)
flag.IntVar(
&port,
"port",
8080,
"Network server port (used for both HTTP and SSE endpoints)",
)
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)
}
}