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

Function validateRemoteTransport

internal/validators/validators.go:578–640  ·  view source on GitHub ↗

validateRemoteTransport validates a remote transport with optional templating

(ctx *ValidationContext, obj *model.Transport)

Source from the content-addressed store, hash-verified

576
577// validateRemoteTransport validates a remote transport with optional templating
578func validateRemoteTransport(ctx *ValidationContext, obj *model.Transport) *ValidationResult {
579 result := &ValidationResult{Valid: true, Issues: []ValidationIssue{}}
580
581 // Validate transport type is supported - remotes only support streamable-http and sse
582 switch obj.Type {
583 case model.TransportTypeStreamableHTTP, model.TransportTypeSSE:
584 // URL is required for streamable-http and sse
585 if obj.URL == "" {
586 issue := NewValidationIssue(
587 ValidationIssueTypeSemantic,
588 ctx.Field("url").String(),
589 fmt.Sprintf("url is required for %s transport type", obj.Type),
590 ValidationIssueSeverityError,
591 "remote-transport-url-required",
592 )
593 result.AddIssue(issue)
594 } else if !IsValidRemoteURL(obj.URL) {
595 // Validate URL format (no templates allowed for remotes, no localhost)
596 issue := NewValidationIssueFromError(
597 ValidationIssueTypeSemantic,
598 ctx.Field("url").String(),
599 fmt.Errorf("%w: %s", ErrInvalidRemoteURL, obj.URL),
600 "invalid-remote-url",
601 )
602 result.AddIssue(issue)
603 }
604
605 // Collect available variables from the transport's Variables field
606 availableVariables := collectRemoteTransportVariables(obj)
607
608 // Validate URL format with template variable support
609 if !IsValidTemplatedURL(obj.URL, availableVariables) {
610 // Check if it's a template variable issue or basic URL issue
611 templateVars := extractTemplateVariables(obj.URL)
612 var err error
613 if len(templateVars) > 0 {
614 err = fmt.Errorf("%w: template variables in URL %s reference undefined variables. Available variables: %v",
615 ErrInvalidRemoteURL, obj.URL, availableVariables)
616 } else {
617 err = fmt.Errorf("%w: %s", ErrInvalidRemoteURL, obj.URL)
618 }
619 issue := NewValidationIssueFromError(
620 ValidationIssueTypeSemantic,
621 ctx.Field("url").String(),
622 err,
623 "invalid-templated-url",
624 )
625 result.AddIssue(issue)
626 }
627 return result
628 default:
629 issue := NewValidationIssue(
630 ValidationIssueTypeSemantic,
631 ctx.Field("type").String(),
632 fmt.Sprintf("unsupported transport type for remotes: %s (only streamable-http and sse are supported)", obj.Type),
633 ValidationIssueSeverityError,
634 "unsupported-remote-transport-type",
635 )

Callers 1

ValidateServerJSONFunction · 0.85

Calls 9

AddIssueMethod · 0.95
NewValidationIssueFunction · 0.85
IsValidRemoteURLFunction · 0.85
IsValidTemplatedURLFunction · 0.85
extractTemplateVariablesFunction · 0.85
FieldMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…