Skip to content

Conversation

@domdomegg
Copy link
Member

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).

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 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
- Add comprehensive test cases for icon validation
- Add example icon to seed.json (Airtable server)
- Change websiteUrl validation to HTTPS-only for consistency

The implementation uses two-layer validation:
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
@domdomegg domdomegg merged commit 66993e9 into main Oct 7, 2025
6 checks passed
@domdomegg domdomegg deleted the adamj/add-icon-support branch October 7, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants