Introduce serverId, rename id to versionId (#465)
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>
This commit is contained in:
parent
52b1dc71b6
commit
56e8b4879b
5 changed files with 5185 additions and 3466 deletions
|
|
@ -18,7 +18,8 @@ import (
|
|||
// EditServerInput represents the input for editing a server
|
||||
type EditServerInput struct {
|
||||
Authorization string `header:"Authorization" doc:"Registry JWT token with edit permissions" required:"true"`
|
||||
ID string `path:"id" doc:"Server ID (UUID)" format:"uuid"`
|
||||
ServerID string `path:"server_id" doc:"Server ID (UUID)" format:"uuid"`
|
||||
Version string `query:"version" doc:"Version to edit (e.g., '1.0.0')" required:"true" example:"1.0.0"`
|
||||
Body apiv0.ServerJSON `body:""`
|
||||
}
|
||||
|
||||
|
|
@ -30,9 +31,9 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
huma.Register(api, huma.Operation{
|
||||
OperationID: "edit-server",
|
||||
Method: http.MethodPut,
|
||||
Path: "/v0/servers/{id}",
|
||||
Path: "/v0/servers/{server_id}",
|
||||
Summary: "Edit MCP server",
|
||||
Description: "Update an existing MCP server (admin only)",
|
||||
Description: "Update an existing MCP server (admin only). Requires version query parameter to specify which version to edit.",
|
||||
Tags: []string{"admin"},
|
||||
Security: []map[string][]string{
|
||||
{"bearer": {}},
|
||||
|
|
@ -53,7 +54,8 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
}
|
||||
|
||||
// Get current server to check permissions against existing name
|
||||
currentServer, err := registry.GetByID(input.ID)
|
||||
currentServer, err := registry.GetByServerIDAndVersion(input.ServerID, input.Version)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, database.ErrNotFound) {
|
||||
return nil, huma.Error404NotFound("Server not found")
|
||||
|
|
@ -76,8 +78,13 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
|||
return nil, huma.Error400BadRequest("Cannot change status of deleted server. Deleted servers cannot be undeleted.")
|
||||
}
|
||||
|
||||
// Edit the server
|
||||
updatedServer, err := registry.EditServer(input.ID, input.Body)
|
||||
// Edit the server using the version_id from the current server
|
||||
versionID := currentServer.GetVersionID()
|
||||
if versionID == "" {
|
||||
return nil, huma.Error500InternalServerError("Server version ID not found in metadata", nil)
|
||||
}
|
||||
|
||||
updatedServer, err := registry.EditServer(versionID, input.Body)
|
||||
if err != nil {
|
||||
if errors.Is(err, database.ErrNotFound) {
|
||||
return nil, huma.Error404NotFound("Server not found")
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
assert.NotNil(t, published.Meta)
|
||||
assert.NotNil(t, published.Meta.Official)
|
||||
|
||||
testServerID := published.Meta.Official.ID
|
||||
testServerID := published.Meta.Official.ServerID
|
||||
|
||||
// Publish a second server for permission testing
|
||||
otherServer := apiv0.ServerJSON{
|
||||
|
|
@ -62,7 +62,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
assert.NotNil(t, otherPublished.Meta)
|
||||
assert.NotNil(t, otherPublished.Meta.Official)
|
||||
|
||||
otherServerID := otherPublished.Meta.Official.ID
|
||||
otherServerID := otherPublished.Meta.Official.ServerID
|
||||
|
||||
// Publish a deleted server for undelete testing
|
||||
deletedServer := apiv0.ServerJSON{
|
||||
|
|
@ -82,13 +82,14 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
assert.NotNil(t, deletedPublished.Meta)
|
||||
assert.NotNil(t, deletedPublished.Meta.Official)
|
||||
|
||||
deletedServerID := deletedPublished.Meta.Official.ID
|
||||
deletedServerID := deletedPublished.Meta.Official.ServerID
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
authHeader string
|
||||
requestBody interface{}
|
||||
serverID string
|
||||
version string
|
||||
expectedStatus int
|
||||
expectedError string
|
||||
}{
|
||||
|
|
@ -114,9 +115,10 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
Source: "github",
|
||||
ID: "domdomegg/test-server",
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: testServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
|
|
@ -124,6 +126,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
authHeader: "",
|
||||
requestBody: apiv0.ServerJSON{},
|
||||
serverID: testServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: 422,
|
||||
expectedError: "required header parameter is missing",
|
||||
},
|
||||
|
|
@ -131,11 +134,12 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
name: "invalid authorization header format",
|
||||
authHeader: "InvalidFormat token123",
|
||||
requestBody: apiv0.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Test server",
|
||||
Version: "1.0.0",
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Test server",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: testServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusUnauthorized,
|
||||
expectedError: "Unauthorized",
|
||||
},
|
||||
|
|
@ -143,11 +147,12 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
name: "invalid token",
|
||||
authHeader: "Bearer invalid-token",
|
||||
requestBody: apiv0.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Test server",
|
||||
Version: "1.0.0",
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Test server",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: testServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusUnauthorized,
|
||||
expectedError: "Unauthorized",
|
||||
},
|
||||
|
|
@ -165,11 +170,12 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: apiv0.ServerJSON{
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
Version: "1.0.0",
|
||||
Name: "io.github.domdomegg/test-server",
|
||||
Description: "Updated test server",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: testServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusForbidden,
|
||||
expectedError: "Forbidden",
|
||||
},
|
||||
|
|
@ -187,11 +193,12 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: apiv0.ServerJSON{
|
||||
Name: "io.github.other/test-server",
|
||||
Description: "Updated test server",
|
||||
Version: "1.0.0",
|
||||
Name: "io.github.other/test-server",
|
||||
Description: "Updated test server",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: otherServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusForbidden,
|
||||
expectedError: "Forbidden",
|
||||
},
|
||||
|
|
@ -209,11 +216,12 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: apiv0.ServerJSON{
|
||||
Name: "io.github.domdomegg/nonexistent-server",
|
||||
Description: "Updated test server",
|
||||
Version: "1.0.0",
|
||||
Name: "io.github.domdomegg/nonexistent-server",
|
||||
Description: "Updated test server",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: "550e8400-e29b-41d4-a716-446655440999", // Non-existent ID
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusNotFound,
|
||||
expectedError: "Not Found",
|
||||
},
|
||||
|
|
@ -231,11 +239,12 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
return "Bearer " + token
|
||||
}(),
|
||||
requestBody: apiv0.ServerJSON{
|
||||
Name: "invalid-name-format", // Missing namespace/name format
|
||||
Description: "Test server",
|
||||
Version: "1.0.0",
|
||||
Name: "invalid-name-format", // Missing namespace/name format
|
||||
Description: "Test server",
|
||||
Version: "1.0.0",
|
||||
},
|
||||
serverID: testServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusBadRequest,
|
||||
expectedError: "Bad Request",
|
||||
},
|
||||
|
|
@ -264,6 +273,7 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
Version: "1.0.1",
|
||||
},
|
||||
serverID: deletedServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusBadRequest,
|
||||
expectedError: "Cannot change status of deleted server",
|
||||
},
|
||||
|
|
@ -293,7 +303,11 @@ func TestEditServerEndpoint(t *testing.T) {
|
|||
}
|
||||
|
||||
// Create request
|
||||
req := httptest.NewRequest(http.MethodPut, "/v0/servers/"+tc.serverID, bytes.NewReader(requestBody))
|
||||
url := "/v0/servers/" + tc.serverID
|
||||
if tc.version != "" {
|
||||
url += "?version=" + tc.version
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodPut, url, bytes.NewReader(requestBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
if tc.authHeader != "" {
|
||||
req.Header.Set("Authorization", tc.authHeader)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package v0
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
|
@ -23,7 +24,13 @@ type ListServersInput struct {
|
|||
|
||||
// ServerDetailInput represents the input for getting server details
|
||||
type ServerDetailInput struct {
|
||||
ID string `path:"id" doc:"Server ID (UUID)" format:"uuid"`
|
||||
ServerID string `path:"server_id" doc:"Server ID (UUID)" format:"uuid"`
|
||||
Version string `query:"version" doc:"Specific version to retrieve (e.g., '1.0.0'). If not specified, returns latest version." required:"false" example:"1.0.0"`
|
||||
}
|
||||
|
||||
// ServerVersionsInput represents the input for listing all versions of a server
|
||||
type ServerVersionsInput struct {
|
||||
ServerID string `path:"server_id" doc:"Server ID (UUID)" format:"uuid"`
|
||||
}
|
||||
|
||||
// RegisterServersEndpoints registers all server-related endpoints
|
||||
|
|
@ -96,15 +103,25 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
|
|||
huma.Register(api, huma.Operation{
|
||||
OperationID: "get-server",
|
||||
Method: http.MethodGet,
|
||||
Path: "/v0/servers/{id}",
|
||||
Path: "/v0/servers/{server_id}",
|
||||
Summary: "Get MCP server details",
|
||||
Description: "Get detailed information about a specific MCP server",
|
||||
Description: "Get detailed information about a specific MCP server. Returns the latest version by default, or a specific version if the 'version' query parameter is provided.",
|
||||
Tags: []string{"servers"},
|
||||
}, func(_ context.Context, input *ServerDetailInput) (*Response[apiv0.ServerJSON], error) {
|
||||
// Get the server details from the registry service
|
||||
serverDetail, err := registry.GetByID(input.ID)
|
||||
var serverDetail *apiv0.ServerJSON
|
||||
var err error
|
||||
|
||||
if input.Version != "" {
|
||||
// Get specific version by server_id and version
|
||||
serverDetail, err = registry.GetByServerIDAndVersion(input.ServerID, input.Version)
|
||||
} else {
|
||||
// Get latest version by server_id
|
||||
serverDetail, err = registry.GetByServerID(input.ServerID)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err.Error() == "record not found" {
|
||||
if err.Error() == "record not found" || errors.Is(err, database.ErrNotFound) {
|
||||
return nil, huma.Error404NotFound("Server not found")
|
||||
}
|
||||
return nil, huma.Error500InternalServerError("Failed to get server details", err)
|
||||
|
|
@ -114,4 +131,32 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
|
|||
Body: *serverDetail,
|
||||
}, nil
|
||||
})
|
||||
|
||||
// Get server versions endpoint
|
||||
huma.Register(api, huma.Operation{
|
||||
OperationID: "get-server-versions",
|
||||
Method: http.MethodGet,
|
||||
Path: "/v0/servers/{server_id}/versions",
|
||||
Summary: "Get all versions of an MCP server",
|
||||
Description: "Get all available versions for a specific MCP server",
|
||||
Tags: []string{"servers"},
|
||||
}, func(_ context.Context, input *ServerVersionsInput) (*Response[apiv0.ServerListResponse], error) {
|
||||
// Get all versions for this server
|
||||
servers, err := registry.GetAllVersionsByServerID(input.ServerID)
|
||||
if err != nil {
|
||||
if err.Error() == "record not found" {
|
||||
return nil, huma.Error404NotFound("Server not found")
|
||||
}
|
||||
return nil, huma.Error500InternalServerError("Failed to get server versions", err)
|
||||
}
|
||||
|
||||
return &Response[apiv0.ServerListResponse]{
|
||||
Body: apiv0.ServerListResponse{
|
||||
Servers: servers,
|
||||
Metadata: apiv0.Metadata{
|
||||
Count: len(servers),
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ func TestServersListEndpoint(t *testing.T) {
|
|||
assert.NotEmpty(t, server.Description)
|
||||
assert.NotNil(t, server.Meta)
|
||||
assert.NotNil(t, server.Meta.Official)
|
||||
assert.NotEmpty(t, server.Meta.Official.ID)
|
||||
assert.NotEmpty(t, server.Meta.Official.VersionID)
|
||||
}
|
||||
|
||||
// Check metadata if expected
|
||||
|
|
@ -380,25 +380,53 @@ func TestServersDetailEndpoint(t *testing.T) {
|
|||
// Create mock registry service
|
||||
registryService := service.NewRegistryService(database.NewMemoryDB(), config.NewConfig())
|
||||
|
||||
testServer, err := registryService.Publish(apiv0.ServerJSON{
|
||||
// Publish multiple versions of the same server
|
||||
testServer1, err := registryService.Publish(apiv0.ServerJSON{
|
||||
Name: "com.example/test-server",
|
||||
Description: "A test server",
|
||||
Version: "1.0.0",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = registryService.Publish(apiv0.ServerJSON{
|
||||
Name: "com.example/test-server",
|
||||
Description: "A test server updated",
|
||||
Version: "2.0.0",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
serverID string
|
||||
version string
|
||||
expectedStatus int
|
||||
expectedServer *apiv0.ServerJSON
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "successful get server detail",
|
||||
serverID: testServer.Meta.Official.ID,
|
||||
name: "successful get server detail (latest)",
|
||||
serverID: testServer1.Meta.Official.ServerID,
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "successful get server detail with specific version",
|
||||
serverID: testServer1.Meta.Official.ServerID,
|
||||
version: "1.0.0",
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "successful get server detail with latest version",
|
||||
serverID: testServer1.Meta.Official.ServerID,
|
||||
version: "2.0.0",
|
||||
expectedStatus: http.StatusOK,
|
||||
},
|
||||
{
|
||||
name: "version not found for server",
|
||||
serverID: testServer1.Meta.Official.ServerID,
|
||||
version: "3.0.0",
|
||||
expectedStatus: http.StatusNotFound,
|
||||
expectedError: "Server not found",
|
||||
},
|
||||
{
|
||||
name: "invalid server ID format",
|
||||
serverID: "invalid-uuid",
|
||||
|
|
@ -424,6 +452,9 @@ func TestServersDetailEndpoint(t *testing.T) {
|
|||
|
||||
// Create request
|
||||
url := "/v0/servers/" + tc.serverID
|
||||
if tc.version != "" {
|
||||
url += "?version=" + tc.version
|
||||
}
|
||||
req := httptest.NewRequest(http.MethodGet, url, nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
|
|
@ -455,6 +486,115 @@ func TestServersDetailEndpoint(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServersVersionsEndpoint(t *testing.T) {
|
||||
// Create mock registry service
|
||||
registryService := service.NewRegistryService(database.NewMemoryDB(), config.NewConfig())
|
||||
|
||||
// Publish multiple versions of the same server
|
||||
testServer1, err := registryService.Publish(apiv0.ServerJSON{
|
||||
Name: "com.example/versioned-server",
|
||||
Description: "A versioned test server",
|
||||
Version: "1.0.0",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = registryService.Publish(apiv0.ServerJSON{
|
||||
Name: "com.example/versioned-server",
|
||||
Description: "A versioned test server updated",
|
||||
Version: "2.0.0",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = registryService.Publish(apiv0.ServerJSON{
|
||||
Name: "com.example/versioned-server",
|
||||
Description: "A versioned test server latest",
|
||||
Version: "2.1.0",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
serverID string
|
||||
expectedStatus int
|
||||
expectedCount int
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
name: "successful get all versions",
|
||||
serverID: testServer1.Meta.Official.ServerID,
|
||||
expectedStatus: http.StatusOK,
|
||||
expectedCount: 3,
|
||||
},
|
||||
{
|
||||
name: "invalid server ID format",
|
||||
serverID: "invalid-uuid",
|
||||
expectedStatus: http.StatusUnprocessableEntity,
|
||||
expectedError: "validation failed",
|
||||
},
|
||||
{
|
||||
name: "server not found",
|
||||
serverID: uuid.New().String(),
|
||||
expectedStatus: http.StatusNotFound,
|
||||
expectedError: "Server not found",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
// Create a new test API
|
||||
mux := http.NewServeMux()
|
||||
api := humago.New(mux, huma.DefaultConfig("Test API", "1.0.0"))
|
||||
|
||||
// Register the servers endpoints
|
||||
v0.RegisterServersEndpoints(api, registryService)
|
||||
|
||||
// Create request
|
||||
url := "/v0/servers/" + tc.serverID + "/versions"
|
||||
req := httptest.NewRequest(http.MethodGet, url, nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
// Serve the request
|
||||
mux.ServeHTTP(w, req)
|
||||
|
||||
// Check status code
|
||||
assert.Equal(t, tc.expectedStatus, w.Code)
|
||||
|
||||
if tc.expectedStatus == http.StatusOK {
|
||||
// Check content type
|
||||
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
|
||||
|
||||
// Parse response body
|
||||
var versionsResp apiv0.ServerListResponse
|
||||
err := json.NewDecoder(w.Body).Decode(&versionsResp)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Check the response data
|
||||
assert.Len(t, versionsResp.Servers, tc.expectedCount)
|
||||
assert.Equal(t, tc.expectedCount, versionsResp.Metadata.Count)
|
||||
|
||||
// Verify all returned servers have the same server ID but different versions
|
||||
for _, server := range versionsResp.Servers {
|
||||
assert.Equal(t, tc.serverID, server.Meta.Official.ServerID)
|
||||
assert.NotEmpty(t, server.Version)
|
||||
assert.Equal(t, "com.example/versioned-server", server.Name)
|
||||
}
|
||||
|
||||
// Verify versions are included (should have 1.0.0, 2.0.0, 2.1.0)
|
||||
versions := make([]string, 0, len(versionsResp.Servers))
|
||||
for _, server := range versionsResp.Servers {
|
||||
versions = append(versions, server.Version)
|
||||
}
|
||||
assert.Contains(t, versions, "1.0.0")
|
||||
assert.Contains(t, versions, "2.0.0")
|
||||
assert.Contains(t, versions, "2.1.0")
|
||||
} else if tc.expectedError != "" {
|
||||
// Check error message for non-200 responses
|
||||
assert.Contains(t, w.Body.String(), tc.expectedError)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestServersEndpointsIntegration tests the servers endpoints with actual HTTP requests
|
||||
func TestServersEndpointsIntegration(t *testing.T) {
|
||||
// Create mock registry service
|
||||
|
|
@ -476,7 +616,7 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.NotNil(t, published)
|
||||
|
||||
serverID := published.Meta.Official.ID
|
||||
serverID := published.Meta.Official.ServerID
|
||||
servers := []apiv0.ServerJSON{*published}
|
||||
serverDetail := published
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func TestPrometheusHandler(t *testing.T) {
|
|||
mux.Handle("/metrics", metrics.PrometheusHandler())
|
||||
|
||||
// Create request
|
||||
url := "/v0/servers/" + server.Meta.Official.ID
|
||||
url := "/v0/servers/" + server.Meta.Official.ServerID
|
||||
req := httptest.NewRequest(http.MethodGet, url, nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
|
|
@ -76,5 +76,5 @@ func TestPrometheusHandler(t *testing.T) {
|
|||
// Check if the response body contains expected metrics
|
||||
assert.Contains(t, body, "mcp_registry_http_request_duration_bucket")
|
||||
assert.Contains(t, body, "mcp_registry_http_requests_total")
|
||||
assert.Contains(t, body, "path=\"/v0/servers/{id}\"")
|
||||
assert.Contains(t, body, "path=\"/v0/servers/{server_id}\"")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue