MCPcopy
hub / github.com/modelcontextprotocol/registry / CreateServer

Method CreateServer

internal/database/postgres.go:490–540  ·  view source on GitHub ↗

CreateServer inserts a new server version with official metadata

(ctx context.Context, tx pgx.Tx, serverJSON *apiv0.ServerJSON, officialMeta *apiv0.RegistryExtensions)

Source from the content-addressed store, hash-verified

488
489// CreateServer inserts a new server version with official metadata
490func (db *PostgreSQL) CreateServer(ctx context.Context, tx pgx.Tx, serverJSON *apiv0.ServerJSON, officialMeta *apiv0.RegistryExtensions) (*apiv0.ServerResponse, error) {
491 if ctx.Err() != nil {
492 return nil, ctx.Err()
493 }
494
495 // Validate inputs
496 if serverJSON == nil || officialMeta == nil {
497 return nil, fmt.Errorf("serverJSON and officialMeta are required")
498 }
499
500 if serverJSON.Name == "" || serverJSON.Version == "" {
501 return nil, fmt.Errorf("server name and version are required")
502 }
503
504 // Marshal the ServerJSON to JSONB
505 valueJSON, err := json.Marshal(serverJSON)
506 if err != nil {
507 return nil, fmt.Errorf("failed to marshal server JSON: %w", err)
508 }
509
510 // Insert the new server version using composite primary key
511 insertQuery := `
512 INSERT INTO servers (server_name, version, status, status_changed_at, status_message, published_at, updated_at, is_latest, value)
513 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
514 `
515
516 _, err = db.getExecutor(tx).Exec(ctx, insertQuery,
517 serverJSON.Name,
518 serverJSON.Version,
519 string(officialMeta.Status),
520 officialMeta.StatusChangedAt,
521 officialMeta.StatusMessage,
522 officialMeta.PublishedAt,
523 officialMeta.UpdatedAt,
524 officialMeta.IsLatest,
525 valueJSON,
526 )
527 if err != nil {
528 return nil, fmt.Errorf("failed to insert server: %w", err)
529 }
530
531 // Return the complete ServerResponse
532 serverResponse := &apiv0.ServerResponse{
533 Server: *serverJSON,
534 Meta: apiv0.ResponseMeta{
535 Official: officialMeta,
536 },
537 }
538
539 return serverResponse, nil
540}
541
542// UpdateServer updates an existing server record with new server details
543func (db *PostgreSQL) UpdateServer(ctx context.Context, tx pgx.Tx, serverName, version string, serverJSON *apiv0.ServerJSON) (*apiv0.ServerResponse, error) {

Callers

nothing calls this directly

Calls 2

getExecutorMethod · 0.95
ExecMethod · 0.80

Tested by

no test coverage detected