Add icon support to server.json schema (#620)

Implements icon support based on the Model Context Protocol
specification, allowing servers to specify display icons with optional
size, MIME type, and theme variants.

## Changes

- Add `Icon` type to `pkg/model/types.go` with struct tags for automatic
API validation
- Add `icons` field to `ServerJSON` in `pkg/api/v0/types.go`
- Add icon validation in `internal/validators/validators.go`:
  - Only HTTPS URLs allowed (no HTTP or data URIs)
  - Maximum URL length of 255 characters
  - Validates absolute URLs with proper scheme
- Update JSON schema and OpenAPI documentation with Icon definitions
- Add comprehensive test cases for icon validation
- Add example icon to seed.json (Airtable server)
- Change `websiteUrl` validation to HTTPS-only for consistency

## Implementation Details

The implementation uses a two-layer validation architecture:

1. **Huma framework** validates struct tags (`required`, `maxLength`,
`enum`, `pattern`) and returns 422 for violations
2. **Custom validators** handle business logic (HTTPS scheme
requirement, absolute URL requirement) and return 400 for violations

This approach leverages Huma's automatic validation while keeping
business-specific rules in the validator layer.

## Icon Field Specification

- `src` (required): HTTPS URL to icon resource, max 255 characters
- `mimeType` (optional): One of `image/png`, `image/jpeg`, `image/jpg`,
`image/svg+xml`, `image/webp`
- `sizes` (optional): Array of size strings in "WxH" format or "any" for
scalable formats
- `theme` (optional): Either "light" or "dark" to indicate intended
background

Multiple icons can be provided (e.g., for different themes or sizes).
This commit is contained in:
adam jones 2025-10-07 13:30:32 +01:00 • committed by GitHub
commit 66993e9121
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -90,3 +90,18 @@ type Argument struct {
IsRepeated bool `json:"isRepeated,omitempty"`
ValueHint string `json:"valueHint,omitempty"`
}
// Icon represents an optionally-sized icon that can be displayed in a user interface
type Icon struct {
// Src is a standard URI pointing to an icon resource (HTTPS URL only for registry)
Src string `json:"src" required:"true" format:"uri" maxLength:"255"`
// MimeType is an optional MIME type override if the source MIME type is missing or generic
MimeType *string `json:"mimeType,omitempty" enum:"image/png,image/jpeg,image/jpg,image/svg+xml,image/webp"`
// Sizes is an optional array of strings that specify sizes at which the icon can be used
// Each string should be in WxH format (e.g., "48x48", "96x96") or "any" for scalable formats
Sizes []string `json:"sizes,omitempty" pattern:"^(\\d+x\\d+|any)$"`
// Theme is an optional specifier for the theme this icon is designed for
// "light" indicates the icon is designed for light backgrounds
// "dark" indicates the icon is designed for dark backgrounds
Theme *string `json:"theme,omitempty" enum:"light,dark"`
}