refactor: consolidate server list response types (#387)

## Summary
- Consolidate ServerListResponse and Metadata types into pkg/api/v0
- Remove duplication between handler and API types
- Change metadata from optional pointer to required value
- Remove unused Total field from Metadata
This commit is contained in:
adam jones 2025-09-09 04:47:27 -07:00 • committed by GitHub
commit 0eada9b3b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,13 +12,6 @@ import (
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
)
// Metadata contains pagination metadata
type Metadata struct {
NextCursor string `json:"next_cursor,omitempty"`
Count int `json:"count,omitempty"`
Total int `json:"total,omitempty"`
}
// ListServersInput represents the input for listing servers
type ListServersInput struct {
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 {
Version string `query:"version" doc:"Filter by version ('latest' for latest version, or an exact version like '1.2.3')" required:"false" example:"latest"`
}
// ListServersBody represents the paginated server list response body
type ListServersBody struct {
Servers []apiv0.ServerJSON `json:"servers" doc:"List of MCP servers with extensions"`
Metadata *Metadata `json:"metadata,omitempty" doc:"Pagination metadata"`
}
// ServerDetailInput represents the input for getting server details
type ServerDetailInput struct {
ID string `path:"id" doc:"Server ID (UUID)" format:"uuid"`
@ -49,7 +36,7 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
Summary: "List MCP servers",
Description: "Get a paginated list of MCP servers from the registry",
Tags: []string{"servers"},
}, func(_ context.Context, input *ListServersInput) (*Response[ListServersBody], error) {
}, func(_ context.Context, input *ListServersInput) (*Response[apiv0.ServerListResponse], error) {
// Validate cursor if provided
if input.Cursor != "" {
_, err := uuid.Parse(input.Cursor)
@ -94,21 +81,14 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
return nil, huma.Error500InternalServerError("Failed to get registry list", err)
}
// Build response body
body := ListServersBody{
Servers: servers,
}
// Add metadata if there's a next cursor
if nextCursor != "" {
body.Metadata = &Metadata{
NextCursor: nextCursor,
Count: len(servers),
}
}
return &Response[ListServersBody]{
Body: body,
return &Response[apiv0.ServerListResponse]{
Body: apiv0.ServerListResponse{
Servers: servers,
Metadata: apiv0.Metadata{
NextCursor: nextCursor,
Count: len(servers),
},
},
}, nil
})