diff --git a/.env.example b/.env.example index bfadfd442..daea3cf89 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,9 @@ MCP_REGISTRY_DATABASE_URL=postgres://username:password@localhost:5432/mcp-regist # For offline development, use: data/seed.json MCP_REGISTRY_SEED_FROM=https://registry.modelcontextprotocol.io/v0/servers +# Custom MCP Registry URL for self-hosted instances (optional) +MCP_REGISTRY_CUSTOM_MCP_REGISTRY_URL=https://your-registry-url.com + # GitHub OAuth configuration # These creds are for local development with the 'MCP Registry Login (Local)' GitHub App # They don't provide any real privileged access, hence why it's okay that they're here diff --git a/internal/api/handlers/v0/ui.go b/internal/api/handlers/v0/ui.go index 32aadd4e2..769553fc6 100644 --- a/internal/api/handlers/v0/ui.go +++ b/internal/api/handlers/v0/ui.go @@ -2,12 +2,39 @@ package v0 import ( _ "embed" + "encoding/json" + "strings" ) //go:embed ui_index.html var embedUI string -// GetUIHTML returns the embedded HTML for the UI -func GetUIHTML() string { - return embedUI +const ( + defaultAPIBasePlaceholder = "PLACEHOLDER" + defaultAPIBaseValueKey = "__DEFAULT_API_BASE_VALUE__" + defaultAPIBasePlaceholderKey = "__DEFAULT_API_BASE_PLACEHOLDER__" +) + +// GetUIHTML returns the embedded HTML for the UI with injected API base URL configuration. +// The defaultBaseURL is injected into the JavaScript context to allow the frontend to +// access a custom registry URL set via environment variable. If no custom URL is provided, +// the frontend will fall back to the default production registry. +func GetUIHTML(defaultBaseURL string) string { + // Marshal the URL to get a JSON-encoded string for safe JavaScript injection + jsonEncoded, err := json.Marshal(defaultBaseURL) + if err != nil { + // Fallback to empty string if marshaling fails (should be very rare for strings) + jsonEncoded = []byte(`""`) + } + + // Trim the surrounding quotes from JSON encoding to get the raw URL value + value := strings.Trim(string(jsonEncoded), `"`) + + // Inject the actual URL value into the UI + html := strings.ReplaceAll(embedUI, defaultAPIBaseValueKey, value) + + // Inject the placeholder sentinel value for frontend comparison logic + html = strings.ReplaceAll(html, defaultAPIBasePlaceholderKey, defaultAPIBasePlaceholder) + + return html } diff --git a/internal/api/handlers/v0/ui_index.html b/internal/api/handlers/v0/ui_index.html index 38bac7f7b..b3e77c68d 100644 --- a/internal/api/handlers/v0/ui_index.html +++ b/internal/api/handlers/v0/ui_index.html @@ -138,6 +138,9 @@

API Base URL