Deduplicate server JSON structs between publisher and registry (#318)
<!-- Provide a brief summary of your changes --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> The following PR eliminates duplicate struct definitions by migrating the publisher tool to use canonical types from pkg/model, creating a single source of truth across the codebase. The publisher tool previously had its own copies of structs that were duplicated, ie. ServerJSON, Package, Repository, VersionDetail, EnvironmentVariable, RuntimeArgument and a few others which was not optimal **Changes in the PR:** - Refactored the structs to single canonical types located at pkg/model - Refactor the implementation to use/build canonical structures directly - Remove all duplicate definitions (5 structs eliminated) - Publisher now uses model.ServerJSON, model.Package, model.Repository, etc. - Renamed some of the structs to better reflect their use case, i.e. ServerJSON instead of ServerDetail - Fixes an issue where the Remote property was missing from the previous publisher copy of the Server **Benefits:** - Single source of truth - Schema changes in one place - Type safety - Compiler catches mismatches - Enhanced validation - Field constraints and bson tags - Zero breaking changes - Same CLI interface and JSON output - Future-proof - New canonical fields automatically available Supersedes: #217 and #240 ## How Has This Been Tested? <!-- Have you tested this in a real application? Which scenarios were tested? --> Locally ## Breaking Changes <!-- Will users need to update their code or configurations? --> No ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [ ] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [ ] My code follows the repository's style guidelines - [ ] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> --------- Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
This commit is contained in:
parent
9d04671ee3
commit
099a2d702e
2 changed files with 1280 additions and 1408 deletions
42
pkg/api/v1/types.go
Normal file
42
pkg/api/v1/types.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||
)
|
||||
|
||||
// RegistryExtensions represents registry-generated metadata
|
||||
type RegistryExtensions struct {
|
||||
ID string `json:"id" bson:"_id"`
|
||||
PublishedAt time.Time `json:"published_at" bson:"published_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty" bson:"updated_at,omitempty"`
|
||||
IsLatest bool `json:"is_latest" bson:"is_latest"`
|
||||
ReleaseDate string `json:"release_date" bson:"release_date"`
|
||||
}
|
||||
|
||||
// ServerRecord represents the unified storage and API response model
|
||||
type ServerRecord struct {
|
||||
Server model.ServerJSON `json:"server" bson:"server"` // Pure MCP server.json
|
||||
XIOModelContextProtocolRegistry RegistryExtensions `json:"x-io.modelcontextprotocol.registry,omitempty" bson:"registry_extensions"` // Registry-generated data
|
||||
XPublisher map[string]interface{} `json:"x-publisher,omitempty" bson:"publisher_extensions"` // x-publisher extensions
|
||||
}
|
||||
|
||||
// ServerListResponse represents the paginated server list response
|
||||
type ServerListResponse struct {
|
||||
Servers []ServerRecord `json:"servers"`
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
// PublishRequest represents the API request format for publishing servers
|
||||
type PublishRequest struct {
|
||||
Server model.ServerJSON `json:"server"`
|
||||
XPublisher map[string]interface{} `json:"x-publisher,omitempty"`
|
||||
}
|
||||
|
||||
// Metadata represents pagination metadata
|
||||
type Metadata struct {
|
||||
NextCursor string `json:"next_cursor,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Total int `json:"total,omitempty"`
|
||||
}
|
||||
107
pkg/model/types.go
Normal file
107
pkg/model/types.go
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
package model
|
||||
|
||||
// Status represents the lifecycle status of a server
|
||||
type Status string
|
||||
|
||||
const (
|
||||
StatusActive Status = "active"
|
||||
StatusDeprecated Status = "deprecated"
|
||||
StatusDeleted Status = "deleted"
|
||||
)
|
||||
|
||||
// ServerJSON represents complete server information as defined in the MCP spec (pure, no registry metadata)
|
||||
type ServerJSON struct {
|
||||
Schema string `json:"$schema,omitempty" bson:"$schema,omitempty"`
|
||||
Name string `json:"name" minLength:"1" maxLength:"200" bson:"name"`
|
||||
Description string `json:"description" minLength:"1" maxLength:"100" bson:"description"`
|
||||
Status Status `json:"status,omitempty" minLength:"1" bson:"status,omitempty"`
|
||||
Repository Repository `json:"repository,omitempty" bson:"repository"`
|
||||
VersionDetail VersionDetail `json:"version_detail" bson:"version_detail"`
|
||||
Packages []Package `json:"packages,omitempty" bson:"packages,omitempty"`
|
||||
Remotes []Remote `json:"remotes,omitempty" bson:"remotes,omitempty"`
|
||||
}
|
||||
|
||||
// Package represents a package configuration
|
||||
type Package struct {
|
||||
// RegistryType indicates how to download packages (e.g., "npm", "pypi", "docker-hub", "mcpb")
|
||||
RegistryType string `json:"registry_type,omitempty" bson:"registry_type,omitempty"`
|
||||
// RegistryBaseURL is the base URL of the package registry
|
||||
RegistryBaseURL string `json:"registry_base_url,omitempty" bson:"registry_base_url,omitempty"`
|
||||
// Identifier is the package identifier - either a package name (for registries) or URL (for direct downloads)
|
||||
Identifier string `json:"identifier,omitempty" bson:"identifier,omitempty"`
|
||||
Version string `json:"version,omitempty" bson:"version,omitempty"`
|
||||
FileSHA256 string `json:"file_sha256,omitempty" bson:"file_sha256,omitempty"`
|
||||
RunTimeHint string `json:"runtime_hint,omitempty" bson:"runtime_hint,omitempty"`
|
||||
RuntimeArguments []Argument `json:"runtime_arguments,omitempty" bson:"runtime_arguments,omitempty"`
|
||||
PackageArguments []Argument `json:"package_arguments,omitempty" bson:"package_arguments,omitempty"`
|
||||
EnvironmentVariables []KeyValueInput `json:"environment_variables,omitempty" bson:"environment_variables,omitempty"`
|
||||
}
|
||||
|
||||
// Remote represents a remote connection endpoint
|
||||
type Remote struct {
|
||||
TransportType string `json:"transport_type" bson:"transport_type"`
|
||||
URL string `json:"url" format:"uri" bson:"url"`
|
||||
Headers []KeyValueInput `json:"headers,omitempty" bson:"headers,omitempty"`
|
||||
}
|
||||
|
||||
// Repository represents a source code repository as defined in the spec
|
||||
type Repository struct {
|
||||
URL string `json:"url" bson:"url"`
|
||||
Source string `json:"source" bson:"source"`
|
||||
ID string `json:"id,omitempty" bson:"id,omitempty"`
|
||||
}
|
||||
|
||||
// Format represents the input format type
|
||||
type Format string
|
||||
|
||||
const (
|
||||
FormatString Format = "string"
|
||||
FormatNumber Format = "number"
|
||||
FormatBoolean Format = "boolean"
|
||||
FormatFilePath Format = "file_path"
|
||||
)
|
||||
|
||||
// Input represents a configuration input
|
||||
type Input struct {
|
||||
Description string `json:"description,omitempty" bson:"description,omitempty"`
|
||||
IsRequired bool `json:"is_required,omitempty" bson:"is_required,omitempty"`
|
||||
Format Format `json:"format,omitempty" bson:"format,omitempty"`
|
||||
Value string `json:"value,omitempty" bson:"value,omitempty"`
|
||||
IsSecret bool `json:"is_secret,omitempty" bson:"is_secret,omitempty"`
|
||||
Default string `json:"default,omitempty" bson:"default,omitempty"`
|
||||
Choices []string `json:"choices,omitempty" bson:"choices,omitempty"`
|
||||
}
|
||||
|
||||
// InputWithVariables represents an input that can contain variables
|
||||
type InputWithVariables struct {
|
||||
Input `json:",inline" bson:",inline"`
|
||||
Variables map[string]Input `json:"variables,omitempty" bson:"variables,omitempty"`
|
||||
}
|
||||
|
||||
// KeyValueInput represents a named input with variables
|
||||
type KeyValueInput struct {
|
||||
InputWithVariables `json:",inline" bson:",inline"`
|
||||
Name string `json:"name" bson:"name"`
|
||||
}
|
||||
|
||||
// ArgumentType represents the type of argument
|
||||
type ArgumentType string
|
||||
|
||||
const (
|
||||
ArgumentTypePositional ArgumentType = "positional"
|
||||
ArgumentTypeNamed ArgumentType = "named"
|
||||
)
|
||||
|
||||
// Argument defines a type that can be either a PositionalArgument or a NamedArgument
|
||||
type Argument struct {
|
||||
InputWithVariables `json:",inline" bson:",inline"`
|
||||
Type ArgumentType `json:"type" bson:"type"`
|
||||
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||
IsRepeated bool `json:"is_repeated,omitempty" bson:"is_repeated,omitempty"`
|
||||
ValueHint string `json:"value_hint,omitempty" bson:"value_hint,omitempty"`
|
||||
}
|
||||
|
||||
// VersionDetail represents the version details of a server (pure MCP spec, no registry metadata)
|
||||
type VersionDetail struct {
|
||||
Version string `json:"version" bson:"version"`
|
||||
}
|
||||
Loading…
Reference in a new issue