Publisher-managed "deleted" support (#893)

(Updated auto-generated PR description from @tadasant / Claude on Feb
22, 2026)

## Motivation and Context

Fixes #637

Server lifecycle management (deprecation and yanking) is a standard
requirement for package registries. Use cases like rebranding, security
vulnerabilities, and end-of-life servers demand the ability to mark
servers as deprecated or deleted, with optional messaging to guide
consumers toward alternatives.

## Changes

### New API endpoints

- **`PATCH /v0/servers/{serverName}/versions/{version}/status`** —
Update the lifecycle status of a single server version
- **`PATCH /v0/servers/{serverName}/status`** — Update the lifecycle
status of all versions of a server in a single transaction

Both endpoints accept:
```json
{
  "status": "active|deprecated|deleted",
  "statusMessage": "Optional message (max 500 chars) explaining the change"
}
```

### New CLI command

- **`mcp-publisher status <serverName> [version]`** — Update server
lifecycle status from the command line
  - `--status` (required): `active`, `deprecated`, or `deleted`
  - `--message`: Optional status message
- `--all-versions`: Apply to all versions of the server (replaces the
`<version>` argument)

### API response changes

`RegistryExtensions` now includes two new fields:
- `statusChangedAt` — Timestamp of the last status change
- `statusMessage` — Optional free-form message (e.g., deprecation
reason, migration guidance)

### List endpoint changes

- New `include_deleted` query parameter on `GET /v0/servers` — defaults
to `false`, hiding deleted servers from listings
- When `updated_since` is provided, `include_deleted` is automatically
set to `true` for incremental sync

### Database

- Migration `013_add_status_fields.sql`: Adds `status_changed_at` (NOT
NULL, initialized from `published_at`) and `status_message` columns to
the `servers` table

### Design decisions (from review discussion)

- **Dedicated status endpoints** rather than overloading the existing
edit endpoint
- **Bidirectional status transitions** — all transitions between
`active`, `deprecated`, and `deleted` are allowed
- **`statusMessage` as free-form text** — no structured `nextName` or
`alternativeUrl` fields (per maintainer feedback, to avoid complexity
around chaining, trust transfer, etc.)
- **Publish permission** grants status change access (not limited to
admin/edit)
- **Status message auto-cleared** when transitioning back to `active`
Good, now I have the full picture. Here's the addendum:

### Consumer-facing API changes

The new status fields live inside
`_meta["io.modelcontextprotocol.registry/official"]` on every
`ServerResponse`. This is the existing `RegistryExtensions` object — two
new fields are added alongside the existing ones:

**Before:**
```json
{
  "server": { "name": "com.example/my-server", "...": "..." },
  "_meta": {
    "io.modelcontextprotocol.registry/official": {
      "status": "active",
      "publishedAt": "2025-06-01T00:00:00Z",
      "updatedAt": "2025-06-15T00:00:00Z",
      "isLatest": true
    }
  }
}
```

**After:**
```json
{
  "server": { "name": "com.example/my-server", "...": "..." },
  "_meta": {
    "io.modelcontextprotocol.registry/official": {
      "status": "deprecated",
      "statusChangedAt": "2026-02-01T12:00:00Z",
      "statusMessage": "Deprecated in favor of com.example/my-server-v2",
      "publishedAt": "2025-06-01T00:00:00Z",
      "updatedAt": "2026-02-01T12:00:00Z",
      "isLatest": true
    }
  }
}
```

| New field | Type | Present when |
|-----------|------|-------------|
| `statusChangedAt` | `string` (RFC3339) | Always — initialized to
`publishedAt` for existing records |
| `statusMessage` | `string` (max 500 chars) | Only when set —
`null`/omitted for active servers (auto-cleared on transition to active)
|

These fields appear on **every endpoint that returns a
`ServerResponse`**: `GET /v0/servers`, `GET /v0/servers/{name}`, `GET
/v0/servers/{name}/versions/{version}`, and the new PATCH status
endpoints.

### List endpoint filtering

`GET /v0/servers` gains an `include_deleted` query parameter:

| Scenario | Behavior |
|----------|----------|
| No `include_deleted` param | Deleted servers hidden (default `false`)
|
| `include_deleted=true` | Deleted servers included in results |
| `updated_since` provided | `include_deleted` forced to `true` for
incremental sync |

## How Has This Been Tested?

- Unit tests for status handler (`status_test.go`) covering status
transitions, permission checks, validation errors, and the all-versions
endpoint
- Unit tests for the CLI command (`status_test.go`)
- Integration with existing server/edit handler tests
- Database layer tests for the new status update and query methods
- Tested locally with `make dev-compose`

## Types of changes

- [x] New feature (non-breaking change which adds functionality)

## Checklist

- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed

## Open items from review

- [ ] `include_deleted` silent override: When `updated_since` is
provided and `include_deleted=false` is explicitly passed, should return
a 400 error rather than silently overriding
([thread](https://github.com/modelcontextprotocol/registry/pull/893#discussion_r2100879360))
— agreed upon but may not yet be implemented
This commit is contained in:
Preeti Dewani 2026-02-27 22:30:07 +05:30 • committed by GitHub
commit bb84ea69e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4153 additions and 474 deletions

View file

@ -7,6 +7,7 @@ import (
"time"
"github.com/jackc/pgx/v5"
"github.com/modelcontextprotocol/registry/internal/config"
"github.com/modelcontextprotocol/registry/internal/database"
"github.com/modelcontextprotocol/registry/internal/validators"
@ -47,8 +48,8 @@ func (s *registryServiceImpl) ListServers(ctx context.Context, filter *database.
}
// GetServerByName retrieves the latest version of a server by its server name
func (s *registryServiceImpl) GetServerByName(ctx context.Context, serverName string) (*apiv0.ServerResponse, error) {
serverRecord, err := s.db.GetServerByName(ctx, nil, serverName)
func (s *registryServiceImpl) GetServerByName(ctx context.Context, serverName string, includeDeleted bool) (*apiv0.ServerResponse, error) {
serverRecord, err := s.db.GetServerByName(ctx, nil, serverName, includeDeleted)
if err != nil {
return nil, err
}
@ -57,8 +58,8 @@ func (s *registryServiceImpl) GetServerByName(ctx context.Context, serverName st
}
// GetServerByNameAndVersion retrieves a specific version of a server by server name and version
func (s *registryServiceImpl) GetServerByNameAndVersion(ctx context.Context, serverName string, version string) (*apiv0.ServerResponse, error) {
serverRecord, err := s.db.GetServerByNameAndVersion(ctx, nil, serverName, version)
func (s *registryServiceImpl) GetServerByNameAndVersion(ctx context.Context, serverName string, version string, includeDeleted bool) (*apiv0.ServerResponse, error) {
serverRecord, err := s.db.GetServerByNameAndVersion(ctx, nil, serverName, version, includeDeleted)
if err != nil {
return nil, err
}
@ -67,8 +68,8 @@ func (s *registryServiceImpl) GetServerByNameAndVersion(ctx context.Context, ser
}
// GetAllVersionsByServerName retrieves all versions of a server by server name
func (s *registryServiceImpl) GetAllVersionsByServerName(ctx context.Context, serverName string) ([]*apiv0.ServerResponse, error) {
serverRecords, err := s.db.GetAllVersionsByServerName(ctx, nil, serverName)
func (s *registryServiceImpl) GetAllVersionsByServerName(ctx context.Context, serverName string, includeDeleted bool) ([]*apiv0.ServerResponse, error) {
serverRecords, err := s.db.GetAllVersionsByServerName(ctx, nil, serverName, includeDeleted)
if err != nil {
return nil, err
}
@ -152,10 +153,11 @@ func (s *registryServiceImpl) createServerInTransaction(ctx context.Context, tx
// Create metadata for the new server
officialMeta := &apiv0.RegistryExtensions{
Status: model.StatusActive, /* New versions are active by default */
PublishedAt: publishTime,
UpdatedAt: publishTime,
IsLatest: isNewLatest,
Status: model.StatusActive, /* New versions are active by default */
StatusChangedAt: publishTime,
PublishedAt: publishTime,
UpdatedAt: publishTime,
IsLatest: isNewLatest,
}
// Insert new server version
@ -186,17 +188,18 @@ func (s *registryServiceImpl) validateNoDuplicateRemoteURLs(ctx context.Context,
}
// UpdateServer updates an existing server with new details
func (s *registryServiceImpl) UpdateServer(ctx context.Context, serverName, version string, req *apiv0.ServerJSON, newStatus *string) (*apiv0.ServerResponse, error) {
func (s *registryServiceImpl) UpdateServer(ctx context.Context, serverName, version string, req *apiv0.ServerJSON, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error) {
// Wrap the entire operation in a transaction
return database.InTransactionT(ctx, s.db, func(ctx context.Context, tx pgx.Tx) (*apiv0.ServerResponse, error) {
return s.updateServerInTransaction(ctx, tx, serverName, version, req, newStatus)
return s.updateServerInTransaction(ctx, tx, serverName, version, req, statusChange)
})
}
// updateServerInTransaction contains the actual UpdateServer logic within a transaction
func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx pgx.Tx, serverName, version string, req *apiv0.ServerJSON, newStatus *string) (*apiv0.ServerResponse, error) {
func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx pgx.Tx, serverName, version string, req *apiv0.ServerJSON, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error) {
// Get current server to check if it's deleted or being deleted
currentServer, err := s.db.GetServerByNameAndVersion(ctx, tx, serverName, version)
// Include deleted servers since we may need to update or restore them
currentServer, err := s.db.GetServerByNameAndVersion(ctx, tx, serverName, version, true)
if err != nil {
return nil, err
}
@ -205,7 +208,7 @@ func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx
// 1. Server is currently deleted, OR
// 2. Server is being set to deleted status
currentlyDeleted := currentServer.Meta.Official != nil && currentServer.Meta.Official.Status == model.StatusDeleted
beingDeleted := newStatus != nil && *newStatus == string(model.StatusDeleted)
beingDeleted := statusChange != nil && statusChange.NewStatus == model.StatusDeleted
skipRegistryValidation := currentlyDeleted || beingDeleted
// Validate the request, potentially skipping registry validation for deleted servers
@ -233,8 +236,8 @@ func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx
}
// Handle status change if provided
if newStatus != nil {
updatedWithStatus, err := s.db.SetServerStatus(ctx, tx, serverName, version, *newStatus)
if statusChange != nil {
updatedWithStatus, err := s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage)
if err != nil {
return nil, err
}
@ -243,3 +246,78 @@ func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx
return updatedServerResponse, nil
}
// UpdateServerStatus updates only the status metadata of a server version
func (s *registryServiceImpl) UpdateServerStatus(ctx context.Context, serverName, version string, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error) {
// Wrap the entire operation in a transaction
return database.InTransactionT(ctx, s.db, func(ctx context.Context, tx pgx.Tx) (*apiv0.ServerResponse, error) {
return s.updateServerStatusInTransaction(ctx, tx, serverName, version, statusChange)
})
}
// updateServerStatusInTransaction contains the actual UpdateServerStatus logic within a transaction
func (s *registryServiceImpl) updateServerStatusInTransaction(ctx context.Context, tx pgx.Tx, serverName, version string, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error) {
// Get current server to verify it exists and check current status
// Include deleted servers since we may need to restore them
currentServer, err := s.db.GetServerByNameAndVersion(ctx, tx, serverName, version, true)
if err != nil {
return nil, err
}
// Acquire advisory lock to prevent concurrent edits of servers with same name
if err := s.db.AcquirePublishLock(ctx, tx, serverName); err != nil {
return nil, err
}
// When transitioning to active from deleted, validate remote URLs don't conflict
if statusChange.NewStatus == model.StatusActive &&
currentServer.Meta.Official != nil &&
currentServer.Meta.Official.Status == model.StatusDeleted {
if err := s.validateNoDuplicateRemoteURLs(ctx, tx, currentServer.Server); err != nil {
return nil, err
}
}
// Update only the status metadata
return s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage)
}
// UpdateAllVersionsStatus updates the status metadata of all versions of a server in a single transaction
func (s *registryServiceImpl) UpdateAllVersionsStatus(ctx context.Context, serverName string, statusChange *StatusChangeRequest) ([]*apiv0.ServerResponse, error) {
// Wrap the entire operation in a transaction
return database.InTransactionT(ctx, s.db, func(ctx context.Context, tx pgx.Tx) ([]*apiv0.ServerResponse, error) {
return s.updateAllVersionsStatusInTransaction(ctx, tx, serverName, statusChange)
})
}
// updateAllVersionsStatusInTransaction contains the actual UpdateAllVersionsStatus logic within a transaction
func (s *registryServiceImpl) updateAllVersionsStatusInTransaction(ctx context.Context, tx pgx.Tx, serverName string, statusChange *StatusChangeRequest) ([]*apiv0.ServerResponse, error) {
// Acquire advisory lock to prevent concurrent edits of servers with same name
if err := s.db.AcquirePublishLock(ctx, tx, serverName); err != nil {
return nil, err
}
// When transitioning to active, validate remote URLs for any versions currently deleted
if statusChange.NewStatus == model.StatusActive {
includeDeleted := true
// When transitioning to active, it means the current status is either deprecated or deleted, so it should include deleted server also
filter := &database.ServerFilter{Name: &serverName, IncludeDeleted: &includeDeleted}
versions, _, err := s.db.ListServers(ctx, tx, filter, "", 1000)
if err != nil {
return nil, fmt.Errorf("failed to list server versions: %w", err)
}
for _, version := range versions {
if version.Meta.Official != nil &&
version.Meta.Official.Status == model.StatusDeleted {
if err := s.validateNoDuplicateRemoteURLs(ctx, tx, version.Server); err != nil {
return nil, err
}
}
}
}
// Update all versions' status in a single database call
return s.db.SetAllVersionsStatus(ctx, tx, serverName, statusChange.NewStatus, statusChange.StatusMessage)
}

View file

@ -8,12 +8,13 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"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"
"github.com/stretchr/testify/require"
)
func TestValidateNoDuplicateRemoteURLs(t *testing.T) {
@ -177,7 +178,7 @@ func TestGetServerByName(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := service.GetServerByName(ctx, tt.serverName)
result, err := service.GetServerByName(ctx, tt.serverName, false)
if tt.expectError {
assert.Error(t, err)
@ -270,7 +271,7 @@ func TestGetServerByNameAndVersion(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := service.GetServerByNameAndVersion(ctx, tt.serverName, tt.version)
result, err := service.GetServerByNameAndVersion(ctx, tt.serverName, tt.version, false)
if tt.expectError {
assert.Error(t, err)
@ -366,7 +367,7 @@ func TestGetAllVersionsByServerName(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := service.GetAllVersionsByServerName(ctx, tt.serverName)
result, err := service.GetAllVersionsByServerName(ctx, tt.serverName, false)
if tt.expectError {
assert.Error(t, err)
@ -425,7 +426,7 @@ func TestCreateServerConcurrentVersionsNoRace(t *testing.T) {
}
// Query database to check the final state after all creates complete
allVersions, err := service.GetAllVersionsByServerName(ctx, serverName)
allVersions, err := service.GetAllVersionsByServerName(ctx, serverName, false)
require.NoError(t, err, "failed to get all versions")
latestCount := 0
@ -466,7 +467,7 @@ func TestUpdateServer(t *testing.T) {
serverName string
version string
updatedServer *apiv0.ServerJSON
newStatus *string
statusChange *StatusChangeRequest
expectError bool
errorMsg string
checkResult func(*testing.T, *apiv0.ServerResponse)
@ -503,7 +504,9 @@ func TestUpdateServer(t *testing.T) {
Description: "Updated with status change",
Version: version,
},
newStatus: stringPtr(string(model.StatusDeprecated)),
statusChange: &StatusChangeRequest{
NewStatus: model.StatusDeprecated,
},
expectError: false,
checkResult: func(t *testing.T, result *apiv0.ServerResponse) {
t.Helper()
@ -528,7 +531,7 @@ func TestUpdateServer(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := service.UpdateServer(ctx, tt.serverName, tt.version, tt.updatedServer, tt.newStatus)
result, err := service.UpdateServer(ctx, tt.serverName, tt.version, tt.updatedServer, tt.statusChange)
if tt.expectError {
assert.Error(t, err)
@ -580,12 +583,14 @@ func TestUpdateServer_SkipValidationForDeletedServers(t *testing.T) {
service.(*registryServiceImpl).cfg.EnableRegistryValidation = originalConfig
// First, set server to deleted status
deletedStatus := string(model.StatusDeleted)
_, err = service.UpdateServer(ctx, serverName, version, invalidServer, &deletedStatus)
deletedStatusChange := &StatusChangeRequest{
NewStatus: model.StatusDeleted,
}
_, err = service.UpdateServer(ctx, serverName, version, invalidServer, deletedStatusChange)
require.NoError(t, err, "should be able to set server to deleted (validation should be skipped)")
// Verify server is now deleted
updatedServer, err := service.GetServerByNameAndVersion(ctx, serverName, version)
// Verify server is now deleted (need includeDeleted=true to find it)
updatedServer, err := service.GetServerByNameAndVersion(ctx, serverName, version, true)
require.NoError(t, err)
assert.Equal(t, model.StatusDeleted, updatedServer.Meta.Official.Status)
@ -635,8 +640,10 @@ func TestUpdateServer_SkipValidationForDeletedServers(t *testing.T) {
service.(*registryServiceImpl).cfg.EnableRegistryValidation = originalConfig
// Update server and set to deleted in same operation - should skip validation
newDeletedStatus := string(model.StatusDeleted)
result2, err := service.UpdateServer(ctx, "com.example/being-deleted-test", "1.0.0", activeServer, &newDeletedStatus)
newDeletedStatusChange := &StatusChangeRequest{
NewStatus: model.StatusDeleted,
}
result2, err := service.UpdateServer(ctx, "com.example/being-deleted-test", "1.0.0", activeServer, newDeletedStatusChange)
assert.NoError(t, err, "updating server being set to deleted should skip registry validation")
assert.NotNil(t, result2)
assert.Equal(t, model.StatusDeleted, result2.Meta.Official.Status)
@ -767,14 +774,14 @@ func TestVersionComparison(t *testing.T) {
}
// Get the latest version - should be 2.1.0 based on semantic versioning
latest, err := service.GetServerByName(ctx, serverName)
latest, err := service.GetServerByName(ctx, serverName, false)
require.NoError(t, err)
assert.Equal(t, "2.1.0", latest.Server.Version, "Latest version should be 2.1.0")
assert.True(t, latest.Meta.Official.IsLatest)
// Verify only one version is marked as latest
allVersions, err := service.GetAllVersionsByServerName(ctx, serverName)
allVersions, err := service.GetAllVersionsByServerName(ctx, serverName, false)
require.NoError(t, err)
latestCount := 0
@ -786,6 +793,195 @@ func TestVersionComparison(t *testing.T) {
assert.Equal(t, 1, latestCount, "Exactly one version should be marked as latest")
}
func TestUpdateServerStatus_ValidateRemoteURLsOnRestoreToActive(t *testing.T) {
ctx := context.Background()
testDB := database.NewTestDB(t)
service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false})
remoteURL := "https://api.example.com/mcp"
// Create Server A with a remote URL
serverA := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/server-a",
Description: "Server A with remote URL",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err := service.CreateServer(ctx, serverA)
require.NoError(t, err)
// Delete Server A
_, err = service.UpdateServerStatus(ctx, "com.example/server-a", "1.0.0", &StatusChangeRequest{
NewStatus: model.StatusDeleted,
})
require.NoError(t, err)
// Create Server B with the same remote URL (should succeed since A is deleted)
serverB := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/server-b",
Description: "Server B with same remote URL",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err = service.CreateServer(ctx, serverB)
require.NoError(t, err)
// Try to restore Server A to active - should fail due to URL conflict
_, err = service.UpdateServerStatus(ctx, "com.example/server-a", "1.0.0", &StatusChangeRequest{
NewStatus: model.StatusActive,
})
assert.Error(t, err)
assert.Contains(t, err.Error(), "remote URL")
assert.Contains(t, err.Error(), "already used by server")
}
func TestUpdateServerStatus_ValidateRemoteURLsOnRestoreFromDeleted(t *testing.T) {
ctx := context.Background()
testDB := database.NewTestDB(t)
service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false})
remoteURL := "https://api.deleted.com/mcp"
// Create Server A with a remote URL and delete it
serverA := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/deleted-server",
Description: "Server to be deleted",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err := service.CreateServer(ctx, serverA)
require.NoError(t, err)
// Delete Server A
_, err = service.UpdateServerStatus(ctx, "com.example/deleted-server", "1.0.0", &StatusChangeRequest{
NewStatus: model.StatusDeleted,
})
require.NoError(t, err)
// Create Server B with the same remote URL (should succeed since A is deleted)
serverB := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/new-server",
Description: "New server with same remote URL",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err = service.CreateServer(ctx, serverB)
require.NoError(t, err)
// Try to restore deleted server to active - should fail due to URL conflict
_, err = service.UpdateServerStatus(ctx, "com.example/deleted-server", "1.0.0", &StatusChangeRequest{
NewStatus: model.StatusActive,
})
assert.Error(t, err)
assert.Contains(t, err.Error(), "remote URL")
assert.Contains(t, err.Error(), "already used by server")
}
func TestUpdateAllVersionsStatus_ValidateRemoteURLsOnRestoreToActive(t *testing.T) {
ctx := context.Background()
testDB := database.NewTestDB(t)
service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false})
remoteURL := "https://api.allversions.com/mcp"
// Create Server A with multiple versions
serverAv1 := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/multi-version-server",
Description: "Server A version 1",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err := service.CreateServer(ctx, serverAv1)
require.NoError(t, err)
serverAv2 := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/multi-version-server",
Description: "Server A version 2",
Version: "2.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err = service.CreateServer(ctx, serverAv2)
require.NoError(t, err)
// Delete all versions of Server A
_, err = service.UpdateAllVersionsStatus(ctx, "com.example/multi-version-server", &StatusChangeRequest{
NewStatus: model.StatusDeleted,
})
require.NoError(t, err)
// Create Server B with the same remote URL
serverB := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/conflicting-server",
Description: "Server B with same remote URL",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: remoteURL},
},
}
_, err = service.CreateServer(ctx, serverB)
require.NoError(t, err)
// Try to restore all versions of Server A to active - should fail
_, err = service.UpdateAllVersionsStatus(ctx, "com.example/multi-version-server", &StatusChangeRequest{
NewStatus: model.StatusActive,
})
assert.Error(t, err)
assert.Contains(t, err.Error(), "remote URL")
assert.Contains(t, err.Error(), "already used by server")
}
func TestUpdateServerStatus_NoConflictWhenRestoringWithUniqueURLs(t *testing.T) {
ctx := context.Background()
testDB := database.NewTestDB(t)
service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false})
// Create and delete a server
server := &apiv0.ServerJSON{
Schema: model.CurrentSchemaURL,
Name: "com.example/unique-url-server",
Description: "Server with unique URL",
Version: "1.0.0",
Remotes: []model.Transport{
{Type: "streamable-http", URL: "https://unique.example.com/mcp"},
},
}
_, err := service.CreateServer(ctx, server)
require.NoError(t, err)
// Delete the server
_, err = service.UpdateServerStatus(ctx, "com.example/unique-url-server", "1.0.0", &StatusChangeRequest{
NewStatus: model.StatusDeleted,
})
require.NoError(t, err)
// Restore to active - should succeed since URL is still unique
result, err := service.UpdateServerStatus(ctx, "com.example/unique-url-server", "1.0.0", &StatusChangeRequest{
NewStatus: model.StatusActive,
})
assert.NoError(t, err)
assert.NotNil(t, result)
assert.Equal(t, model.StatusActive, result.Meta.Official.Status)
}
// Helper functions
func stringPtr(s string) *string {
return &s

View file

@ -5,20 +5,31 @@ import (
"github.com/modelcontextprotocol/registry/internal/database"
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
"github.com/modelcontextprotocol/registry/pkg/model"
)
// StatusChangeRequest represents a request to change a server's status
type StatusChangeRequest struct {
NewStatus model.Status `json:"newStatus"`
StatusMessage *string `json:"statusMessage,omitempty"`
}
// RegistryService defines the interface for registry operations
type RegistryService interface {
// ListServers retrieve all servers with optional filtering
ListServers(ctx context.Context, filter *database.ServerFilter, cursor string, limit int) ([]*apiv0.ServerResponse, string, error)
// GetServerByName retrieve latest version of a server by server name
GetServerByName(ctx context.Context, serverName string) (*apiv0.ServerResponse, error)
GetServerByName(ctx context.Context, serverName string, includeDeleted bool) (*apiv0.ServerResponse, error)
// GetServerByNameAndVersion retrieve specific version of a server by server name and version
GetServerByNameAndVersion(ctx context.Context, serverName string, version string) (*apiv0.ServerResponse, error)
GetServerByNameAndVersion(ctx context.Context, serverName string, version string, includeDeleted bool) (*apiv0.ServerResponse, error)
// GetAllVersionsByServerName retrieve all versions of a server by server name
GetAllVersionsByServerName(ctx context.Context, serverName string) ([]*apiv0.ServerResponse, error)
GetAllVersionsByServerName(ctx context.Context, serverName string, includeDeleted bool) ([]*apiv0.ServerResponse, error)
// CreateServer creates a new server version
CreateServer(ctx context.Context, req *apiv0.ServerJSON) (*apiv0.ServerResponse, error)
// UpdateServer updates an existing server and optionally its status
UpdateServer(ctx context.Context, serverName, version string, req *apiv0.ServerJSON, newStatus *string) (*apiv0.ServerResponse, error)
UpdateServer(ctx context.Context, serverName, version string, req *apiv0.ServerJSON, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error)
// UpdateServerStatus updates only the status metadata of a server version
UpdateServerStatus(ctx context.Context, serverName, version string, statusChange *StatusChangeRequest) (*apiv0.ServerResponse, error)
// UpdateAllVersionsStatus updates the status metadata of all versions of a server in a single transaction
UpdateAllVersionsStatus(ctx context.Context, serverName string, statusChange *StatusChangeRequest) ([]*apiv0.ServerResponse, error)
}