MCPcopy Index your code
hub / github.com/modelcontextprotocol/registry / replaceTemplateVariables

Function replaceTemplateVariables

internal/validators/utils.go:49–75  ·  view source on GitHub ↗

replaceTemplateVariables replaces template variables with placeholder values for URL validation

(rawURL string)

Source from the content-addressed store, hash-verified

47
48// replaceTemplateVariables replaces template variables with placeholder values for URL validation
49func replaceTemplateVariables(rawURL string) string {
50 // Replace common template variables with valid placeholder values for parsing
51 templateReplacements := map[string]string{
52 "{host}": "example.com",
53 "{port}": "8080",
54 "{path}": "api",
55 "{protocol}": "http",
56 "{scheme}": "http",
57 }
58
59 result := rawURL
60 for placeholder, replacement := range templateReplacements {
61 result = strings.ReplaceAll(result, placeholder, replacement)
62 }
63
64 // Handle any remaining {variable} patterns with context-appropriate placeholders
65 // If the variable is in a port position (after a colon in the host), use a numeric placeholder
66 // Pattern: :/{variable} or :{variable}/ or :{variable} at end
67 portRe := regexp.MustCompile(`:(\{[^}]+\})(/|$)`)
68 result = portRe.ReplaceAllString(result, ":8080$2")
69
70 // Replace any other remaining {variable} patterns with generic placeholder
71 re := regexp.MustCompile(`\{[^}]+\}`)
72 result = re.ReplaceAllString(result, "placeholder")
73
74 return result
75}
76
77// IsValidURL checks if a URL is in valid format (basic structure validation)
78func IsValidURL(rawURL string) bool {

Callers 2

IsValidURLFunction · 0.85
IsValidRemoteURLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…