Repository: modelcontextprotocol/registry
File: internal/validators/validators.go (Go)

Code before:
	// - ">1.0.0",
	// - "<1.0.0",
	// - "=1.0.0",
	comparatorRangeRe = regexp.MustCompile(`^\s*(?:\^|~|>=|<=|>|<|=)\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*$`)
	// Case 2: hyphen ranges
	// - "1.2.3 - 2.0.0",
	hyphenRangeRe = regexp.MustCompile(`^\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s-\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*$`)
	// Case 3: OR ranges
	// - "1.2 || 1.3",
	orRangeRe = regexp.MustCompile(`^\s*(?:v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*)(?:\|\|\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*)+$`)
	// Case 4: dotted version wildcards
	// - "1.2.*",
	// - "1.2.x",
	// - "1.2.X",
	// - "1.x",
	// etc.
	dottedVersionLikeRe = regexp.MustCompile(`^\s*(?:v?\d+|x|X|\*)(?:\.(?:\d+|x|X|\*)){1,2}(?:-[0-9A-Za-z.-]+)?\s*$`)
)

func ValidateServerJSON(serverJSON *apiv0.ServerJSON) error {
	// Validate schema version is provided and supported
	if serverJSON.Schema == "" {
		return fmt.Errorf("$schema field is required")
	}
	if !strings.Contains(serverJSON.Schema, model.CurrentSchemaVersion) {
		return fmt.Errorf("schema version %s is not supported. Please use schema version %s or later", serverJSON.Schema, model.CurrentSchemaVersion)
	}

	// Validate server name exists and format
	if _, err := parseServerName(*serverJSON); err != nil {
		return err
	}

	// Validate top-level server version is a specific version (not a range) & not "latest"
	if err := validateVersion(serverJSON.Version); err != nil {
		return err
	}

	// Validate repository
	if err := validateRepository(&serverJSON.Repository); err != nil {
		return err
	}

	// Validate website URL if provided
	if err := validateWebsiteURL(serverJSON.WebsiteURL); err != nil {
		return err
	}

	// Validate all packages (basic field validation)
	// Detailed package validation (including registry checks) is done during publish
	for _, pkg := range serverJSON.Packages {

Review comment (bug):
Regarding the wording of the error message: `Please use schema version %s or later`

Might be wrong here, but it seems to me that we are doing an exact version check, which would also return an error if a "later" version is used 

Code after:
	// - ">1.0.0",
	// - "<1.0.0",
	// - "=1.0.0",
	comparatorRangeRe = regexp.MustCompile(`^\s*(?:\^|~|>=|<=|>|<|=)\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*$`)
	// Case 2: hyphen ranges
	// - "1.2.3 - 2.0.0",
	hyphenRangeRe = regexp.MustCompile(`^\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s-\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*$`)
	// Case 3: OR ranges
	// - "1.2 || 1.3",
	orRangeRe = regexp.MustCompile(`^\s*(?:v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*)(?:\|\|\s*v?\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z.-]+)?\s*)+$`)
	// Case 4: dotted version wildcards
	// - "1.2.*",
	// - "1.2.x",
	// - "1.2.X",
	// - "1.x",
	// etc.
	dottedVersionLikeRe = regexp.MustCompile(`^\s*(?:v?\d+|x|X|\*)(?:\.(?:\d+|x|X|\*)){1,2}(?:-[0-9A-Za-z.-]+)?\s*$`)
)

func ValidateServerJSON(serverJSON *apiv0.ServerJSON) error {
	// Validate schema version is provided and supported
	// Note: Schema field is also marked as required in the ServerJSON struct definition
	// for API-level validation and documentation
	if serverJSON.Schema == "" {
		return fmt.Errorf("$schema field is required")
	}
	if !strings.Contains(serverJSON.Schema, model.CurrentSchemaVersion) {
		return fmt.Errorf("schema version %s is not supported. Please use schema version %s", serverJSON.Schema, model.CurrentSchemaVersion)
	}

	// Validate server name exists and format
	if _, err := parseServerName(*serverJSON); err != nil {
		return err
	}

	// Validate top-level server version is a specific version (not a range) & not "latest"
	if err := validateVersion(serverJSON.Version); err != nil {
		return err
	}

	// Validate repository
	if err := validateRepository(&serverJSON.Repository); err != nil {
		return err
	}

	// Validate website URL if provided
	if err := validateWebsiteURL(serverJSON.WebsiteURL); err != nil {
		return err
	}

	// Validate all packages (basic field validation)