Fixes #96 ## Motivation and Context See #96 ## How Has This Been Tested? Has some unit and integration tests, still needs proper testing of the different registry types ## Breaking Changes Yes, new package uploads will need extra verification ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update
29 lines
1 KiB
Go
29 lines
1 KiB
Go
package validators
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/modelcontextprotocol/registry/internal/validators/registries"
|
|
"github.com/modelcontextprotocol/registry/pkg/model"
|
|
)
|
|
|
|
// ValidatePackage validates that the package referenced in the server configuration is:
|
|
// 1. allowed on the official registry (based on registry base url); and
|
|
// 2. owned by the publisher, by checking for a matching server name in the package metadata
|
|
func ValidatePackage(ctx context.Context, pkg model.Package, serverName string) error {
|
|
switch pkg.RegistryType {
|
|
case model.RegistryTypeNPM:
|
|
return registries.ValidateNPM(ctx, pkg, serverName)
|
|
case model.RegistryTypePyPI:
|
|
return registries.ValidatePyPI(ctx, pkg, serverName)
|
|
case model.RegistryTypeNuGet:
|
|
return registries.ValidateNuGet(ctx, pkg, serverName)
|
|
case model.RegistryTypeOCI:
|
|
return registries.ValidateOCI(ctx, pkg, serverName)
|
|
case model.RegistryTypeMCPB:
|
|
return registries.ValidateMCPB(ctx, pkg, serverName)
|
|
default:
|
|
return fmt.Errorf("unsupported registry type: %s", pkg.RegistryType)
|
|
}
|
|
}
|