feat: add multi-server support via GITEA_SERVERS env var

Allows connecting to multiple Gitea instances from a single MCP server.
Set GITEA_SERVERS as a JSON object mapping names to {host, token, insecure}
configs. Every tool gets an optional "server" parameter, and a new
"list_servers" tool is added to discover available connections.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 17:28:40 +00:00
parent 4b4b5ee247
commit 58d2feb54a
6 changed files with 150 additions and 49 deletions
+13
View File
@@ -2,6 +2,7 @@ package cmd
import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
@@ -57,6 +58,7 @@ func init() {
fmt.Fprintf(w, " GITEA_HOST\tOverride Gitea host URL\n")
fmt.Fprintf(w, " GITEA_INSECURE\tSet to 'true' to ignore TLS errors\n")
fmt.Fprintf(w, " GITEA_READONLY\tSet to 'true' for read-only mode\n")
fmt.Fprintf(w, " GITEA_SERVERS\tJSON object mapping server names to {host, token, insecure} configs\n")
fmt.Fprintf(w, " MCP_MODE\tOverride transport mode\n")
w.Flush()
}
@@ -91,6 +93,17 @@ func init() {
if os.Getenv("GITEA_INSECURE") == "true" {
flagPkg.Insecure = true
}
// Parse multi-server configuration from GITEA_SERVERS env var (JSON object).
// Example: {"dev":{"host":"https://gitea.dev.example.com","token":"xxx"},"prod":{...}}
if serversJSON := os.Getenv("GITEA_SERVERS"); serversJSON != "" {
var servers map[string]flagPkg.ServerConfig
if err := json.Unmarshal([]byte(serversJSON), &servers); err != nil {
fmt.Fprintf(os.Stderr, "Warning: failed to parse GITEA_SERVERS: %v\n", err)
} else {
flagPkg.Servers = servers
}
}
}
func Execute() {