Deduplicate server JSON structs between publisher and registry (#318)
<!-- Provide a brief summary of your changes --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> The following PR eliminates duplicate struct definitions by migrating the publisher tool to use canonical types from pkg/model, creating a single source of truth across the codebase. The publisher tool previously had its own copies of structs that were duplicated, ie. ServerJSON, Package, Repository, VersionDetail, EnvironmentVariable, RuntimeArgument and a few others which was not optimal **Changes in the PR:** - Refactored the structs to single canonical types located at pkg/model - Refactor the implementation to use/build canonical structures directly - Remove all duplicate definitions (5 structs eliminated) - Publisher now uses model.ServerJSON, model.Package, model.Repository, etc. - Renamed some of the structs to better reflect their use case, i.e. ServerJSON instead of ServerDetail - Fixes an issue where the Remote property was missing from the previous publisher copy of the Server **Benefits:** - Single source of truth - Schema changes in one place - Type safety - Compiler catches mismatches - Enhanced validation - Field constraints and bson tags - Zero breaking changes - Same CLI interface and JSON output - Future-proof - New canonical fields automatically available Supersedes: #217 and #240 ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> Locally ## Breaking Changes <!-- Will users need to update their code or configurations? --> No ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [ ] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> --------- Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
This commit is contained in:
parent
9d04671ee3
commit
099a2d702e
39 changed files with 1280 additions and 1408 deletions
|
|
@ -14,9 +14,9 @@ import (
|
|||
"github.com/modelcontextprotocol/registry/internal/api"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/database"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/modelcontextprotocol/registry/internal/service"
|
||||
"github.com/modelcontextprotocol/registry/internal/telemetry"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -46,7 +46,7 @@ func main() {
|
|||
// Initialize services based on environment
|
||||
switch cfg.DatabaseType {
|
||||
case config.DatabaseTypeMemory:
|
||||
db = database.NewMemoryDB(map[string]*model.ServerDetail{})
|
||||
db = database.NewMemoryDB(map[string]*model.ServerJSON{})
|
||||
registryService = service.NewRegistryServiceWithDB(db)
|
||||
case config.DatabaseTypePostgreSQL:
|
||||
// Use PostgreSQL for real registry service
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// DNSTokenExchangeInput represents the input for DNS-based authentication
|
||||
|
|
@ -147,7 +146,7 @@ func (h *DNSAuthHandler) ExchangeToken(ctx context.Context, domain, timestamp, s
|
|||
|
||||
// Create JWT claims
|
||||
jwtClaims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodDNS,
|
||||
AuthMethod: auth.MethodDNS,
|
||||
AuthMethodSubject: domain,
|
||||
Permissions: permissions,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
|
||||
intauth "github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// MockDNSResolver for testing
|
||||
|
|
@ -174,7 +173,7 @@ func TestDNSAuthHandler_ExchangeToken(t *testing.T) {
|
|||
claims, err := jwtManager.ValidateToken(context.Background(), result.RegistryToken)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, model.AuthMethodDNS, claims.AuthMethod)
|
||||
assert.Equal(t, intauth.MethodDNS, claims.AuthMethod)
|
||||
assert.Equal(t, tt.domain, claims.AuthMethodSubject)
|
||||
assert.Len(t, claims.Permissions, 2) // domain and subdomain permissions
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// GitHubTokenExchangeInput represents the input for GitHub token exchange
|
||||
|
|
@ -86,7 +85,7 @@ func (h *GitHubHandler) ExchangeToken(ctx context.Context, githubToken string) (
|
|||
|
||||
// Create JWT claims with GitHub user info
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: user.Login,
|
||||
Permissions: permissions,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
v0auth "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -78,7 +77,7 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) {
|
|||
jwtManager := auth.NewJWTManager(cfg)
|
||||
claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, model.AuthMethodGitHubAT, claims.AuthMethod)
|
||||
assert.Equal(t, auth.MethodGitHubAT, claims.AuthMethod)
|
||||
assert.Equal(t, "testuser", claims.AuthMethodSubject)
|
||||
assert.Len(t, claims.Permissions, 1)
|
||||
assert.Equal(t, auth.PermissionActionPublish, claims.Permissions[0].Action)
|
||||
|
|
@ -333,7 +332,7 @@ func TestJWTTokenValidation(t *testing.T) {
|
|||
t.Run("generate and validate token", func(t *testing.T) {
|
||||
// Create test claims
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "testuser",
|
||||
Permissions: []auth.Permission{
|
||||
{
|
||||
|
|
@ -351,7 +350,7 @@ func TestJWTTokenValidation(t *testing.T) {
|
|||
// Validate token
|
||||
validatedClaims, err := jwtManager.ValidateToken(ctx, tokenResponse.RegistryToken)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, model.AuthMethodGitHubAT, validatedClaims.AuthMethod)
|
||||
assert.Equal(t, auth.MethodGitHubAT, validatedClaims.AuthMethod)
|
||||
assert.Equal(t, "testuser", validatedClaims.AuthMethodSubject)
|
||||
assert.Len(t, validatedClaims.Permissions, 1)
|
||||
})
|
||||
|
|
@ -360,7 +359,7 @@ func TestJWTTokenValidation(t *testing.T) {
|
|||
// Create claims with past expiration
|
||||
pastTime := time.Now().Add(-1 * time.Hour)
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "testuser",
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(pastTime),
|
||||
|
|
@ -381,7 +380,7 @@ func TestJWTTokenValidation(t *testing.T) {
|
|||
t.Run("invalid signature", func(t *testing.T) {
|
||||
// Create test claims
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "testuser",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// GitHubOIDCTokenExchangeInput represents the input for GitHub OIDC token exchange
|
||||
|
|
@ -263,7 +262,7 @@ func (h *GitHubOIDCHandler) ExchangeToken(ctx context.Context, oidcToken string)
|
|||
|
||||
// Create JWT claims with GitHub OIDC info
|
||||
jwtClaims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubOIDC,
|
||||
AuthMethod: auth.MethodGitHubOIDC,
|
||||
AuthMethodSubject: claims.Subject, // e.g. "repo:octo-org/octo-repo:environment:prod"
|
||||
Permissions: permissions,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
|
||||
internalauth "github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -106,7 +105,7 @@ func TestGitHubOIDCHandler_ExchangeToken(t *testing.T) {
|
|||
claims, err := jwtManager.ValidateToken(context.Background(), response.RegistryToken)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, model.AuthMethodGitHubOIDC, claims.AuthMethod)
|
||||
assert.Equal(t, internalauth.MethodGitHubOIDC, claims.AuthMethod)
|
||||
assert.Equal(t, tt.expectedSubject, claims.AuthMethodSubject)
|
||||
assert.Len(t, claims.Permissions, tt.expectedPerms)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// HTTPTokenExchangeInput represents the input for HTTP-based authentication
|
||||
|
|
@ -182,7 +181,7 @@ func (h *HTTPAuthHandler) ExchangeToken(ctx context.Context, domain, timestamp,
|
|||
|
||||
// Create JWT claims
|
||||
jwtClaims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodHTTP,
|
||||
AuthMethod: auth.MethodHTTP,
|
||||
AuthMethodSubject: domain,
|
||||
Permissions: permissions,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import (
|
|||
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
|
||||
intauth "github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// MockHTTPKeyFetcher for testing
|
||||
|
|
@ -210,7 +209,7 @@ func TestHTTPAuthHandler_ExchangeToken(t *testing.T) {
|
|||
claims, err := jwtManager.ValidateToken(context.Background(), result.RegistryToken)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, model.AuthMethodHTTP, claims.AuthMethod)
|
||||
assert.Equal(t, intauth.MethodHTTP, claims.AuthMethod)
|
||||
assert.Equal(t, tt.domain, claims.AuthMethodSubject)
|
||||
assert.Len(t, claims.Permissions, 1) // domain permissions only
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
)
|
||||
|
||||
// NoneHandler handles anonymous authentication
|
||||
|
|
@ -66,7 +65,7 @@ func (h *NoneHandler) GetAnonymousToken(ctx context.Context) (*auth.TokenRespons
|
|||
|
||||
// Create JWT claims for anonymous user
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodNone,
|
||||
AuthMethod: auth.MethodNone,
|
||||
AuthMethodSubject: "anonymous",
|
||||
Permissions: permissions,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
v0auth "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -41,7 +40,7 @@ func TestNoneHandler_GetAnonymousToken(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// Check auth method
|
||||
assert.Equal(t, model.AuthMethodNone, claims.AuthMethod)
|
||||
assert.Equal(t, auth.MethodNone, claims.AuthMethod)
|
||||
assert.Equal(t, "anonymous", claims.AuthMethodSubject)
|
||||
|
||||
// Check permissions
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
|
@ -301,7 +300,7 @@ func (h *OIDCHandler) ExchangeToken(ctx context.Context, oidcToken string) (*aut
|
|||
|
||||
// Create JWT claims
|
||||
jwtClaims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodOIDC,
|
||||
AuthMethod: auth.MethodOIDC,
|
||||
AuthMethodSubject: claims.Subject,
|
||||
Permissions: permissions,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ import (
|
|||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/database"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/modelcontextprotocol/registry/internal/service"
|
||||
"github.com/modelcontextprotocol/registry/internal/validators"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
)
|
||||
|
||||
// EditServerInput represents the input for editing a server
|
||||
|
|
@ -38,7 +39,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
Security: []map[string][]string{
|
||||
{"bearer": {}},
|
||||
},
|
||||
}, func(ctx context.Context, input *EditServerInput) (*Response[model.ServerResponse], error) {
|
||||
}, func(ctx context.Context, input *EditServerInput) (*Response[apiv1.ServerRecord], error) {
|
||||
// Extract bearer token
|
||||
const bearerPrefix = "Bearer "
|
||||
authHeader := input.Authorization
|
||||
|
|
@ -54,7 +55,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
}
|
||||
|
||||
// Validate that only allowed extension fields are present
|
||||
if err := model.ValidatePublishRequestExtensions(input.RawBody); err != nil {
|
||||
if err := validators.ValidatePublishRequestExtensions(input.RawBody); err != nil {
|
||||
return nil, huma.Error400BadRequest("Invalid request format", err)
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
}
|
||||
|
||||
// Parse the validated request body
|
||||
var editRequest model.PublishRequest
|
||||
var editRequest apiv1.PublishRequest
|
||||
if err := json.Unmarshal(input.RawBody, &editRequest); err != nil {
|
||||
return nil, huma.Error400BadRequest("Invalid JSON format", err)
|
||||
}
|
||||
|
|
@ -90,7 +91,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
}
|
||||
|
||||
// Prevent undeleting servers - once deleted, they stay deleted
|
||||
if currentServer.Server.Status == model.ServerStatusDeleted && editRequest.Server.Status != model.ServerStatusDeleted {
|
||||
if currentServer.Server.Status == model.StatusDeleted && editRequest.Server.Status != model.StatusDeleted {
|
||||
return nil, huma.Error400BadRequest("Cannot change status of deleted server. Deleted servers cannot be undeleted.")
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
return nil, huma.Error400BadRequest("Failed to edit server", err)
|
||||
}
|
||||
|
||||
return &Response[model.ServerResponse]{
|
||||
return &Response[apiv1.ServerRecord]{
|
||||
Body: *updatedServer,
|
||||
}, nil
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ import (
|
|||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/database"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
)
|
||||
|
||||
func TestEditServerEndpoint(t *testing.T) {
|
||||
|
|
@ -36,7 +37,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionEdit, ResourcePattern: "io.github.domdomegg/*"},
|
||||
|
|
@ -44,11 +45,11 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
})
|
||||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
Status: model.ServerStatusDeprecated,
|
||||
Status: model.StatusDeprecated,
|
||||
Repository: model.Repository{
|
||||
URL: "https://github.com/domdomegg/test-server",
|
||||
Source: "github",
|
||||
|
|
@ -61,23 +62,23 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
// Current server (not deleted)
|
||||
currentServer := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
currentServer := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Original server",
|
||||
Status: model.ServerStatusActive,
|
||||
Status: model.StatusActive,
|
||||
},
|
||||
}
|
||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||
|
||||
expectedResponse := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
|
||||
expectedResponse := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
Status: model.ServerStatusDeprecated,
|
||||
Status: model.StatusDeprecated,
|
||||
},
|
||||
}
|
||||
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("model.PublishRequest")).Return(expectedResponse, nil)
|
||||
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("v1.PublishRequest")).Return(expectedResponse, nil)
|
||||
},
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
|
|
@ -85,7 +86,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
name: "missing authorization header",
|
||||
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
||||
authHeader: "",
|
||||
requestBody: model.PublishRequest{},
|
||||
requestBody: apiv1.PublishRequest{},
|
||||
setupMocks: func(_ *MockRegistryService) {},
|
||||
expectedStatus: 422,
|
||||
expectedError: "required header parameter is missing",
|
||||
|
|
@ -94,7 +95,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
name: "invalid authorization header format",
|
||||
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
||||
authHeader: "InvalidFormat token123",
|
||||
requestBody: model.PublishRequest{},
|
||||
requestBody: apiv1.PublishRequest{},
|
||||
setupMocks: func(_ *MockRegistryService) {},
|
||||
expectedStatus: http.StatusUnauthorized,
|
||||
expectedError: "Unauthorized",
|
||||
|
|
@ -103,7 +104,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
name: "invalid token",
|
||||
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
||||
authHeader: "Bearer invalid-token",
|
||||
requestBody: model.PublishRequest{},
|
||||
requestBody: apiv1.PublishRequest{},
|
||||
setupMocks: func(_ *MockRegistryService) {},
|
||||
expectedStatus: http.StatusUnauthorized,
|
||||
expectedError: "Unauthorized",
|
||||
|
|
@ -114,7 +115,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "io.github.domdomegg/*"},
|
||||
|
|
@ -122,19 +123,19 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
})
|
||||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
},
|
||||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
// Need to mock GetByID since we check permissions against existing server name
|
||||
currentServer := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
currentServer := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Original server",
|
||||
Status: model.ServerStatusActive,
|
||||
Status: model.StatusActive,
|
||||
},
|
||||
}
|
||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||
|
|
@ -148,7 +149,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionEdit, ResourcePattern: "io.github.domdomegg/*"},
|
||||
|
|
@ -156,8 +157,8 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
})
|
||||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.other/test-server",
|
||||
Description: "Updated test server",
|
||||
},
|
||||
|
|
@ -165,11 +166,11 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
setupMocks: func(registry *MockRegistryService) {
|
||||
// Need to mock GetByID since we check permissions against existing server name
|
||||
// This test case shows a different scenario: existing server is "other" but user only has perms for "domdomegg"
|
||||
currentServer := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
currentServer := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.other/test-server",
|
||||
Description: "Original server",
|
||||
Status: model.ServerStatusActive,
|
||||
Status: model.StatusActive,
|
||||
},
|
||||
}
|
||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||
|
|
@ -183,7 +184,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionEdit, ResourcePattern: "io.github.domdomegg/*"},
|
||||
|
|
@ -191,8 +192,8 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
})
|
||||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
},
|
||||
|
|
@ -209,7 +210,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionEdit, ResourcePattern: "*"},
|
||||
|
|
@ -217,23 +218,23 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
})
|
||||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
},
|
||||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
// Current server (not deleted)
|
||||
currentServer := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
currentServer := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Original server",
|
||||
Status: model.ServerStatusActive,
|
||||
Status: model.StatusActive,
|
||||
},
|
||||
}
|
||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("model.PublishRequest")).Return(nil, errors.New("database error"))
|
||||
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("v1.PublishRequest")).Return(nil, errors.New("database error"))
|
||||
},
|
||||
expectedStatus: http.StatusBadRequest,
|
||||
expectedError: "Bad Request",
|
||||
|
|
@ -244,7 +245,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionEdit, ResourcePattern: "*"},
|
||||
|
|
@ -263,7 +264,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: func() string {
|
||||
cfg := &config.Config{JWTPrivateKey: "bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb825b23f7ef47c"}
|
||||
token, _ := generateTestJWTToken(cfg, auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "domdomegg",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionEdit, ResourcePattern: "*"},
|
||||
|
|
@ -271,20 +272,20 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
})
|
||||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Trying to undelete server",
|
||||
Status: model.ServerStatusActive,
|
||||
Status: model.StatusActive,
|
||||
},
|
||||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
// Current server is deleted
|
||||
currentServer := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
currentServer := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Original server",
|
||||
Status: model.ServerStatusDeleted,
|
||||
Status: model.StatusDeleted,
|
||||
},
|
||||
}
|
||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||
|
|
@ -345,4 +346,4 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
mockRegistry.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import (
|
|||
"github.com/danielgtaylor/huma/v2"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/modelcontextprotocol/registry/internal/service"
|
||||
"github.com/modelcontextprotocol/registry/internal/validators"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
)
|
||||
|
||||
// PublishServerInput represents the input for publishing a server
|
||||
|
|
@ -35,7 +35,7 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
|||
Security: []map[string][]string{
|
||||
{"bearer": {}},
|
||||
},
|
||||
}, func(ctx context.Context, input *PublishServerInput) (*Response[model.ServerResponse], error) {
|
||||
}, func(ctx context.Context, input *PublishServerInput) (*Response[apiv1.ServerRecord], error) {
|
||||
// Extract bearer token
|
||||
const bearerPrefix = "Bearer "
|
||||
authHeader := input.Authorization
|
||||
|
|
@ -51,12 +51,12 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
|||
}
|
||||
|
||||
// Validate that only allowed extension fields are present
|
||||
if err := model.ValidatePublishRequestExtensions(input.RawBody); err != nil {
|
||||
if err := validators.ValidatePublishRequestExtensions(input.RawBody); err != nil {
|
||||
return nil, huma.Error400BadRequest("Invalid request format", err)
|
||||
}
|
||||
|
||||
// Parse the validated request body
|
||||
var publishRequest model.PublishRequest
|
||||
var publishRequest apiv1.PublishRequest
|
||||
if err := json.Unmarshal(input.RawBody, &publishRequest); err != nil {
|
||||
return nil, huma.Error400BadRequest("Invalid JSON format", err)
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
|||
}
|
||||
|
||||
// Return the published server in extension wrapper format
|
||||
return &Response[model.ServerResponse]{
|
||||
return &Response[apiv1.ServerRecord]{
|
||||
Body: *publishedServer,
|
||||
}, nil
|
||||
})
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/modelcontextprotocol/registry/internal/service"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
|
@ -53,8 +54,8 @@ func TestPublishIntegration(t *testing.T) {
|
|||
v0.RegisterPublishEndpoint(api, registryService, testConfig)
|
||||
|
||||
t.Run("successful publish with GitHub auth", func(t *testing.T) {
|
||||
publishReq := model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
publishReq := apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.testuser/test-mcp-server",
|
||||
Description: "A test MCP server for integration testing",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -70,7 +71,7 @@ func TestPublishIntegration(t *testing.T) {
|
|||
|
||||
// Generate valid JWT token
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "testuser",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "io.github.testuser/*"},
|
||||
|
|
@ -91,7 +92,7 @@ func TestPublishIntegration(t *testing.T) {
|
|||
|
||||
assert.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var response model.ServerResponse
|
||||
var response apiv1.ServerRecord
|
||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -100,8 +101,8 @@ func TestPublishIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("successful publish with none auth (no prefix)", func(t *testing.T) {
|
||||
publishReq := model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
publishReq := apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "com.example/test-mcp-server-no-auth",
|
||||
Description: "A test MCP server without authentication",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -117,7 +118,7 @@ func TestPublishIntegration(t *testing.T) {
|
|||
|
||||
// Generate valid JWT token with wildcard permission
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodNone,
|
||||
AuthMethod: auth.MethodNone,
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "*"},
|
||||
},
|
||||
|
|
@ -137,7 +138,7 @@ func TestPublishIntegration(t *testing.T) {
|
|||
|
||||
assert.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var response model.ServerResponse
|
||||
var response apiv1.ServerRecord
|
||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -145,8 +146,8 @@ func TestPublishIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("publish fails with missing authorization header", func(t *testing.T) {
|
||||
publishReq := model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
publishReq := apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server",
|
||||
},
|
||||
}
|
||||
|
|
@ -166,8 +167,8 @@ func TestPublishIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("publish fails with invalid token", func(t *testing.T) {
|
||||
publishReq := model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
publishReq := apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server",
|
||||
},
|
||||
}
|
||||
|
|
@ -187,8 +188,8 @@ func TestPublishIntegration(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("publish fails when permission denied", func(t *testing.T) {
|
||||
publishReq := model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
publishReq := apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.other/test-server",
|
||||
Description: "A test server",
|
||||
VersionDetail: model.VersionDetail{
|
||||
|
|
@ -204,7 +205,7 @@ func TestPublishIntegration(t *testing.T) {
|
|||
|
||||
// Generate valid JWT token but with different permissions
|
||||
claims := auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "io.github.myuser/*"},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/auth"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -28,33 +29,33 @@ type MockRegistryService struct {
|
|||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *MockRegistryService) List(cursor string, limit int) ([]model.ServerResponse, string, error) {
|
||||
func (m *MockRegistryService) List(cursor string, limit int) ([]apiv1.ServerRecord, string, error) {
|
||||
args := m.Called(cursor, limit)
|
||||
return args.Get(0).([]model.ServerResponse), args.String(1), args.Error(2)
|
||||
return args.Get(0).([]apiv1.ServerRecord), args.String(1), args.Error(2)
|
||||
}
|
||||
|
||||
func (m *MockRegistryService) GetByID(id string) (*model.ServerResponse, error) {
|
||||
func (m *MockRegistryService) GetByID(id string) (*apiv1.ServerRecord, error) {
|
||||
args := m.Called(id)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
return args.Get(0).(*model.ServerResponse), args.Error(1)
|
||||
return args.Get(0).(*apiv1.ServerRecord), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockRegistryService) Publish(request model.PublishRequest) (*model.ServerResponse, error) {
|
||||
func (m *MockRegistryService) Publish(request apiv1.PublishRequest) (*apiv1.ServerRecord, error) {
|
||||
args := m.Called(request)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
return args.Get(0).(*model.ServerResponse), args.Error(1)
|
||||
return args.Get(0).(*apiv1.ServerRecord), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockRegistryService) EditServer(id string, request model.PublishRequest) (*model.ServerResponse, error) {
|
||||
func (m *MockRegistryService) EditServer(id string, request apiv1.PublishRequest) (*apiv1.ServerRecord, error) {
|
||||
args := m.Called(id, request)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
return args.Get(0).(*model.ServerResponse), args.Error(1)
|
||||
return args.Get(0).(*apiv1.ServerRecord), args.Error(1)
|
||||
}
|
||||
|
||||
// Helper function to generate a valid JWT token for testing
|
||||
|
|
@ -87,8 +88,8 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
name: "successful publish with GitHub auth",
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.example/test-server",
|
||||
Description: "A test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -102,21 +103,21 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
},
|
||||
tokenClaims: &auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
AuthMethodSubject: "example",
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "io.github.example/*"},
|
||||
},
|
||||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
registry.On("Publish", mock.AnythingOfType("model.PublishRequest")).Return(&model.ServerResponse{}, nil)
|
||||
registry.On("Publish", mock.AnythingOfType("v1.PublishRequest")).Return(&apiv1.ServerRecord{}, nil)
|
||||
},
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "successful publish with no auth (AuthMethodNone)",
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "example/test-server",
|
||||
Description: "A test server without auth",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -130,19 +131,19 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
},
|
||||
tokenClaims: &auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodNone,
|
||||
AuthMethod: auth.MethodNone,
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "example/*"},
|
||||
},
|
||||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
registry.On("Publish", mock.AnythingOfType("model.PublishRequest")).Return(&model.ServerResponse{}, nil)
|
||||
registry.On("Publish", mock.AnythingOfType("v1.PublishRequest")).Return(&apiv1.ServerRecord{}, nil)
|
||||
},
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "missing authorization header",
|
||||
requestBody: model.PublishRequest{},
|
||||
requestBody: apiv1.PublishRequest{},
|
||||
authHeader: "", // Empty auth header
|
||||
setupMocks: func(_ *MockRegistryService) {},
|
||||
expectedStatus: http.StatusUnprocessableEntity,
|
||||
|
|
@ -150,7 +151,7 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "invalid authorization header format",
|
||||
requestBody: model.PublishRequest{},
|
||||
requestBody: apiv1.PublishRequest{},
|
||||
authHeader: "InvalidFormat",
|
||||
setupMocks: func(_ *MockRegistryService) {},
|
||||
expectedStatus: http.StatusUnauthorized,
|
||||
|
|
@ -158,8 +159,8 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "invalid token",
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server",
|
||||
Description: "A test server",
|
||||
VersionDetail: model.VersionDetail{
|
||||
|
|
@ -174,8 +175,8 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "permission denied",
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "io.github.other/test-server",
|
||||
Description: "A test server",
|
||||
VersionDetail: model.VersionDetail{
|
||||
|
|
@ -189,7 +190,7 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
},
|
||||
tokenClaims: &auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodGitHubAT,
|
||||
AuthMethod: auth.MethodGitHubAT,
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "io.github.example/*"},
|
||||
},
|
||||
|
|
@ -200,8 +201,8 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "registry service error",
|
||||
requestBody: model.PublishRequest{
|
||||
Server: model.ServerDetail{
|
||||
requestBody: apiv1.PublishRequest{
|
||||
Server: model.ServerJSON{
|
||||
Name: "example/test-server",
|
||||
Description: "A test server",
|
||||
VersionDetail: model.VersionDetail{
|
||||
|
|
@ -215,13 +216,13 @@ func TestPublishEndpoint(t *testing.T) {
|
|||
},
|
||||
},
|
||||
tokenClaims: &auth.JWTClaims{
|
||||
AuthMethod: model.AuthMethodNone,
|
||||
AuthMethod: auth.MethodNone,
|
||||
Permissions: []auth.Permission{
|
||||
{Action: auth.PermissionActionPublish, ResourcePattern: "*"},
|
||||
},
|
||||
},
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
registry.On("Publish", mock.AnythingOfType("model.PublishRequest")).Return(nil, errors.New("cannot publish duplicate version"))
|
||||
registry.On("Publish", mock.AnythingOfType("v1.PublishRequest")).Return(nil, errors.New("cannot publish duplicate version"))
|
||||
},
|
||||
expectedStatus: http.StatusBadRequest,
|
||||
expectedError: "Failed to publish server",
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
"github.com/danielgtaylor/huma/v2"
|
||||
"github.com/google/uuid"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/modelcontextprotocol/registry/internal/service"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
)
|
||||
|
||||
// Metadata contains pagination metadata
|
||||
|
|
@ -25,8 +25,8 @@ type ListServersInput struct {
|
|||
|
||||
// ListServersBody represents the paginated server list response body
|
||||
type ListServersBody struct {
|
||||
Servers []model.ServerResponse `json:"servers" doc:"List of MCP servers with extensions"`
|
||||
Metadata *Metadata `json:"metadata,omitempty" doc:"Pagination metadata"`
|
||||
Servers []apiv1.ServerRecord `json:"servers" doc:"List of MCP servers with extensions"`
|
||||
Metadata *Metadata `json:"metadata,omitempty" doc:"Pagination metadata"`
|
||||
}
|
||||
|
||||
// ServerDetailInput represents the input for getting server details
|
||||
|
|
@ -85,7 +85,7 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
|
|||
Summary: "Get MCP server details",
|
||||
Description: "Get detailed information about a specific MCP server",
|
||||
Tags: []string{"servers"},
|
||||
}, func(_ context.Context, input *ServerDetailInput) (*Response[model.ServerResponse], error) {
|
||||
}, func(_ context.Context, input *ServerDetailInput) (*Response[apiv1.ServerRecord], error) {
|
||||
// Get the server details from the registry service
|
||||
serverDetail, err := registry.GetByID(input.ID)
|
||||
if err != nil {
|
||||
|
|
@ -95,7 +95,7 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
|
|||
return nil, huma.Error500InternalServerError("Failed to get server details", err)
|
||||
}
|
||||
|
||||
return &Response[model.ServerResponse]{
|
||||
return &Response[apiv1.ServerRecord]{
|
||||
Body: *serverDetail,
|
||||
}, nil
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ import (
|
|||
"github.com/danielgtaylor/huma/v2/adapters/humago"
|
||||
"github.com/google/uuid"
|
||||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
|
@ -23,16 +24,16 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
queryParams string
|
||||
setupMocks func(*MockRegistryService)
|
||||
expectedStatus int
|
||||
expectedServers []model.ServerResponse
|
||||
expectedServers []apiv1.ServerRecord
|
||||
expectedMeta *v0.Metadata
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "successful list with default parameters",
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
servers := []model.ServerResponse{
|
||||
servers := []apiv1.ServerRecord{
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-1",
|
||||
Description: "First test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -44,12 +45,12 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
Version: "1.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440001",
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: "550e8400-e29b-41d4-a716-446655440001",
|
||||
},
|
||||
},
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-2",
|
||||
Description: "Second test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -61,17 +62,17 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
Version: "2.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440002",
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: "550e8400-e29b-41d4-a716-446655440002",
|
||||
},
|
||||
},
|
||||
}
|
||||
registry.Mock.On("List", "", 30).Return(servers, "", nil)
|
||||
},
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedServers: []model.ServerResponse{
|
||||
expectedServers: []apiv1.ServerRecord{
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-1",
|
||||
Description: "First test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -83,12 +84,12 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
Version: "1.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440001",
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: "550e8400-e29b-41d4-a716-446655440001",
|
||||
},
|
||||
},
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-2",
|
||||
Description: "Second test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -100,8 +101,8 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
Version: "2.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440002",
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: "550e8400-e29b-41d4-a716-446655440002",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -110,9 +111,9 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
name: "successful list with cursor and limit",
|
||||
queryParams: "?cursor=550e8400-e29b-41d4-a716-446655440000&limit=10",
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
servers := []model.ServerResponse{
|
||||
servers := []apiv1.ServerRecord{
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-3",
|
||||
Description: "Third test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -124,8 +125,8 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
Version: "1.5.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440003",
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: "550e8400-e29b-41d4-a716-446655440003",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -133,9 +134,9 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
registry.Mock.On("List", mock.AnythingOfType("string"), 10).Return(servers, nextCursor, nil)
|
||||
},
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedServers: []model.ServerResponse{
|
||||
expectedServers: []apiv1.ServerRecord{
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-3",
|
||||
Description: "Third test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -147,8 +148,8 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
Version: "1.5.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": "550e8400-e29b-41d4-a716-446655440003",
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: "550e8400-e29b-41d4-a716-446655440003",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -195,7 +196,7 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
{
|
||||
name: "registry service error",
|
||||
setupMocks: func(registry *MockRegistryService) {
|
||||
registry.Mock.On("List", "", 30).Return([]model.ServerResponse{}, "", errors.New("database connection error"))
|
||||
registry.Mock.On("List", "", 30).Return([]apiv1.ServerRecord{}, "", errors.New("database connection error"))
|
||||
},
|
||||
expectedStatus: http.StatusInternalServerError,
|
||||
expectedError: "Failed to get registry list",
|
||||
|
|
@ -232,8 +233,8 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
|
||||
// Parse response body
|
||||
var resp struct {
|
||||
Servers []model.ServerResponse `json:"servers"`
|
||||
Metadata *v0.Metadata `json:"metadata,omitempty"`
|
||||
Servers []apiv1.ServerRecord `json:"servers"`
|
||||
Metadata *v0.Metadata `json:"metadata,omitempty"`
|
||||
}
|
||||
err := json.NewDecoder(w.Body).Decode(&resp)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -267,15 +268,15 @@ func TestServersDetailEndpoint(t *testing.T) {
|
|||
serverID string
|
||||
setupMocks func(*MockRegistryService, string)
|
||||
expectedStatus int
|
||||
expectedServer *model.ServerResponse
|
||||
expectedServer *apiv1.ServerRecord
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "successful get server detail",
|
||||
serverID: uuid.New().String(),
|
||||
setupMocks: func(registry *MockRegistryService, serverID string) {
|
||||
serverDetail := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
serverDetail := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-detail",
|
||||
Description: "Test server detail",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -287,8 +288,8 @@ func TestServersDetailEndpoint(t *testing.T) {
|
|||
Version: "2.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": serverID,
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: serverID,
|
||||
},
|
||||
}
|
||||
registry.Mock.On("GetByID", serverID).Return(serverDetail, nil)
|
||||
|
|
@ -351,7 +352,7 @@ func TestServersDetailEndpoint(t *testing.T) {
|
|||
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
|
||||
|
||||
// Parse response body
|
||||
var serverDetailResp model.ServerResponse
|
||||
var serverDetailResp apiv1.ServerRecord
|
||||
err := json.NewDecoder(w.Body).Decode(&serverDetailResp)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -375,9 +376,9 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
|||
|
||||
// Test data
|
||||
serverID := uuid.New().String()
|
||||
servers := []model.ServerResponse{
|
||||
servers := []apiv1.ServerRecord{
|
||||
{
|
||||
Server: model.ServerDetail{
|
||||
Server: model.ServerJSON{
|
||||
Name: "integration-test-server",
|
||||
Description: "Integration test server",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -389,14 +390,14 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
|||
Version: "1.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": serverID,
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: serverID,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
serverDetail := &model.ServerResponse{
|
||||
Server: servers[0].Server,
|
||||
serverDetail := &apiv1.ServerRecord{
|
||||
Server: servers[0].Server,
|
||||
XIOModelContextProtocolRegistry: servers[0].XIOModelContextProtocolRegistry,
|
||||
}
|
||||
|
||||
|
|
@ -438,7 +439,7 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
|||
|
||||
// Parse response body
|
||||
var listResp struct {
|
||||
Servers []model.ServerResponse `json:"servers"`
|
||||
Servers []apiv1.ServerRecord `json:"servers"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&listResp)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -469,7 +470,7 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
|||
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
|
||||
|
||||
// Parse response body
|
||||
var serverDetailResp model.ServerResponse
|
||||
var serverDetailResp apiv1.ServerRecord
|
||||
err = json.NewDecoder(resp.Body).Decode(&serverDetailResp)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
@ -479,4 +480,4 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
|||
|
||||
// Verify mock expectations
|
||||
mockRegistry.AssertExpectations(t)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@ import (
|
|||
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
|
||||
"github.com/modelcontextprotocol/registry/internal/api/router"
|
||||
"github.com/modelcontextprotocol/registry/internal/config"
|
||||
"github.com/modelcontextprotocol/registry/internal/model"
|
||||
"github.com/modelcontextprotocol/registry/internal/telemetry"
|
||||
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
)
|
||||
|
||||
func mockServerEndpoint(registry *MockRegistryService, serverID string) {
|
||||
serverDetail := &model.ServerResponse{
|
||||
Server: model.ServerDetail{
|
||||
serverDetail := &apiv1.ServerRecord{
|
||||
Server: model.ServerJSON{
|
||||
Name: "test-server-detail",
|
||||
Description: "Test server detail",
|
||||
Repository: model.Repository{
|
||||
|
|
@ -32,8 +33,8 @@ func mockServerEndpoint(registry *MockRegistryService, serverID string) {
|
|||
Version: "2.0.0",
|
||||
},
|
||||
},
|
||||
XIOModelContextProtocolRegistry: map[string]interface{}{
|
||||
"id": serverID,
|
||||
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
|
||||
ID: serverID,
|
||||
},
|
||||
}
|
||||
registry.Mock.On("GetByID", serverID).Return(serverDetail, nil)
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue