Rename api/v1 -> api/v0 to match API paths (#320)

This PR renames the API paths from v1 to v0 to align with the actual API
versioning scheme.
This commit is contained in:
adam jones 2025-08-28 15:06:00 +01:00 • committed by GitHub
commit c0a94cca8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 176 additions and 177 deletions

View file

@ -4,7 +4,7 @@ import (
"context"
"errors"
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
"github.com/modelcontextprotocol/registry/pkg/model"
)
@ -21,16 +21,16 @@ var (
// Database defines the interface for database operations with extension wrapper architecture
type Database interface {
// List retrieves all ServerRecord entries with optional filtering
List(ctx context.Context, filter map[string]any, cursor string, limit int) ([]*apiv1.ServerRecord, string, error)
List(ctx context.Context, filter map[string]any, cursor string, limit int) ([]*apiv0.ServerRecord, string, error)
// GetByID retrieves a single ServerRecord by its ID
GetByID(ctx context.Context, id string) (*apiv1.ServerRecord, error)
GetByID(ctx context.Context, id string) (*apiv0.ServerRecord, error)
// Publish adds a new server to the database with separated server.json and extensions
// The registryMetadata contains metadata determined by the service layer (e.g., is_latest, timestamps)
Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv1.RegistryExtensions) (*apiv1.ServerRecord, error)
Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerRecord, error)
// UpdateLatestFlag updates the is_latest flag for a specific server record
UpdateLatestFlag(ctx context.Context, id string, isLatest bool) error
// UpdateServer updates an existing server record with new server details
UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv1.ServerRecord, error)
UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerRecord, error)
// ImportSeed imports initial data from a seed file
ImportSeed(ctx context.Context, seedFilePath string) error
// Close closes the database connection

View file

@ -9,7 +9,7 @@ import (
"os"
"strings"
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
)
// ReadSeedFile reads seed data from various sources:
@ -17,7 +17,7 @@ import (
// 2. Direct HTTP URLs to seed.json files - expects extension wrapper format
// 3. Registry root URLs (automatically appends /v0/servers and paginates)
// Only the extension wrapper format is supported (array of ServerResponse objects)
func ReadSeedFile(ctx context.Context, path string) ([]*apiv1.ServerRecord, error) {
func ReadSeedFile(ctx context.Context, path string) ([]*apiv0.ServerRecord, error) {
var data []byte
var err error
@ -39,17 +39,17 @@ func ReadSeedFile(ctx context.Context, path string) ([]*apiv1.ServerRecord, erro
}
// Parse extension wrapper format (only supported format)
var serverResponses []apiv1.ServerRecord
var serverResponses []apiv0.ServerRecord
if err := json.Unmarshal(data, &serverResponses); err != nil {
return nil, fmt.Errorf("failed to parse seed data as extension wrapper format: %w", err)
}
if len(serverResponses) == 0 {
return []*apiv1.ServerRecord{}, nil
return []*apiv0.ServerRecord{}, nil
}
// Convert ServerResponse to ServerRecord
var records []*apiv1.ServerRecord
var records []*apiv0.ServerRecord
for _, response := range serverResponses {
record := convertServerResponseToRecord(response)
records = append(records, record)
@ -77,8 +77,8 @@ func fetchFromHTTP(ctx context.Context, url string) ([]byte, error) {
return io.ReadAll(resp.Body)
}
func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv1.ServerRecord, error) {
var allRecords []*apiv1.ServerRecord
func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv0.ServerRecord, error) {
var allRecords []*apiv0.ServerRecord
cursor := ""
for {
@ -97,7 +97,7 @@ func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv1.ServerR
}
var response struct {
Servers []apiv1.ServerRecord `json:"servers"`
Servers []apiv0.ServerRecord `json:"servers"`
Metadata *struct {
NextCursor string `json:"next_cursor,omitempty"`
} `json:"metadata,omitempty"`
@ -123,7 +123,7 @@ func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv1.ServerR
return allRecords, nil
}
func convertServerResponseToRecord(response apiv1.ServerRecord) *apiv1.ServerRecord {
func convertServerResponseToRecord(response apiv0.ServerRecord) *apiv0.ServerRecord {
// The registry extensions are already properly typed, so we can use them directly
registryMetadata := response.XIOModelContextProtocolRegistry
@ -133,10 +133,9 @@ func convertServerResponseToRecord(response apiv1.ServerRecord) *apiv1.ServerRec
publisherExtensions = make(map[string]interface{})
}
return &apiv1.ServerRecord{
return &apiv0.ServerRecord{
Server: response.Server,
XIOModelContextProtocolRegistry: registryMetadata,
XPublisher: publisherExtensions,
}
}

View file

@ -10,7 +10,7 @@ import (
"time"
"github.com/modelcontextprotocol/registry/internal/database"
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
"github.com/modelcontextprotocol/registry/pkg/model"
"github.com/stretchr/testify/assert"
)
@ -18,7 +18,7 @@ import (
func TestReadSeedFile_LocalFile(t *testing.T) {
// Create a temporary seed file in extension wrapper format
tempFile := "/tmp/test_seed.json"
seedData := []apiv1.ServerRecord{
seedData := []apiv0.ServerRecord{
{
Server: model.ServerJSON{
Name: "test-server-1",
@ -32,7 +32,7 @@ func TestReadSeedFile_LocalFile(t *testing.T) {
Version: "1.0.0",
},
},
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
ID: "test-id-1",
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
IsLatest: true,
@ -66,13 +66,13 @@ func TestReadSeedFile_LocalFile(t *testing.T) {
func TestReadSeedFile_DirectHTTPURL(t *testing.T) {
// Create a test HTTP server that serves seed JSON directly in extension wrapper format
seedData := []apiv1.ServerRecord{
seedData := []apiv0.ServerRecord{
{
Server: model.ServerJSON{
Name: "test-server-1",
Description: "Test server 1",
},
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
ID: "test-id-1",
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
IsLatest: true,
@ -98,7 +98,7 @@ func TestReadSeedFile_DirectHTTPURL(t *testing.T) {
func TestReadSeedFile_RegistryURL(t *testing.T) {
// Create mock registry responses
server1 := apiv1.ServerRecord{
server1 := apiv0.ServerRecord{
Server: model.ServerJSON{
Name: "Test Server 1",
Description: "First test server",
@ -111,14 +111,14 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
},
},
},
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
ID: "server-1",
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
IsLatest: true,
ReleaseDate: "2023-01-01T00:00:00Z",
},
}
server2 := apiv1.ServerRecord{
server2 := apiv0.ServerRecord{
Server: model.ServerJSON{
Name: "Test Server 2",
Description: "Second test server",
@ -131,7 +131,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
},
},
},
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
ID: "server-2",
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
IsLatest: true,
@ -177,7 +177,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
}
type PaginatedResponse struct {
Servers []apiv1.ServerRecord `json:"servers"`
Servers []apiv0.ServerRecord `json:"servers"`
Metadata *Metadata `json:"metadata,omitempty"`
}
@ -186,7 +186,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
case "":
// First page
response = PaginatedResponse{
Servers: []apiv1.ServerRecord{server1},
Servers: []apiv0.ServerRecord{server1},
Metadata: &Metadata{
NextCursor: "next-cursor-1",
Count: 1,
@ -195,7 +195,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
case "next-cursor-1":
// Second page
response = PaginatedResponse{
Servers: []apiv1.ServerRecord{server2},
Servers: []apiv0.ServerRecord{server2},
Metadata: &Metadata{
Count: 1,
// No NextCursor means end of pagination
@ -204,7 +204,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
default:
// No more pages
response = PaginatedResponse{
Servers: []apiv1.ServerRecord{},
Servers: []apiv0.ServerRecord{},
Metadata: &Metadata{},
}
}

View file

@ -7,26 +7,26 @@ import (
"sync"
"time"
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
"github.com/modelcontextprotocol/registry/pkg/model"
)
// MemoryDB is an in-memory implementation of the Database interface
type MemoryDB struct {
entries map[string]*apiv1.ServerRecord // maps registry metadata ID to ServerRecord
entries map[string]*apiv0.ServerRecord // maps registry metadata ID to ServerRecord
mu sync.RWMutex
}
// NewMemoryDB creates a new instance of the in-memory database
func NewMemoryDB(e map[string]*model.ServerJSON) *MemoryDB {
// Convert ServerJSON entries to ServerRecord entries
serverRecords := make(map[string]*apiv1.ServerRecord)
serverRecords := make(map[string]*apiv0.ServerRecord)
for registryID, serverDetail := range e {
// Create registry metadata
now := time.Now()
record := &apiv1.ServerRecord{
record := &apiv0.ServerRecord{
Server: *serverDetail,
XIOModelContextProtocolRegistry: apiv1.RegistryExtensions{
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
ID: registryID,
PublishedAt: now,
UpdatedAt: now,
@ -48,7 +48,7 @@ func (db *MemoryDB) List(
filter map[string]any,
cursor string,
limit int,
) ([]*apiv1.ServerRecord, string, error) {
) ([]*apiv0.ServerRecord, string, error) {
if ctx.Err() != nil {
return nil, "", ctx.Err()
}
@ -61,7 +61,7 @@ func (db *MemoryDB) List(
defer db.mu.RUnlock()
// Convert all entries to a slice for pagination, filter by is_latest
var allEntries []*apiv1.ServerRecord
var allEntries []*apiv0.ServerRecord
for _, entry := range db.entries {
if entry.XIOModelContextProtocolRegistry.IsLatest {
allEntries = append(allEntries, entry)
@ -69,7 +69,7 @@ func (db *MemoryDB) List(
}
// Simple filtering implementation
var filteredEntries []*apiv1.ServerRecord
var filteredEntries []*apiv0.ServerRecord
for _, entry := range allEntries {
include := true
@ -127,11 +127,11 @@ func (db *MemoryDB) List(
// Apply pagination
endIdx := min(startIdx+limit, len(filteredEntries))
var result []*apiv1.ServerRecord
var result []*apiv0.ServerRecord
if startIdx < len(filteredEntries) {
result = filteredEntries[startIdx:endIdx]
} else {
result = []*apiv1.ServerRecord{}
result = []*apiv0.ServerRecord{}
}
// Determine next cursor using registry metadata ID
@ -144,7 +144,7 @@ func (db *MemoryDB) List(
}
// GetByID retrieves a single ServerRecord by its registry metadata ID
func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv1.ServerRecord, error) {
func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv0.ServerRecord, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
@ -163,7 +163,7 @@ func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv1.ServerRecord
}
// Publish adds a new server to the database with separated server.json and extensions
func (db *MemoryDB) Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv1.RegistryExtensions) (*apiv1.ServerRecord, error) {
func (db *MemoryDB) Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerRecord, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
@ -188,7 +188,7 @@ func (db *MemoryDB) Publish(ctx context.Context, serverDetail model.ServerJSON,
}
// Create server record
record := &apiv1.ServerRecord{
record := &apiv0.ServerRecord{
Server: serverDetail,
XIOModelContextProtocolRegistry: registryMetadata,
XPublisher: publisherExtensions,
@ -245,7 +245,7 @@ func (db *MemoryDB) UpdateLatestFlag(ctx context.Context, id string, isLatest bo
}
// UpdateServer updates an existing server record with new server details
func (db *MemoryDB) UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv1.ServerRecord, error) {
func (db *MemoryDB) UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerRecord, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}

View file

@ -10,7 +10,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
apiv1 "github.com/modelcontextprotocol/registry/pkg/api/v1"
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
"github.com/modelcontextprotocol/registry/pkg/model"
)
@ -48,7 +48,7 @@ func (db *PostgreSQL) List(
filter map[string]any,
cursor string,
limit int,
) ([]*apiv1.ServerRecord, string, error) {
) ([]*apiv0.ServerRecord, string, error) {
if limit <= 0 {
limit = 10
}
@ -113,9 +113,9 @@ func (db *PostgreSQL) List(
}
defer rows.Close()
var results []*apiv1.ServerRecord
var results []*apiv0.ServerRecord
for rows.Next() {
var record apiv1.ServerRecord
var record apiv0.ServerRecord
var repositoryJSON, packagesJSON, remotesJSON, publisherExtensionsJSON []byte
var publishedAt, updatedAt, releaseDate time.Time
@ -167,7 +167,7 @@ func (db *PostgreSQL) List(
}
// parseJSONFields parses JSON fields for a server record
func parseJSONFields(record *apiv1.ServerRecord, repositoryJSON, packagesJSON, remotesJSON, publisherExtensionsJSON []byte) error {
func parseJSONFields(record *apiv0.ServerRecord, repositoryJSON, packagesJSON, remotesJSON, publisherExtensionsJSON []byte) error {
if len(repositoryJSON) > 0 {
if err := json.Unmarshal(repositoryJSON, &record.Server.Repository); err != nil {
return fmt.Errorf("failed to unmarshal repository: %w", err)
@ -198,7 +198,7 @@ func parseJSONFields(record *apiv1.ServerRecord, repositoryJSON, packagesJSON, r
}
// GetByID retrieves a single ServerRecord by its registry metadata ID
func (db *PostgreSQL) GetByID(ctx context.Context, id string) (*apiv1.ServerRecord, error) {
func (db *PostgreSQL) GetByID(ctx context.Context, id string) (*apiv0.ServerRecord, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
@ -212,7 +212,7 @@ func (db *PostgreSQL) GetByID(ctx context.Context, id string) (*apiv1.ServerReco
WHERE se.id = $1
`
var record apiv1.ServerRecord
var record apiv0.ServerRecord
var repositoryJSON, packagesJSON, remotesJSON, publisherExtensionsJSON []byte
var publishedAt, updatedAt, releaseDate time.Time
@ -278,7 +278,7 @@ func (db *PostgreSQL) GetByID(ctx context.Context, id string) (*apiv1.ServerReco
}
// Publish adds a new server to the database with separated server.json and extensions
func (db *PostgreSQL) Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv1.RegistryExtensions) (*apiv1.ServerRecord, error) {
func (db *PostgreSQL) Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerRecord, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
@ -360,10 +360,10 @@ func (db *PostgreSQL) Publish(ctx context.Context, serverDetail model.ServerJSON
}
// Create and return the ServerRecord
record := &apiv1.ServerRecord{
Server: serverDetail,
XIOModelContextProtocolRegistry: registryMetadata,
XPublisher: publisherExtensions,
record := &apiv0.ServerRecord{
Server: serverDetail,
XIOModelContextProtocolRegistry: registryMetadata,
XPublisher: publisherExtensions,
}
return record, nil
@ -409,7 +409,7 @@ func (db *PostgreSQL) ImportSeed(ctx context.Context, seedFilePath string) error
}
// publishWithTransaction handles publishing within an existing transaction, optionally with predefined metadata
func (db *PostgreSQL) publishWithTransaction(ctx context.Context, tx pgx.Tx, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, existingMetadata *apiv1.RegistryExtensions) error {
func (db *PostgreSQL) publishWithTransaction(ctx context.Context, tx pgx.Tx, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, existingMetadata *apiv0.RegistryExtensions) error {
// Use the same ID for both server and server_extensions (1:1 relationship)
var id string
if existingMetadata != nil && existingMetadata.ID != "" {
@ -531,7 +531,7 @@ func (db *PostgreSQL) UpdateLatestFlag(ctx context.Context, id string, isLatest
}
// UpdateServer updates an existing server record with new server details
func (db *PostgreSQL) UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv1.ServerRecord, error) {
func (db *PostgreSQL) UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerRecord, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}