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

Function validatePackageTransport

internal/validators/validators.go:517–575  ·  view source on GitHub ↗

validatePackageTransport validates a package's transport with templating support

(ctx *ValidationContext, transport *model.Transport, availableVariables []string)

Source from the content-addressed store, hash-verified

515
516// validatePackageTransport validates a package's transport with templating support
517func validatePackageTransport(ctx *ValidationContext, transport *model.Transport, availableVariables []string) *ValidationResult {
518 result := &ValidationResult{Valid: true, Issues: []ValidationIssue{}}
519
520 // Validate transport type is supported
521 switch transport.Type {
522 case model.TransportTypeStdio:
523 // Validate that URL is empty for stdio transport
524 if transport.URL != "" {
525 issue := NewValidationIssue(
526 ValidationIssueTypeSemantic,
527 ctx.Field("url").String(),
528 fmt.Sprintf("url must be empty for %s transport type, got: %s", transport.Type, transport.URL),
529 ValidationIssueSeverityError,
530 "stdio-transport-url-not-empty",
531 )
532 result.AddIssue(issue)
533 }
534 case model.TransportTypeStreamableHTTP, model.TransportTypeSSE:
535 // URL is required for streamable-http and sse
536 if transport.URL == "" {
537 issue := NewValidationIssue(
538 ValidationIssueTypeSemantic,
539 ctx.Field("url").String(),
540 fmt.Sprintf("url is required for %s transport type", transport.Type),
541 ValidationIssueSeverityError,
542 "streamable-transport-url-required",
543 )
544 result.AddIssue(issue)
545 } else if !IsValidTemplatedURL(transport.URL, availableVariables) {
546 // Check if it's a template variable issue or basic URL issue
547 templateVars := extractTemplateVariables(transport.URL)
548 var err error
549 if len(templateVars) > 0 {
550 err = fmt.Errorf("%w: template variables in URL %s reference undefined variables. Available variables: %v",
551 ErrInvalidPackageTransportURL, transport.URL, availableVariables)
552 } else {
553 err = fmt.Errorf("%w: %s", ErrInvalidPackageTransportURL, transport.URL)
554 }
555 issue := NewValidationIssueFromError(
556 ValidationIssueTypeSemantic,
557 ctx.Field("url").String(),
558 err,
559 "invalid-templated-url",
560 )
561 result.AddIssue(issue)
562 }
563 default:
564 issue := NewValidationIssue(
565 ValidationIssueTypeSemantic,
566 ctx.Field("type").String(),
567 fmt.Sprintf("unsupported transport type: %s", transport.Type),
568 ValidationIssueSeverityError,
569 "unsupported-transport-type",
570 )
571 result.AddIssue(issue)
572 }
573
574 return result

Callers 1

validatePackageFieldFunction · 0.85

Calls 7

AddIssueMethod · 0.95
NewValidationIssueFunction · 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…