Skip to content

Commit 968b203

Browse files
tadasantclaude
andcommitted
Fix is_latest flag management in UpdateServer method
The UpdateServer method was incorrectly using is_latest=true in the WHERE clause when trying to mark servers as not latest, causing a logic conflict. Changed to use server_id and version to target the specific record instead. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ca1e44d commit 968b203

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

internal/database/postgres.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,26 @@ func (db *PostgreSQL) UpdateServer(ctx context.Context, id string, server *apiv0
307307
var args []interface{}
308308

309309
if hasServerID {
310-
// New schema: update by server_id and is_latest
310+
// New schema: update by server_id and version to target specific record
311+
// We need to find the record by server_id and version from the updated server data
312+
serverVersion := ""
313+
if server.Version != "" {
314+
serverVersion = server.Version
315+
} else {
316+
// Extract version from the server data if not provided separately
317+
var tempServer apiv0.ServerJSON
318+
if err := json.Unmarshal(valueJSON, &tempServer); err == nil {
319+
serverVersion = tempServer.Version
320+
}
321+
}
322+
311323
query = `
312324
UPDATE servers
313325
SET value = $1
314326
WHERE server_id = $2
315-
AND (value->'_meta'->'io.modelcontextprotocol.registry/official'->>'is_latest')::boolean = true
327+
AND (value->>'version') = $3
316328
`
317-
args = []interface{}{valueJSON, id}
329+
args = []interface{}{valueJSON, id, serverVersion}
318330
} else {
319331
// Old schema: update by id in JSON
320332
query = `

internal/service/registry_service.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,21 @@ func (s *registryServiceImpl) markAsNotLatest(ctx context.Context, server *apiv0
241241
return nil
242242
}
243243

244-
// Update the existing server to set is_latest = false
245-
server.Meta.Official.IsLatest = false
246-
server.Meta.Official.UpdatedAt = time.Now()
247-
_, err := s.db.UpdateServer(ctx, serverID, server)
244+
// Create a copy of the server to avoid modifying the original
245+
serverCopy := *server
246+
if serverCopy.Meta == nil {
247+
serverCopy.Meta = &apiv0.ServerMeta{}
248+
}
249+
if serverCopy.Meta.Official == nil {
250+
serverCopy.Meta.Official = &apiv0.RegistryExtensions{}
251+
}
252+
253+
// Update the copy to set is_latest = false
254+
serverCopy.Meta.Official.IsLatest = false
255+
serverCopy.Meta.Official.UpdatedAt = time.Now()
256+
257+
// Use UpdateServer with the serverID which should match the current latest version
258+
_, err := s.db.UpdateServer(ctx, serverID, &serverCopy)
248259
return err
249260
}
250261

0 commit comments

Comments
 (0)