Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/registry/converters/registry_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (
"github.com/stacklok/toolhive/pkg/registry/types"
)

// NewServerRegistryFromUpstream creates a ServerRegistry from upstream ServerJSON array.
// NewUpstreamRegistryFromUpstreamServers creates a UpstreamRegistry from upstream ServerJSON array.
// This is used when ingesting data from upstream MCP Registry API endpoints.
func NewServerRegistryFromUpstream(servers []upstreamv0.ServerJSON) *types.ServerRegistry {
return &types.ServerRegistry{
func NewUpstreamRegistryFromUpstreamServers(servers []upstreamv0.ServerJSON) *types.UpstreamRegistry {
return &types.UpstreamRegistry{
Version: "1.0.0",
LastUpdated: time.Now().Format(time.RFC3339),
Servers: servers,
}
}

// NewServerRegistryFromToolhive creates a ServerRegistry from ToolHive Registry.
// NewUpstreamRegistryFromToolhiveRegistry creates a UpstreamRegistry from ToolHive Registry.
// This converts ToolHive format to upstream ServerJSON using the converters package.
// Used when ingesting data from ToolHive-format sources (Git, File, API).
func NewServerRegistryFromToolhive(toolhiveReg *types.Registry) (*types.ServerRegistry, error) {
func NewUpstreamRegistryFromToolhiveRegistry(toolhiveReg *types.Registry) (*types.UpstreamRegistry, error) {
if toolhiveReg == nil {
return nil, fmt.Errorf("toolhive registry cannot be nil")
}
Expand All @@ -47,7 +47,7 @@ func NewServerRegistryFromToolhive(toolhiveReg *types.Registry) (*types.ServerRe
servers = append(servers, *serverJSON)
}

return &types.ServerRegistry{
return &types.UpstreamRegistry{
Version: toolhiveReg.Version,
LastUpdated: toolhiveReg.LastUpdated,
Servers: servers,
Expand Down
24 changes: 12 additions & 12 deletions pkg/registry/converters/registry_converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
"github.com/stacklok/toolhive/pkg/registry/types"
)

func TestNewServerRegistryFromToolhive(t *testing.T) {
func TestNewUpstreamRegistryFromToolhiveRegistry(t *testing.T) {
t.Parallel()

tests := []struct {
name string
toolhiveReg *types.Registry
expectError bool
validate func(*testing.T, *types.ServerRegistry)
validate func(*testing.T, *types.UpstreamRegistry)
}{
{
name: "successful conversion with container servers",
Expand All @@ -42,7 +42,7 @@ func TestNewServerRegistryFromToolhive(t *testing.T) {
RemoteServers: make(map[string]*types.RemoteServerMetadata),
},
expectError: false,
validate: func(t *testing.T, sr *types.ServerRegistry) {
validate: func(t *testing.T, sr *types.UpstreamRegistry) {
t.Helper()
assert.Equal(t, "1.0.0", sr.Version)
assert.Equal(t, "2024-01-01T00:00:00Z", sr.LastUpdated)
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestNewServerRegistryFromToolhive(t *testing.T) {
},
},
expectError: false,
validate: func(t *testing.T, sr *types.ServerRegistry) {
validate: func(t *testing.T, sr *types.UpstreamRegistry) {
t.Helper()
assert.Len(t, sr.Servers, 1)
assert.Contains(t, sr.Servers[0].Name, "remote-server")
Expand All @@ -87,7 +87,7 @@ func TestNewServerRegistryFromToolhive(t *testing.T) {
RemoteServers: make(map[string]*types.RemoteServerMetadata),
},
expectError: false,
validate: func(t *testing.T, sr *types.ServerRegistry) {
validate: func(t *testing.T, sr *types.UpstreamRegistry) {
t.Helper()
assert.Empty(t, sr.Servers)
},
Expand All @@ -98,7 +98,7 @@ func TestNewServerRegistryFromToolhive(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result, err := NewServerRegistryFromToolhive(tt.toolhiveReg)
result, err := NewUpstreamRegistryFromToolhiveRegistry(tt.toolhiveReg)

if tt.expectError {
assert.Error(t, err)
Expand All @@ -114,13 +114,13 @@ func TestNewServerRegistryFromToolhive(t *testing.T) {
}
}

func TestNewServerRegistryFromUpstream(t *testing.T) {
func TestNewUpstreamRegistryFromUpstreamServers(t *testing.T) {
t.Parallel()

tests := []struct {
name string
servers []upstreamv0.ServerJSON
validate func(*testing.T, *types.ServerRegistry)
validate func(*testing.T, *types.UpstreamRegistry)
}{
{
name: "create from upstream servers",
Expand All @@ -139,7 +139,7 @@ func TestNewServerRegistryFromUpstream(t *testing.T) {
},
},
},
validate: func(t *testing.T, sr *types.ServerRegistry) {
validate: func(t *testing.T, sr *types.UpstreamRegistry) {
t.Helper()
assert.Equal(t, "1.0.0", sr.Version)
assert.NotEmpty(t, sr.LastUpdated)
Expand All @@ -150,7 +150,7 @@ func TestNewServerRegistryFromUpstream(t *testing.T) {
{
name: "create from empty slice",
servers: []upstreamv0.ServerJSON{},
validate: func(t *testing.T, sr *types.ServerRegistry) {
validate: func(t *testing.T, sr *types.UpstreamRegistry) {
t.Helper()
assert.Empty(t, sr.Servers)
},
Expand All @@ -161,7 +161,7 @@ func TestNewServerRegistryFromUpstream(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result := NewServerRegistryFromUpstream(tt.servers)
result := NewUpstreamRegistryFromUpstreamServers(tt.servers)

assert.NotNil(t, result)
if tt.validate != nil {
Expand All @@ -183,7 +183,7 @@ func TestNewServerRegistryFromUpstream_DefaultValues(t *testing.T) {
},
}

result := NewServerRegistryFromUpstream(servers)
result := NewUpstreamRegistryFromUpstreamServers(servers)

// Verify defaults
assert.Equal(t, "1.0.0", result.Version)
Expand Down
4 changes: 2 additions & 2 deletions pkg/registry/types/upstream_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
upstreamv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
)

// ServerRegistry is the unified internal registry format.
// UpstreamRegistry is the unified internal registry format.
// It stores servers in upstream ServerJSON format while maintaining
// ToolHive-compatible metadata fields for backward compatibility.
type ServerRegistry struct {
type UpstreamRegistry struct {
// Version is the schema version (ToolHive compatibility)
Version string `json:"version"`

Expand Down
Loading