resources

package
v1.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BaseDirKey contextKey = "baseDir"

BaseDirKey is the context key for storing the base directory path during config parsing.

View Source
const SkillFile = "SKILL.md"

SkillFile is the document at the root of every Agent Skill.

View Source
const SkillScheme = "skill"

SkillScheme is how a resource belonging to an Agent Skill is addressed, as skill://<skill-name>/<path>, whichever resource type backs it.

View Source
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

func GetBaseDirFromContext(ctx context.Context) string

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.

func SkillRoot added in v1.16.0

func SkillRoot(uri string) (string, bool)

SkillRoot returns the skill path of a SKILL.md, and reports whether uri addresses one.

The test reads the raw uri, not the decoded path, so one rule serves both the config validation and the skill registry.

func SkillURISegments added in v1.16.0

func SkillURISegments(raw string) (string, []string, error)

SkillURISegments splits a URI into its scheme and a flat list of path segments, the host first.

func ValidSkillName added in v1.16.0

func ValidSkillName(s string) error

ValidSkillName applies the Agent Skills naming rules.

func ValidateScheme added in v1.16.0

func ValidateScheme(uri, nativeScheme string) error

ValidateScheme checks uri against the schemes a resource may be addressed by: nativeScheme, which is the resource's own type (eg. file), or SkillScheme. The returned error names the accepted set, so callers need only prefix it with the resource they were validating.

func ValidateSkillURI added in v1.16.0

func ValidateSkillURI(uri string) error

ValidateSkillURI applies the SEP-2640 rules to a skill:// URI: a bare path with no empty or relative segments and, for a SKILL.md, a valid skill name as its parent segment. It returns nil for any other scheme.

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.

func (*CSPConfig) Clone added in v1.16.0

func (c *CSPConfig) Clone() *CSPConfig

Clone returns a deep copy of the CSPConfig so callers can safely read or modify domain slices without concurrent data races.

func (*CSPConfig) Validate

func (c *CSPConfig) Validate() error

Validate validates that every configured domain is a valid origin with a supported scheme.

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 DynamicUIResource added in v1.16.0

type DynamicUIResource struct {
	ResourceConfigBase
	ReadFunc func(ctx context.Context) (string, error)
	// contains filtered or unexported fields
}

DynamicUIResource represents an interactive MCP Apps UI resource that fetches or generates content dynamically.

func NewDynamicUIResource added in v1.16.0

func NewDynamicUIResource(name, uri, description string, csp *CSPConfig, prefersBorder *bool, readFunc func(ctx context.Context) (string, error)) *DynamicUIResource

NewDynamicUIResource constructs a DynamicUIResource configured for MCP Apps UI.

func (*DynamicUIResource) GetCSP added in v1.16.0

func (r *DynamicUIResource) GetCSP() *CSPConfig

GetCSP returns a thread-safe deep copy of the resource's CSP configuration.

func (*DynamicUIResource) GetResourceUIMetadata added in v1.16.0

func (r *DynamicUIResource) GetResourceUIMetadata() any

GetResourceUIMetadata returns the UI metadata conforming to the MCP Ext-Apps specification using a thread-safe snapshot of the dynamic CSP configuration.

func (*DynamicUIResource) GetSize added in v1.16.0

func (r *DynamicUIResource) GetSize() *int64

GetSize returns nil for dynamic resources.

func (*DynamicUIResource) Read added in v1.16.0

func (r *DynamicUIResource) Read(ctx context.Context, _ map[string]any) (any, error)

Read executes the dynamic content generation function.

func (*DynamicUIResource) SetCSP added in v1.16.0

func (r *DynamicUIResource) SetCSP(csp *CSPConfig)

SetCSP atomically replaces the resource's CSP configuration with a deep copy.

func (*DynamicUIResource) ToConfig added in v1.16.0

func (r *DynamicUIResource) ToConfig() ResourceConfig

ToConfig returns nil for dynamic resources.

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
	IsDynamic() 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"`
	Dynamic    bool   `yaml:"dynamic,omitempty"`
}

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) IsDynamic added in v1.16.0

func (c ResourceConfigBase) IsDynamic() bool

IsDynamic reports whether the skill at this SKILL.md publishes the "dynamic" marker in place of a manifest of digests.

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 ResourceProvider added in v1.16.0

type ResourceProvider interface {
	GetResources() []Resource
}

ResourceProvider is an optional interface tools can implement to expose UI resources.

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.

Directories

Path Synopsis
Package skills implements the io.modelcontextprotocol/skills extension (SEP-2640).
Package skills implements the io.modelcontextprotocol/skills extension (SEP-2640).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL