Documentation
¶
Overview ¶
Package serverjson provides utilities for reading, modifying, and writing individual server.json files, with support for extracting and updating ToolHive-specific extensions in the _meta section.
Index ¶
- type Scanner
- type ServerEntry
- type ServerFile
- func (sf *ServerFile) ExtensionKey() (string, error)
- func (sf *ServerFile) GetExtensions() (*registry.ServerExtensions, error)
- func (sf *ServerFile) IsPackageServer() bool
- func (sf *ServerFile) IsRemoteServer() bool
- func (sf *ServerFile) MetaSize() int
- func (sf *ServerFile) RepositoryURL() string
- func (sf *ServerFile) UpdateExtensions(ext *registry.ServerExtensions) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner walks a registries directory to find and sort server.json files.
func NewScanner ¶
NewScanner creates a Scanner rooted at the given registries directory.
func (*Scanner) FindOldestServers ¶
func (s *Scanner) FindOldestServers(count int) ([]ServerEntry, error)
FindOldestServers returns the N server.json entries with the oldest LastUpdated timestamps. Entries with missing or empty LastUpdated are treated as epoch (selected first). Malformed files are logged and skipped.
type ServerEntry ¶
ServerEntry represents a server.json file with its path and last-updated timestamp.
type ServerFile ¶
type ServerFile struct {
// Path is the filesystem path to the server.json file.
Path string
// ServerJSON is the parsed upstream ServerJSON structure.
ServerJSON upstream.ServerJSON
// contains filtered or unexported fields
}
ServerFile represents a loaded server.json with its file path and parsed data.
func LoadServerFile ¶
func LoadServerFile(path string) (*ServerFile, error)
LoadServerFile reads and parses a server.json from the given path.
func (*ServerFile) ExtensionKey ¶
func (sf *ServerFile) ExtensionKey() (string, error)
ExtensionKey returns the key used inside the publisher namespace. For OCI packages this is the image identifier (e.g. "ghcr.io/org/image:tag"). For remote servers this is the URL (e.g. "https://api.example.com/mcp").
func (*ServerFile) GetExtensions ¶
func (sf *ServerFile) GetExtensions() (*registry.ServerExtensions, error)
GetExtensions extracts the ServerExtensions for this server. It navigates: _meta → publisher-provided → io.github.stacklok → <key> and deserializes into registry.ServerExtensions.
func (*ServerFile) IsPackageServer ¶
func (sf *ServerFile) IsPackageServer() bool
IsPackageServer returns true if this server.json defines OCI package(s).
func (*ServerFile) IsRemoteServer ¶
func (sf *ServerFile) IsRemoteServer() bool
IsRemoteServer returns true if this server.json defines remote server(s).
func (*ServerFile) MetaSize ¶
func (sf *ServerFile) MetaSize() int
MetaSize returns the size in bytes of the _meta field when serialized as JSON. Returns 0 if there is no _meta field.
func (*ServerFile) RepositoryURL ¶
func (sf *ServerFile) RepositoryURL() string
RepositoryURL returns the repository URL if set, or empty string.
func (*ServerFile) UpdateExtensions ¶
func (sf *ServerFile) UpdateExtensions(ext *registry.ServerExtensions) error
UpdateExtensions writes the modified ServerExtensions back into the server.json. It parses the raw file bytes into a map[string]interface{} to preserve all fields (including unknown ones), replaces only the extension subtree, and writes back with json.MarshalIndent.