Skip to content

Commit 099a2d7

Browse files
authored
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 <[email protected]>
1 parent 9d04671 commit 099a2d7

39 files changed

+1280
-1408
lines changed

cmd/registry/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/modelcontextprotocol/registry/internal/api"
1515
"github.com/modelcontextprotocol/registry/internal/config"
1616
"github.com/modelcontextprotocol/registry/internal/database"
17-
"github.com/modelcontextprotocol/registry/internal/model"
1817
"github.com/modelcontextprotocol/registry/internal/service"
1918
"github.com/modelcontextprotocol/registry/internal/telemetry"
19+
"github.com/modelcontextprotocol/registry/pkg/model"
2020
)
2121

2222
func main() {
@@ -46,7 +46,7 @@ func main() {
4646
// Initialize services based on environment
4747
switch cfg.DatabaseType {
4848
case config.DatabaseTypeMemory:
49-
db = database.NewMemoryDB(map[string]*model.ServerDetail{})
49+
db = database.NewMemoryDB(map[string]*model.ServerJSON{})
5050
registryService = service.NewRegistryServiceWithDB(db)
5151
case config.DatabaseTypePostgreSQL:
5252
// Use PostgreSQL for real registry service

internal/api/handlers/v0/auth/dns.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
1717
"github.com/modelcontextprotocol/registry/internal/auth"
1818
"github.com/modelcontextprotocol/registry/internal/config"
19-
"github.com/modelcontextprotocol/registry/internal/model"
2019
)
2120

2221
// DNSTokenExchangeInput represents the input for DNS-based authentication
@@ -147,7 +146,7 @@ func (h *DNSAuthHandler) ExchangeToken(ctx context.Context, domain, timestamp, s
147146

148147
// Create JWT claims
149148
jwtClaims := auth.JWTClaims{
150-
AuthMethod: model.AuthMethodDNS,
149+
AuthMethod: auth.MethodDNS,
151150
AuthMethodSubject: domain,
152151
Permissions: permissions,
153152
}

internal/api/handlers/v0/auth/dns_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
1717
intauth "github.com/modelcontextprotocol/registry/internal/auth"
1818
"github.com/modelcontextprotocol/registry/internal/config"
19-
"github.com/modelcontextprotocol/registry/internal/model"
2019
)
2120

2221
// MockDNSResolver for testing
@@ -174,7 +173,7 @@ func TestDNSAuthHandler_ExchangeToken(t *testing.T) {
174173
claims, err := jwtManager.ValidateToken(context.Background(), result.RegistryToken)
175174
require.NoError(t, err)
176175

177-
assert.Equal(t, model.AuthMethodDNS, claims.AuthMethod)
176+
assert.Equal(t, intauth.MethodDNS, claims.AuthMethod)
178177
assert.Equal(t, tt.domain, claims.AuthMethodSubject)
179178
assert.Len(t, claims.Permissions, 2) // domain and subdomain permissions
180179

internal/api/handlers/v0/auth/github_at.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
1313
"github.com/modelcontextprotocol/registry/internal/auth"
1414
"github.com/modelcontextprotocol/registry/internal/config"
15-
"github.com/modelcontextprotocol/registry/internal/model"
1615
)
1716

1817
// GitHubTokenExchangeInput represents the input for GitHub token exchange
@@ -86,7 +85,7 @@ func (h *GitHubHandler) ExchangeToken(ctx context.Context, githubToken string) (
8685

8786
// Create JWT claims with GitHub user info
8887
claims := auth.JWTClaims{
89-
AuthMethod: model.AuthMethodGitHubAT,
88+
AuthMethod: auth.MethodGitHubAT,
9089
AuthMethodSubject: user.Login,
9190
Permissions: permissions,
9291
}

internal/api/handlers/v0/auth/github_at_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
v0auth "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
1717
"github.com/modelcontextprotocol/registry/internal/auth"
1818
"github.com/modelcontextprotocol/registry/internal/config"
19-
"github.com/modelcontextprotocol/registry/internal/model"
2019
"github.com/stretchr/testify/assert"
2120
"github.com/stretchr/testify/require"
2221
)
@@ -78,7 +77,7 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) {
7877
jwtManager := auth.NewJWTManager(cfg)
7978
claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken)
8079
require.NoError(t, err)
81-
assert.Equal(t, model.AuthMethodGitHubAT, claims.AuthMethod)
80+
assert.Equal(t, auth.MethodGitHubAT, claims.AuthMethod)
8281
assert.Equal(t, "testuser", claims.AuthMethodSubject)
8382
assert.Len(t, claims.Permissions, 1)
8483
assert.Equal(t, auth.PermissionActionPublish, claims.Permissions[0].Action)
@@ -333,7 +332,7 @@ func TestJWTTokenValidation(t *testing.T) {
333332
t.Run("generate and validate token", func(t *testing.T) {
334333
// Create test claims
335334
claims := auth.JWTClaims{
336-
AuthMethod: model.AuthMethodGitHubAT,
335+
AuthMethod: auth.MethodGitHubAT,
337336
AuthMethodSubject: "testuser",
338337
Permissions: []auth.Permission{
339338
{
@@ -351,7 +350,7 @@ func TestJWTTokenValidation(t *testing.T) {
351350
// Validate token
352351
validatedClaims, err := jwtManager.ValidateToken(ctx, tokenResponse.RegistryToken)
353352
require.NoError(t, err)
354-
assert.Equal(t, model.AuthMethodGitHubAT, validatedClaims.AuthMethod)
353+
assert.Equal(t, auth.MethodGitHubAT, validatedClaims.AuthMethod)
355354
assert.Equal(t, "testuser", validatedClaims.AuthMethodSubject)
356355
assert.Len(t, validatedClaims.Permissions, 1)
357356
})
@@ -360,7 +359,7 @@ func TestJWTTokenValidation(t *testing.T) {
360359
// Create claims with past expiration
361360
pastTime := time.Now().Add(-1 * time.Hour)
362361
claims := auth.JWTClaims{
363-
AuthMethod: model.AuthMethodGitHubAT,
362+
AuthMethod: auth.MethodGitHubAT,
364363
AuthMethodSubject: "testuser",
365364
RegisteredClaims: jwt.RegisteredClaims{
366365
ExpiresAt: jwt.NewNumericDate(pastTime),
@@ -381,7 +380,7 @@ func TestJWTTokenValidation(t *testing.T) {
381380
t.Run("invalid signature", func(t *testing.T) {
382381
// Create test claims
383382
claims := auth.JWTClaims{
384-
AuthMethod: model.AuthMethodGitHubAT,
383+
AuthMethod: auth.MethodGitHubAT,
385384
AuthMethodSubject: "testuser",
386385
}
387386

internal/api/handlers/v0/auth/github_oidc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
1616
"github.com/modelcontextprotocol/registry/internal/auth"
1717
"github.com/modelcontextprotocol/registry/internal/config"
18-
"github.com/modelcontextprotocol/registry/internal/model"
1918
)
2019

2120
// GitHubOIDCTokenExchangeInput represents the input for GitHub OIDC token exchange
@@ -263,7 +262,7 @@ func (h *GitHubOIDCHandler) ExchangeToken(ctx context.Context, oidcToken string)
263262

264263
// Create JWT claims with GitHub OIDC info
265264
jwtClaims := auth.JWTClaims{
266-
AuthMethod: model.AuthMethodGitHubOIDC,
265+
AuthMethod: auth.MethodGitHubOIDC,
267266
AuthMethodSubject: claims.Subject, // e.g. "repo:octo-org/octo-repo:environment:prod"
268267
Permissions: permissions,
269268
}

internal/api/handlers/v0/auth/github_oidc_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
1212
internalauth "github.com/modelcontextprotocol/registry/internal/auth"
1313
"github.com/modelcontextprotocol/registry/internal/config"
14-
"github.com/modelcontextprotocol/registry/internal/model"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716
)
@@ -106,7 +105,7 @@ func TestGitHubOIDCHandler_ExchangeToken(t *testing.T) {
106105
claims, err := jwtManager.ValidateToken(context.Background(), response.RegistryToken)
107106
require.NoError(t, err)
108107

109-
assert.Equal(t, model.AuthMethodGitHubOIDC, claims.AuthMethod)
108+
assert.Equal(t, internalauth.MethodGitHubOIDC, claims.AuthMethod)
110109
assert.Equal(t, tt.expectedSubject, claims.AuthMethodSubject)
111110
assert.Len(t, claims.Permissions, tt.expectedPerms)
112111

internal/api/handlers/v0/auth/http.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
1717
"github.com/modelcontextprotocol/registry/internal/auth"
1818
"github.com/modelcontextprotocol/registry/internal/config"
19-
"github.com/modelcontextprotocol/registry/internal/model"
2019
)
2120

2221
// HTTPTokenExchangeInput represents the input for HTTP-based authentication
@@ -182,7 +181,7 @@ func (h *HTTPAuthHandler) ExchangeToken(ctx context.Context, domain, timestamp,
182181

183182
// Create JWT claims
184183
jwtClaims := auth.JWTClaims{
185-
AuthMethod: model.AuthMethodHTTP,
184+
AuthMethod: auth.MethodHTTP,
186185
AuthMethodSubject: domain,
187186
Permissions: permissions,
188187
}

internal/api/handlers/v0/auth/http_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
1717
intauth "github.com/modelcontextprotocol/registry/internal/auth"
1818
"github.com/modelcontextprotocol/registry/internal/config"
19-
"github.com/modelcontextprotocol/registry/internal/model"
2019
)
2120

2221
// MockHTTPKeyFetcher for testing
@@ -210,7 +209,7 @@ func TestHTTPAuthHandler_ExchangeToken(t *testing.T) {
210209
claims, err := jwtManager.ValidateToken(context.Background(), result.RegistryToken)
211210
require.NoError(t, err)
212211

213-
assert.Equal(t, model.AuthMethodHTTP, claims.AuthMethod)
212+
assert.Equal(t, intauth.MethodHTTP, claims.AuthMethod)
214213
assert.Equal(t, tt.domain, claims.AuthMethodSubject)
215214
assert.Len(t, claims.Permissions, 1) // domain permissions only
216215

internal/api/handlers/v0/auth/none.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0"
1010
"github.com/modelcontextprotocol/registry/internal/auth"
1111
"github.com/modelcontextprotocol/registry/internal/config"
12-
"github.com/modelcontextprotocol/registry/internal/model"
1312
)
1413

1514
// NoneHandler handles anonymous authentication
@@ -66,7 +65,7 @@ func (h *NoneHandler) GetAnonymousToken(ctx context.Context) (*auth.TokenRespons
6665

6766
// Create JWT claims for anonymous user
6867
claims := auth.JWTClaims{
69-
AuthMethod: model.AuthMethodNone,
68+
AuthMethod: auth.MethodNone,
7069
AuthMethodSubject: "anonymous",
7170
Permissions: permissions,
7271
}

0 commit comments

Comments
 (0)