Changes on the server.json format and the API (#562)

This commit is contained in:
Radoslav Dimitrov 2025-09-29 23:30:35 +03:00 • committed by GitHub
commit b21c6f564d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4056 additions and 5608 deletions

View file

@ -343,7 +343,7 @@ func validateRemoteTransport(obj *model.Transport) error {
}
// ValidatePublishRequest validates a complete publish request including extensions
func ValidatePublishRequest(req apiv0.ServerJSON, cfg *config.Config) error {
func ValidatePublishRequest(ctx context.Context, req apiv0.ServerJSON, cfg *config.Config) error {
// Validate publisher extensions in _meta
if err := validatePublisherExtensions(req); err != nil {
return err
@ -354,9 +354,8 @@ func ValidatePublishRequest(req apiv0.ServerJSON, cfg *config.Config) error {
return err
}
// Validate registry ownership for all packages if validation is enabled and server is not deleted
if cfg.EnableRegistryValidation && req.Status != model.StatusDeleted {
ctx := context.Background()
// Validate registry ownership for all packages if validation is enabled
if cfg.EnableRegistryValidation {
for i, pkg := range req.Packages {
if err := ValidatePackage(ctx, pkg, req.Name); err != nil {
return fmt.Errorf("registry validation failed for package %d (%s): %w", i, pkg.Identifier, err)
@ -381,12 +380,8 @@ func validatePublisherExtensions(req apiv0.ServerJSON) error {
}
}
if req.Meta != nil {
// Validate that only publisher-provided data is allowed in _meta during publish (no official registry metadata should be present)
if req.Meta.Official != nil {
return fmt.Errorf("official registry metadata '_meta.io.modelcontextprotocol.registry/official' is not allowed during publish")
}
}
// Note: ServerJSON._meta only contains PublisherProvided data
// Official registry metadata is handled separately in the response structure
return nil
}

View file

@ -1,6 +1,7 @@
package validators_test
import (
"context"
"fmt"
"testing"
@ -1551,7 +1552,7 @@ func TestValidate_RegistryTypesAndUrls(t *testing.T) {
},
}
err := validators.ValidatePublishRequest(serverJSON, &config.Config{
err := validators.ValidatePublishRequest(context.Background(), serverJSON, &config.Config{
EnableRegistryValidation: true,
})
if tc.expectError {