Documentation
¶
Overview ¶
Package validators provides validation functions for MCP Registry Server entities.
Index ¶
- func DeserializeArguments(data []byte) []model.Argument
- func IsValidServerName(name string) bool
- func SerializeArguments(arguments []model.Argument) ([]byte, error)
- func SerializeServerMeta(meta *upstreamv0.ServerMeta, maxMetaSize int) ([]byte, error)
- func ValidateServerName(name string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeserializeArguments ¶ added in v1.5.1
DeserializeArguments reconstructs a slice of model.Argument from JSONB bytes.
Malformed or absent data degrades to an empty slice rather than an error: a single malformed row must not fail a whole listing. This mirrors how environment variables and transport headers are read back.
A flat array of strings is also accepted. Binaries older than migration 000023 stored arguments as bare flag names, and one writing to the migrated JSONB column lands a value like ["--url","--timeout",""]. Recovering the names is strictly better than discarding the row, though the upgrade is documented as stop-the-world precisely so this path should not be reached.
func IsValidServerName ¶
IsValidServerName checks if a server name is valid according to the MCP Registry specification. Returns true if valid, false otherwise. This is a convenience wrapper around ValidateServerName for boolean checks.
func SerializeArguments ¶ added in v1.5.1
SerializeArguments serializes a slice of model.Argument to JSON bytes for storage in a JSONB column. The full object is preserved — value, type, default, valueHint, variables and the rest — rather than just the flag name.
Empty and nil input both serialize to an empty JSON array so the column never holds a JSON `null`.
func SerializeServerMeta ¶ added in v0.6.0
func SerializeServerMeta(meta *upstreamv0.ServerMeta, maxMetaSize int) ([]byte, error)
SerializeServerMeta serializes the publisher-provided metadata to JSON bytes for storage. maxMetaSize specifies the maximum allowed size in bytes and must be greater than zero.
func ValidateServerName ¶
ValidateServerName validates a server name according to the MCP Registry specification. The name must be in reverse-DNS format: namespace/name Returns the validated name (trimmed) and an error if validation fails.
Format requirements: - Must contain exactly one '/' separator - Namespace (before /): [a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9] - Name (after /): [a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9] - Total length: 3-200 characters
Examples of valid names:
- com.toolhive.k8s.default/weather-service (K8s auto-discovered)
- com.example/server (manually published)
- org.stacklok.toolhive/my-server (manually published)
- com.example/test_server (manually published - underscores allowed in name part)
Examples of invalid names:
- my-server (missing slash)
- com.example//server (multiple slashes)
- .example/server (namespace starts with dot)
- com.example/server- (name ends with dash)
Types ¶
This section is empty.