@@ -3,6 +3,7 @@ package registries
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "net/http"
89 "strings"
@@ -11,6 +12,11 @@ import (
1112 "github.com/modelcontextprotocol/registry/pkg/model"
1213)
1314
15+ var (
16+ ErrMissingIdentifierForPyPI = errors .New ("package identifier is required for PyPI packages" )
17+ ErrMissingVersionForPyPi = errors .New ("package version is required for PyPI packages" )
18+ )
19+
1420// PyPIPackageResponse represents the structure returned by the PyPI JSON API
1521type PyPIPackageResponse struct {
1622 Info struct {
@@ -25,6 +31,14 @@ func ValidatePyPI(ctx context.Context, pkg model.Package, serverName string) err
2531 pkg .RegistryBaseURL = model .RegistryURLPyPI
2632 }
2733
34+ if pkg .Identifier == "" {
35+ return ErrMissingIdentifierForPyPI
36+ }
37+
38+ if pkg .Version == "" {
39+ return ErrMissingVersionForPyPi
40+ }
41+
2842 // Validate that the registry base URL matches PyPI exactly
2943 if pkg .RegistryBaseURL != model .RegistryURLPyPI {
3044 return fmt .Errorf ("registry type and base URL do not match: '%s' is not valid for registry type '%s'. Expected: %s" ,
@@ -33,7 +47,7 @@ func ValidatePyPI(ctx context.Context, pkg model.Package, serverName string) err
3347
3448 client := & http.Client {Timeout : 10 * time .Second }
3549
36- url := fmt .Sprintf ("%s/pypi/%s/json" , pkg .RegistryBaseURL , pkg .Identifier )
50+ url := fmt .Sprintf ("%s/pypi/%s/%s/ json" , pkg .RegistryBaseURL , pkg .Identifier , pkg . Version )
3751 req , err := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
3852 if err != nil {
3953 return fmt .Errorf ("failed to create request: %w" , err )
0 commit comments