MCPcopy Index your code
hub / github.com/modelcontextprotocol/registry / SetServerStatus

Method SetServerStatus

internal/database/postgres.go:604–658  ·  view source on GitHub ↗

SetServerStatus updates the status of a specific server version

(ctx context.Context, tx pgx.Tx, serverName, version string, status model.Status, statusMessage *string)

Source from the content-addressed store, hash-verified

602
603// SetServerStatus updates the status of a specific server version
604func (db *PostgreSQL) SetServerStatus(ctx context.Context, tx pgx.Tx, serverName, version string, status model.Status, statusMessage *string) (*apiv0.ServerResponse, error) {
605 if ctx.Err() != nil {
606 return nil, ctx.Err()
607 }
608
609 // Update the status and related fields
610 // Only update status_changed_at when status actually changes
611 query := `
612 UPDATE servers
613 SET
614 status = $1,
615 status_changed_at = CASE WHEN status != $1::varchar THEN NOW() ELSE status_changed_at END,
616 updated_at = NOW(),
617 status_message = $4
618 WHERE server_name = $2 AND version = $3
619 RETURNING server_name, version, status, value, published_at, updated_at, is_latest, status_changed_at, status_message
620 `
621
622 var name, vers, currentStatus string
623 var publishedAt, updatedAt, statusChangedAt time.Time
624 var isLatest bool
625 var valueJSON []byte
626 var resultStatusMessage *string
627
628 err := db.getExecutor(tx).QueryRow(ctx, query, string(status), serverName, version, statusMessage).Scan(&name, &vers, &currentStatus, &valueJSON, &publishedAt, &updatedAt, &isLatest, &statusChangedAt, &resultStatusMessage)
629 if err != nil {
630 if errors.Is(err, pgx.ErrNoRows) {
631 return nil, ErrNotFound
632 }
633 return nil, fmt.Errorf("failed to update server status: %w", err)
634 }
635
636 // Unmarshal the JSON data
637 var serverJSON apiv0.ServerJSON
638 if err := json.Unmarshal(valueJSON, &serverJSON); err != nil {
639 return nil, fmt.Errorf("failed to unmarshal server JSON: %w", err)
640 }
641
642 // Return the updated ServerResponse
643 serverResponse := &apiv0.ServerResponse{
644 Server: serverJSON,
645 Meta: apiv0.ResponseMeta{
646 Official: &apiv0.RegistryExtensions{
647 Status: model.Status(currentStatus),
648 StatusChangedAt: statusChangedAt,
649 StatusMessage: resultStatusMessage,
650 PublishedAt: publishedAt,
651 UpdatedAt: updatedAt,
652 IsLatest: isLatest,
653 },
654 },
655 }
656
657 return serverResponse, nil
658}
659
660// SetAllVersionsStatus updates the status of all versions of a server in a single query
661func (db *PostgreSQL) SetAllVersionsStatus(ctx context.Context, tx pgx.Tx, serverName string, status model.Status, statusMessage *string) ([]*apiv0.ServerResponse, error) {

Callers

nothing calls this directly

Calls 3

getExecutorMethod · 0.95
StatusTypeAlias · 0.92
QueryRowMethod · 0.80

Tested by

no test coverage detected