Documentation
¶
Index ¶
- Constants
- func GetBaseDirFromContext(ctx context.Context) string
- func Register(resourceType string, factory ResourceConfigFactory) bool
- func RegisterTemplate(resourceType string, factory ResourceTemplateConfigFactory) bool
- type AudienceRole
- type CSPConfig
- type ConfigBase
- func (c ConfigBase) GetAnnotations() *ResourceAnnotations
- func (c ConfigBase) GetDescription() string
- func (c ConfigBase) GetMimeType() string
- func (c ConfigBase) GetName() string
- func (c ConfigBase) GetResourceUIMetadata() any
- func (c ConfigBase) GetTitle() string
- func (c ConfigBase) IsUI() bool
- func (c *ConfigBase) SetDefaults()
- func (c *ConfigBase) Validate() error
- type PermissionsConfig
- type Resource
- type ResourceAnnotations
- type ResourceConfig
- type ResourceConfigBase
- type ResourceConfigFactory
- type ResourceTemplate
- type ResourceTemplateConfig
- type ResourceTemplateConfigBase
- type ResourceTemplateConfigFactory
- type ResourceUIMetadata
Constants ¶
const BaseDirKey contextKey = "baseDir"
BaseDirKey is the context key for storing the base directory path during config parsing.
const UIMimeType = "text/html;profile=mcp-app"
UIMimeType is the required MIME type for MCP Apps UI resources.
Variables ¶
This section is empty.
Functions ¶
func GetBaseDirFromContext ¶
GetBaseDirFromContext extracts the base directory path from the context.
func Register ¶
func Register(resourceType string, factory ResourceConfigFactory) bool
Register allows individual resource packages to register their configuration factory function. It returns true if the registration was successful, and false if the factory is nil or a resource with the same type was already registered.
func RegisterTemplate ¶
func RegisterTemplate(resourceType string, factory ResourceTemplateConfigFactory) bool
RegisterTemplate allows individual resource packages to register their template configuration factory function. It returns true if the registration was successful, and false if the factory is nil or a template with the same type was already registered.
Types ¶
type AudienceRole ¶
type AudienceRole string
const ( RoleUser AudienceRole = "user" RoleAssistant AudienceRole = "assistant" )
func (*AudienceRole) UnmarshalYAML ¶
func (r *AudienceRole) UnmarshalYAML(b []byte) error
type CSPConfig ¶
type CSPConfig struct {
ConnectDomains []string `yaml:"connectDomains,omitempty" json:"connectDomains,omitempty"`
ResourceDomains []string `yaml:"resourceDomains,omitempty" json:"resourceDomains,omitempty"`
FrameDomains []string `yaml:"frameDomains,omitempty" json:"frameDomains,omitempty"`
BaseUriDomains []string `yaml:"baseUriDomains,omitempty" json:"baseUriDomains,omitempty"`
}
CSPConfig defines allowed external origins for the UI Resource.
type ConfigBase ¶
type ConfigBase struct {
Name string `yaml:"name" validate:"required"`
Type string `yaml:"type" validate:"required"`
Description string `yaml:"description,omitempty"`
Title string `yaml:"title,omitempty"`
MimeType string `yaml:"mimeType,omitempty"`
Annotations *ResourceAnnotations `yaml:"annotations,omitempty"`
UI bool `yaml:"ui,omitempty"`
CSP *CSPConfig `yaml:"csp,omitempty"`
Permissions *PermissionsConfig `yaml:"permissions,omitempty"`
Domain string `yaml:"domain,omitempty"`
PrefersBorder *bool `yaml:"prefersBorder,omitempty"`
}
ConfigBase contains the common fields for all resource and template configurations.
func (ConfigBase) GetAnnotations ¶
func (c ConfigBase) GetAnnotations() *ResourceAnnotations
func (ConfigBase) GetDescription ¶
func (c ConfigBase) GetDescription() string
GetDescription returns the description of the resource or template.
func (ConfigBase) GetMimeType ¶
func (c ConfigBase) GetMimeType() string
GetMimeType returns the MIME type of the resource or template.
func (ConfigBase) GetName ¶
func (c ConfigBase) GetName() string
GetName returns the name of the resource or template.
func (ConfigBase) GetResourceUIMetadata ¶
func (c ConfigBase) GetResourceUIMetadata() any
GetResourceUIMetadata returns the UI metadata conforming to the MCP Ext-Apps specification.
func (ConfigBase) GetTitle ¶
func (c ConfigBase) GetTitle() string
GetTitle returns the title of the resource or template.
func (ConfigBase) IsUI ¶
func (c ConfigBase) IsUI() bool
IsUI returns whether the resource or template is configured as an interactive UI application.
func (*ConfigBase) SetDefaults ¶
func (c *ConfigBase) SetDefaults()
SetDefaults applies system defaults (like priority=1.0) for unspecified optional fields.
func (*ConfigBase) Validate ¶
func (c *ConfigBase) Validate() error
Validate performs base configuration validation, including validating the MIME type, checking for duplicate audiences, and validating the lastModified timestamp format.
type PermissionsConfig ¶
type PermissionsConfig struct {
Camera *bool `yaml:"camera,omitempty"`
Microphone *bool `yaml:"microphone,omitempty"`
Geolocation *bool `yaml:"geolocation,omitempty"`
ClipboardWrite *bool `yaml:"clipboardWrite,omitempty"`
}
PermissionsConfig defines browser device permissions requested by the UI Resource.
func (*PermissionsConfig) ToUIMetadata ¶
func (p *PermissionsConfig) ToUIMetadata() map[string]any
ToUIMetadata converts PermissionsConfig to _meta.ui.permissions format.
func (*PermissionsConfig) UnmarshalYAML ¶
func (p *PermissionsConfig) UnmarshalYAML(b []byte) error
UnmarshalYAML parses a list of permission names: [camera, microphone, geolocation, clipboardWrite] and maps each entry to true on the PermissionsConfig struct.
type Resource ¶
type Resource interface {
GetName() string
GetTitle() string
GetDescription() string
GetMimeType() string
GetAnnotations() *ResourceAnnotations
GetURI() string
GetSize() *int64
Read(ctx context.Context, params map[string]any) (any, error)
ToConfig() ResourceConfig
GetResourceUIMetadata() any
IsUI() bool
}
Resource is the initialized object that handles data execution.
type ResourceAnnotations ¶
type ResourceAnnotations struct {
Priority *float64 `yaml:"priority,omitempty"`
Audience []AudienceRole `yaml:"audience,omitempty"`
LastModified string `yaml:"lastModified,omitempty"`
}
type ResourceConfig ¶
type ResourceConfig interface {
ResourceConfigType() string
GetURI() string
SetDefaults()
Validate() error
Initialize(ctx context.Context) (Resource, error)
}
ResourceConfig represents the uninitialized configuration for a resource.
func DecodeConfig ¶
func DecodeConfig(ctx context.Context, resourceType, name string, decoder *yaml.Decoder) (ResourceConfig, error)
DecodeConfig decodes a YAML document into the appropriate ResourceConfig implementation.
type ResourceConfigBase ¶
type ResourceConfigBase struct {
ConfigBase `yaml:",inline"`
URI string `yaml:"uri,omitempty" validate:"omitempty,uri"`
}
ResourceConfigBase contains the fields for a specific resource configuration.
func (ResourceConfigBase) GetURI ¶
func (c ResourceConfigBase) GetURI() string
GetURI returns the URI of the resource configuration.
func (*ResourceConfigBase) Validate ¶
func (c *ResourceConfigBase) Validate() error
Validate performs resource-specific validation including URI scheme checks.
type ResourceConfigFactory ¶
type ResourceConfigFactory func(ctx context.Context, name string, decoder *yaml.Decoder) (ResourceConfig, error)
ResourceConfigFactory defines the signature for a function that creates and decodes a specific resource's configuration.
type ResourceTemplate ¶
type ResourceTemplate interface {
GetName() string
GetTitle() string
GetDescription() string
GetMimeType() string
GetAnnotations() *ResourceAnnotations
GetURITemplate() string
Read(ctx context.Context, params map[string]any) (any, error)
ToConfig() ResourceTemplateConfig
GetResourceUIMetadata() any
IsUI() bool
}
ResourceTemplate is the initialized object that handles data execution.
type ResourceTemplateConfig ¶
type ResourceTemplateConfig interface {
ResourceTemplateConfigType() string
GetURITemplate() string
SetDefaults()
Validate() error
Initialize(ctx context.Context) (ResourceTemplate, error)
}
ResourceTemplateConfig represents the uninitialized configuration for a resource template.
func DecodeTemplateConfig ¶
func DecodeTemplateConfig(ctx context.Context, resourceType, name string, decoder *yaml.Decoder) (ResourceTemplateConfig, error)
DecodeTemplateConfig looks up the registered factory for the given type and uses it to decode the resource template configuration.
type ResourceTemplateConfigBase ¶
type ResourceTemplateConfigBase struct {
ConfigBase `yaml:",inline"`
URITemplate string `yaml:"uriTemplate" validate:"required"`
}
ResourceTemplateConfigBase contains the specific fields for resource template configurations.
func (ResourceTemplateConfigBase) GetURITemplate ¶
func (c ResourceTemplateConfigBase) GetURITemplate() string
GetURITemplate returns the URI template of the resource configuration.
func (*ResourceTemplateConfigBase) Validate ¶
func (c *ResourceTemplateConfigBase) Validate() error
Validate performs base configuration validation for resource templates.
type ResourceTemplateConfigFactory ¶
type ResourceTemplateConfigFactory func(ctx context.Context, name string, decoder *yaml.Decoder) (ResourceTemplateConfig, error)
ResourceTemplateConfigFactory defines the signature for a function that creates and decodes a specific resource template's configuration.
type ResourceUIMetadata ¶
type ResourceUIMetadata struct {
CSP *CSPConfig `yaml:"csp,omitempty" json:"csp,omitempty"`
Permissions map[string]any `yaml:"permissions,omitempty" json:"permissions,omitempty"`
Domain string `yaml:"domain,omitempty" json:"domain,omitempty"`
PrefersBorder *bool `yaml:"prefersBorder,omitempty" json:"prefersBorder,omitempty"`
}
ResourceUIMetadata represents the metadata for a UI Resource.