Skip to content

Commit 6202aaf

Browse files
committed
refactor: consolidate server list response types
Consolidate ServerListResponse and Metadata types into pkg/api/v0 to reduce duplication and make the API more consistent. Changes metadata from optional pointer to required value and removes unused Total field. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> :house: Remote-Dev: homespace
1 parent 0745bb9 commit 6202aaf

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

internal/api/handlers/v0/servers.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ import (
1212
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
1313
)
1414

15-
// Metadata contains pagination metadata
16-
type Metadata struct {
17-
NextCursor string `json:"next_cursor,omitempty"`
18-
Count int `json:"count,omitempty"`
19-
Total int `json:"total,omitempty"`
20-
}
21-
2215
// ListServersInput represents the input for listing servers
2316
type ListServersInput struct {
2417
Cursor string `query:"cursor" doc:"Pagination cursor (UUID)" format:"uuid" required:"false" example:"550e8400-e29b-41d4-a716-446655440000"`
@@ -28,12 +21,6 @@ type ListServersInput struct {
2821
Version string `query:"version" doc:"Filter by version ('latest' for latest version, or an exact version like '1.2.3')" required:"false" example:"latest"`
2922
}
3023

31-
// ListServersBody represents the paginated server list response body
32-
type ListServersBody struct {
33-
Servers []apiv0.ServerJSON `json:"servers" doc:"List of MCP servers with extensions"`
34-
Metadata *Metadata `json:"metadata,omitempty" doc:"Pagination metadata"`
35-
}
36-
3724
// ServerDetailInput represents the input for getting server details
3825
type ServerDetailInput struct {
3926
ID string `path:"id" doc:"Server ID (UUID)" format:"uuid"`
@@ -49,7 +36,7 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
4936
Summary: "List MCP servers",
5037
Description: "Get a paginated list of MCP servers from the registry",
5138
Tags: []string{"servers"},
52-
}, func(_ context.Context, input *ListServersInput) (*Response[ListServersBody], error) {
39+
}, func(_ context.Context, input *ListServersInput) (*Response[apiv0.ServerListResponse], error) {
5340
// Validate cursor if provided
5441
if input.Cursor != "" {
5542
_, err := uuid.Parse(input.Cursor)
@@ -94,21 +81,14 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
9481
return nil, huma.Error500InternalServerError("Failed to get registry list", err)
9582
}
9683

97-
// Build response body
98-
body := ListServersBody{
99-
Servers: servers,
100-
}
101-
102-
// Add metadata if there's a next cursor
103-
if nextCursor != "" {
104-
body.Metadata = &Metadata{
105-
NextCursor: nextCursor,
106-
Count: len(servers),
107-
}
108-
}
109-
110-
return &Response[ListServersBody]{
111-
Body: body,
84+
return &Response[apiv0.ServerListResponse]{
85+
Body: apiv0.ServerListResponse{
86+
Servers: servers,
87+
Metadata: apiv0.Metadata{
88+
NextCursor: nextCursor,
89+
Count: len(servers),
90+
},
91+
},
11292
}, nil
11393
})
11494

pkg/api/v0/types.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type RegistryExtensions struct {
1717
// ServerListResponse represents the paginated server list response
1818
type ServerListResponse struct {
1919
Servers []ServerJSON `json:"servers"`
20-
Metadata *Metadata `json:"metadata,omitempty"`
20+
Metadata Metadata `json:"metadata"`
2121
}
2222

2323
// ServerMeta represents the structured metadata with known extension fields
@@ -42,6 +42,5 @@ type ServerJSON struct {
4242
// Metadata represents pagination metadata
4343
type Metadata struct {
4444
NextCursor string `json:"next_cursor,omitempty"`
45-
Count int `json:"count,omitempty"`
46-
Total int `json:"total,omitempty"`
45+
Count int `json:"count"`
4746
}

0 commit comments

Comments
 (0)