Wielded Claude Code to do this; across many iterations and have reviewed all the code + largely rewritten the PR commentary here. This PR implements the server ID consistency changes from [#396](https://github.com/modelcontextprotocol/registry/issues/396). Our goal is to: - Rename `id` to `versionId` to make it clear that it is the ID for a specific version, not a server - Introduce `serverId` as a net new concept. This will be 1:1 with `name`. While not strictly necessary (we could just use name as a PK), the convention of having a UUID as an ID on our objects is just a helpful subjective architecture decision. Plus also leaves open the door to reconsidering the "should we allow renames" question. ## Key Changes ### 🗄️ Database Schema Changes - **Renamed**: `id` column → `version_id` (unique identifier for each server version) ### 📋 Metadata Structure Updates - **JSON Schema**: Updated `_meta.io.modelcontextprotocol.registry/official` to include: - `serverId`: Consistent ID across all versions of a server - `versionId`: Unique ID for this specific version (renamed from `id`) ### 🔧 API Endpoint Updates - **New endpoint structure**: Changed from version-ID-based to server-ID-based URLs: - `GET /v0/servers/{server_id}` - Get latest version of server - `GET /v0/servers/{server_id}?version=X.X.X` - Get specific version - `GET /v0/servers/{server_id}/versions` - List all versions of a server - `PUT /v0/servers/{server_id}?version=X.X.X` - Edit specific version - **Consistent URL patterns**: All server endpoints now use `server_id` as the primary identifier ### Database Migration Strategy The migration (`005_add_server_id_rename_version_id.sql`): 1. Adds new `version_id` column 2. Generates deterministic UUIDs for servers with the same name 3. Updates JSON metadata to add `serverId` and rename `id` to `versionId` 4. Copies existing `id` values to `version_id` column 5. Drops old `id` column and makes `version_id` the new primary key ## Testing Besides of course automated tests passing, I: 1. Set up my local db with the pre-005-migration state, imported all the production data 2. Ran the migration 3. Spot checked some diffs of the data that resulted -- ```json // before { "name": "io.github.ruvnet/ruv-swarm", "_meta": { "io.modelcontextprotocol.registry/official": { "id": "0a9cda7f-2b73-4839-844b-6582f335de42", "is_latest": false, "updated_at": "2025-09-10T17:21:34.92137012Z", "published_at": "2025-09-10T17:15:32.69690433Z" } }, "version": "1.0.18", "repository": { "url": "", "source": "" }, "description": "Neural network swarm orchestration with WebAssembly acceleration and MCP integration" } // after { "name": "io.github.ruvnet/ruv-swarm", "_meta": { "io.modelcontextprotocol.registry/official": { "serverId": "e8538952-96af-4a33-9e31-7fbed012521e", "is_latest": false, "versionId": "0a9cda7f-2b73-4839-844b-6582f335de42", "updated_at": "2025-09-10T17:21:34.92137012Z", "published_at": "2025-09-10T17:15:32.69690433Z" } }, "version": "1.0.18", "repository": { "url": "", "source": "" }, "description": "Neural network swarm orchestration with WebAssembly acceleration and MCP integration" } ``` Servers that have multiple versions stayed consistent in their `serverId`: ```json // First version { "name": "app.getdialer/dialer", "_meta": { "io.modelcontextprotocol.registry/official": { "serverId": "80f08bdb-f3e4-4f19-b072-1676ae49b663", "is_latest": false, "versionId": "04f25b17-331d-48d7-b08b-37baece208a7", "updated_at": "2025-09-09T00:16:49.162620072Z", "published_at": "2025-09-08T23:47:09.452137971Z" } }, "status": "active", "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", "remotes": [ { "url": "https://getdialer.app/mcp", "type": "streamable-http" }, { "url": "https://getdialer.app/sse", "type": "sse" } ], "version": "1.0.0", "repository": { "url": "", "source": "" }, "description": "An MCP server that provides your you make outbound phone calls using your own phone number" } // Second version { "name": "app.getdialer/dialer", "_meta": { "io.modelcontextprotocol.registry/official": { "serverId": "80f08bdb-f3e4-4f19-b072-1676ae49b663", "is_latest": true, "versionId": "faa26cb9-3aad-415e-aece-f715fff5fe5e", "updated_at": "2025-09-09T00:16:49.107842808Z", "published_at": "2025-09-09T00:16:49.107842808Z" } }, "status": "active", "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", "remotes": [ { "url": "https://getdialer.app/mcp", "type": "streamable-http" }, { "url": "https://getdialer.app/sse", "type": "sse" } ], "version": "1.0.1", "repository": { "url": "", "source": "" }, "description": "An MCP server that provides lets you make outbound phone calls using your own phone number" } ``` And I also tried publishing a test server anew; looked good: ```bash ⏺ Bash(curl -s "http://localhost:8080/v0/servers/102dc4e4-6ca8-40e6-aa11-cd45763d3352" | jq '.') ⎿ { "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", "name": "io.modelcontextprotocol.anonymous/test-claude-migration-server", "description": "A test server to verify the new migration and API endpoints work correctly", "status": "active", "repository": { "url": "https://github.com/example/test-claude-migration-server", "source": "github", "id": "example/test-claude-migration-server" }, "version": "1.0.0", "_meta": { "io.modelcontextprotocol.registry/official": { "serverId": "102dc4e4-6ca8-40e6-aa11-cd45763d3352", "versionId": "48c9cd55-7bc4-4ac2-896e-59e81eb653e4", "published_at": "2025-09-12T18:33:23.264203-07:00", "updated_at": "2025-09-12T18:33:23.264203-07:00", "is_latest": true } } } ⏺ Bash(curl -s "http://localhost:8080/v0/servers/102dc4e4-6ca8-40e6-aa11-cd45763d3352/versions" | jq '.') ⎿ { "servers": [ { "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", "name": "io.modelcontextprotocol.anonymous/test-claude-migration-server", "description": "A test server to verify the new migration and API endpoints work correctly", "status": "active", "repository": { "url": "https://github.com/example/test-claude-migration-server", "source": "github", "id": "example/test-claude-migration-server" }, "version": "1.0.0", "_meta": { "io.modelcontextprotocol.registry/official": { "serverId": "102dc4e4-6ca8-40e6-aa11-cd45763d3352", "versionId": "48c9cd55-7bc4-4ac2-896e-59e81eb653e4", "published_at": "2025-09-12T18:33:23.264203-07:00", "updated_at": "2025-09-12T18:33:23.264203-07:00", "is_latest": true } } } ], "metadata": { "count": 1 } } ``` Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Preeti Dewani <preetidewani1990@gmail.com> Co-authored-by: adam jones <adamj+git@anthropic.com> Co-authored-by: Adam Jones <adamj@anthropic.com>
379 lines
10 KiB
Go
379 lines
10 KiB
Go
//nolint:testpackage
|
|
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/modelcontextprotocol/registry/internal/config"
|
|
"github.com/modelcontextprotocol/registry/internal/database"
|
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
|
"github.com/modelcontextprotocol/registry/pkg/model"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestValidateNoDuplicateRemoteURLs(t *testing.T) {
|
|
// Create test data
|
|
existingServers := map[string]*apiv0.ServerJSON{
|
|
"existing1": {
|
|
Name: "com.example/existing-server",
|
|
Description: "An existing server",
|
|
Version: "1.0.0",
|
|
Remotes: []model.Transport{
|
|
{Type: "streamable-http", URL: "https://api.example.com/mcp"},
|
|
{Type: "sse", URL: "https://webhook.example.com/sse"},
|
|
},
|
|
},
|
|
"existing2": {
|
|
Name: "com.microsoft/another-server",
|
|
Description: "Another existing server",
|
|
Version: "1.0.0",
|
|
Remotes: []model.Transport{
|
|
{Type: "streamable-http", URL: "https://api.microsoft.com/mcp"},
|
|
},
|
|
},
|
|
}
|
|
|
|
memDB := database.NewMemoryDB()
|
|
service := NewRegistryService(memDB, &config.Config{EnableRegistryValidation: false})
|
|
|
|
for _, server := range existingServers {
|
|
_, err := service.Publish(*server)
|
|
if err != nil {
|
|
t.Fatalf("failed to publish server: %v", err)
|
|
}
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
serverDetail apiv0.ServerJSON
|
|
expectError bool
|
|
errorMsg string
|
|
}{
|
|
{
|
|
name: "no remote URLs - should pass",
|
|
serverDetail: apiv0.ServerJSON{
|
|
Name: "com.example/new-server",
|
|
Description: "A new server with no remotes",
|
|
Version: "1.0.0",
|
|
Remotes: []model.Transport{},
|
|
},
|
|
expectError: false,
|
|
},
|
|
{
|
|
name: "new unique remote URLs - should pass",
|
|
serverDetail: apiv0.ServerJSON{
|
|
Name: "com.example/new-server",
|
|
Description: "A new server",
|
|
Version: "1.0.0",
|
|
Remotes: []model.Transport{
|
|
{Type: "streamable-http", URL: "https://new.example.com/mcp"},
|
|
{Type: "sse", URL: "https://unique.example.com/sse"},
|
|
},
|
|
},
|
|
expectError: false,
|
|
},
|
|
{
|
|
name: "duplicate remote URL - should fail",
|
|
serverDetail: apiv0.ServerJSON{
|
|
Name: "com.example/new-server",
|
|
Description: "A new server with duplicate URL",
|
|
Version: "1.0.0",
|
|
Remotes: []model.Transport{
|
|
{Type: "streamable-http", URL: "https://api.example.com/mcp"}, // This URL already exists
|
|
},
|
|
},
|
|
expectError: true,
|
|
errorMsg: "remote URL https://api.example.com/mcp is already used by server com.example/existing-server",
|
|
},
|
|
{
|
|
name: "updating same server with same URLs - should pass",
|
|
serverDetail: apiv0.ServerJSON{
|
|
Name: "com.example/existing-server", // Same name as existing
|
|
Description: "Updated existing server",
|
|
Version: "1.1.0",
|
|
Remotes: []model.Transport{
|
|
{Type: "streamable-http", URL: "https://api.example.com/mcp"}, // Same URL as before
|
|
},
|
|
},
|
|
expectError: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
impl := service.(*registryServiceImpl)
|
|
|
|
err := impl.validateNoDuplicateRemoteURLs(ctx, tt.serverDetail)
|
|
|
|
if tt.expectError {
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), tt.errorMsg)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetByServerID(t *testing.T) {
|
|
memDB := database.NewMemoryDB()
|
|
service := NewRegistryService(memDB, &config.Config{EnableRegistryValidation: false})
|
|
|
|
// Publish multiple versions of the same server
|
|
server1, err := service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/test-server",
|
|
Description: "Test server v1",
|
|
Version: "1.0.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
_, err = service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/test-server",
|
|
Description: "Test server v2",
|
|
Version: "2.0.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
tests := []struct {
|
|
name string
|
|
serverID string
|
|
expectError bool
|
|
errorMsg string
|
|
checkResult func(*testing.T, *apiv0.ServerJSON)
|
|
}{
|
|
{
|
|
name: "get latest version by server ID",
|
|
serverID: server1.Meta.Official.ServerID,
|
|
expectError: false,
|
|
checkResult: func(t *testing.T, result *apiv0.ServerJSON) {
|
|
t.Helper()
|
|
assert.Equal(t, "2.0.0", result.Version) // Should get latest version
|
|
assert.Equal(t, "Test server v2", result.Description)
|
|
assert.True(t, result.Meta.Official.IsLatest)
|
|
},
|
|
},
|
|
{
|
|
name: "server not found",
|
|
serverID: "00000000-0000-0000-0000-000000000000",
|
|
expectError: true,
|
|
errorMsg: "record not found",
|
|
},
|
|
{
|
|
name: "invalid server ID format",
|
|
serverID: "invalid-uuid",
|
|
expectError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := service.GetByServerID(tt.serverID)
|
|
|
|
if tt.expectError {
|
|
assert.Error(t, err)
|
|
if tt.errorMsg != "" {
|
|
assert.Contains(t, err.Error(), tt.errorMsg)
|
|
}
|
|
assert.Nil(t, result)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, result)
|
|
if tt.checkResult != nil {
|
|
tt.checkResult(t, result)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetByServerIDAndVersion(t *testing.T) {
|
|
memDB := database.NewMemoryDB()
|
|
service := NewRegistryService(memDB, &config.Config{EnableRegistryValidation: false})
|
|
|
|
// Publish multiple versions of the same server
|
|
server1, err := service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/versioned-server",
|
|
Description: "Versioned server v1",
|
|
Version: "1.0.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
_, err = service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/versioned-server",
|
|
Description: "Versioned server v2",
|
|
Version: "2.0.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
tests := []struct {
|
|
name string
|
|
serverID string
|
|
version string
|
|
expectError bool
|
|
errorMsg string
|
|
checkResult func(*testing.T, *apiv0.ServerJSON)
|
|
}{
|
|
{
|
|
name: "get specific version 1.0.0",
|
|
serverID: server1.Meta.Official.ServerID,
|
|
version: "1.0.0",
|
|
expectError: false,
|
|
checkResult: func(t *testing.T, result *apiv0.ServerJSON) {
|
|
t.Helper()
|
|
assert.Equal(t, "1.0.0", result.Version)
|
|
assert.Equal(t, "Versioned server v1", result.Description)
|
|
assert.False(t, result.Meta.Official.IsLatest)
|
|
},
|
|
},
|
|
{
|
|
name: "get specific version 2.0.0",
|
|
serverID: server1.Meta.Official.ServerID,
|
|
version: "2.0.0",
|
|
expectError: false,
|
|
checkResult: func(t *testing.T, result *apiv0.ServerJSON) {
|
|
t.Helper()
|
|
assert.Equal(t, "2.0.0", result.Version)
|
|
assert.Equal(t, "Versioned server v2", result.Description)
|
|
assert.True(t, result.Meta.Official.IsLatest)
|
|
},
|
|
},
|
|
{
|
|
name: "version not found",
|
|
serverID: server1.Meta.Official.ServerID,
|
|
version: "3.0.0",
|
|
expectError: true,
|
|
errorMsg: "record not found",
|
|
},
|
|
{
|
|
name: "server not found",
|
|
serverID: "00000000-0000-0000-0000-000000000000",
|
|
version: "1.0.0",
|
|
expectError: true,
|
|
errorMsg: "record not found",
|
|
},
|
|
{
|
|
name: "invalid server ID format",
|
|
serverID: "invalid-uuid",
|
|
version: "1.0.0",
|
|
expectError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := service.GetByServerIDAndVersion(tt.serverID, tt.version)
|
|
|
|
if tt.expectError {
|
|
assert.Error(t, err)
|
|
if tt.errorMsg != "" {
|
|
assert.Contains(t, err.Error(), tt.errorMsg)
|
|
}
|
|
assert.Nil(t, result)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, result)
|
|
if tt.checkResult != nil {
|
|
tt.checkResult(t, result)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetAllVersionsByServerID(t *testing.T) {
|
|
memDB := database.NewMemoryDB()
|
|
service := NewRegistryService(memDB, &config.Config{EnableRegistryValidation: false})
|
|
|
|
// Publish multiple versions of the same server
|
|
server1, err := service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/multi-version-server",
|
|
Description: "Multi-version server v1",
|
|
Version: "1.0.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
_, err = service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/multi-version-server",
|
|
Description: "Multi-version server v2",
|
|
Version: "2.0.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
_, err = service.Publish(apiv0.ServerJSON{
|
|
Name: "com.example/multi-version-server",
|
|
Description: "Multi-version server v2.1",
|
|
Version: "2.1.0",
|
|
})
|
|
assert.NoError(t, err)
|
|
|
|
tests := []struct {
|
|
name string
|
|
serverID string
|
|
expectError bool
|
|
errorMsg string
|
|
checkResult func(*testing.T, []apiv0.ServerJSON)
|
|
}{
|
|
{
|
|
name: "get all versions of server",
|
|
serverID: server1.Meta.Official.ServerID,
|
|
expectError: false,
|
|
checkResult: func(t *testing.T, result []apiv0.ServerJSON) {
|
|
t.Helper()
|
|
assert.Len(t, result, 3)
|
|
|
|
// Collect versions
|
|
versions := make([]string, 0, len(result))
|
|
latestCount := 0
|
|
for _, server := range result {
|
|
versions = append(versions, server.Version)
|
|
assert.Equal(t, server1.Meta.Official.ServerID, server.Meta.Official.ServerID)
|
|
assert.Equal(t, "com.example/multi-version-server", server.Name)
|
|
if server.Meta.Official.IsLatest {
|
|
latestCount++
|
|
}
|
|
}
|
|
|
|
// Verify all versions are present
|
|
assert.Contains(t, versions, "1.0.0")
|
|
assert.Contains(t, versions, "2.0.0")
|
|
assert.Contains(t, versions, "2.1.0")
|
|
|
|
// Only one should be marked as latest
|
|
assert.Equal(t, 1, latestCount)
|
|
},
|
|
},
|
|
{
|
|
name: "server not found",
|
|
serverID: "00000000-0000-0000-0000-000000000000",
|
|
expectError: true,
|
|
errorMsg: "record not found",
|
|
},
|
|
{
|
|
name: "invalid server ID format",
|
|
serverID: "invalid-uuid",
|
|
expectError: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := service.GetAllVersionsByServerID(tt.serverID)
|
|
|
|
if tt.expectError {
|
|
assert.Error(t, err)
|
|
if tt.errorMsg != "" {
|
|
assert.Contains(t, err.Error(), tt.errorMsg)
|
|
}
|
|
assert.Empty(t, result)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, result)
|
|
if tt.checkResult != nil {
|
|
tt.checkResult(t, result)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|