uispec

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package uispec defines constants and _meta types for the MCP Apps extension (io.modelcontextprotocol/ui), spec version 2026-01-26.

It is deliberately free of any MCP SDK dependency: everything is expressed as plain Go types and map[string]any meta maps, so gomukit widgets can be wired into any Go MCP implementation. The official go-sdk adapter lives in package gosdk.

Spec names that may still shift with upcoming spec revisions (the meta key, notification method names) are encoded here exactly once; the TypeScript runtime mirrors them from ui/src/spec-constants.json, and tests cross-check the two.

Index

Constants

View Source
const (
	// ExtensionID is the MCP Apps extension identifier used in capability
	// negotiation.
	ExtensionID = "io.modelcontextprotocol/ui"

	// SpecVersion is the ext-apps specification version gomukit targets.
	SpecVersion = "2026-01-26"

	// MIMEType is the media type of MCP Apps HTML template resources.
	MIMEType = "text/html;profile=mcp-app"

	// MetaKey is the key under which UI metadata is nested inside _meta on
	// tools, resources, and tool results.
	MetaKey = "ui"

	// URIScheme is the URI scheme for UI template resources ("ui://...").
	URIScheme = "ui"
)
View Source
const (
	VisibilityModel = "model" // tool is callable by the model
	VisibilityApp   = "app"   // tool is callable from the app UI only
)

Visibility values for ToolUIMeta.Visibility.

Variables

View Source
var Grant = &Permission{}

Grant is the marker used to request a permission, e.g. Permissions{Camera: uispec.Grant}.

Functions

func MergeMeta

func MergeMeta(dst, src map[string]any) map[string]any

MergeMeta merges src into dst recursively (map values merge, everything else overwrites) and returns dst. A nil dst is allocated. src is not modified; nested maps from src are copied on merge conflicts only — callers must not retain and mutate src maps that end up shared in dst.

func ValidateURI

func ValidateURI(uri string) error

ValidateURI checks that uri is a well-formed ui:// resource URI.

Types

type CSP

type CSP struct {
	ConnectDomains  []string `json:"connectDomains,omitempty"`
	ResourceDomains []string `json:"resourceDomains,omitempty"`
	FrameDomains    []string `json:"frameDomains,omitempty"`
	BaseURIDomains  []string `json:"baseUriDomains,omitempty"`
}

CSP declares the external origins a UI resource needs. Hosts apply a fully locked-down policy by default; every domain must be predeclared.

type Permission

type Permission struct{}

Permission is the presence marker for a requested sandbox permission. Per the MCP Apps spec each requested capability is a key mapping to an empty object, so a *Permission serializes to {} when set and is omitted when nil.

type Permissions

type Permissions struct {
	Camera         *Permission `json:"camera,omitempty"`
	Microphone     *Permission `json:"microphone,omitempty"`
	Geolocation    *Permission `json:"geolocation,omitempty"`
	ClipboardWrite *Permission `json:"clipboardWrite,omitempty"`
}

Permissions declares the browser capabilities a UI resource requests. Hosts MAY honor these by setting the sandbox iframe's allow attribute; apps must not assume they are granted. Serializes to the spec object shape, e.g. {"camera":{},"clipboardWrite":{}}.

type ResourceDescriptor

type ResourceDescriptor struct {
	URI         string
	Name        string
	Title       string
	Description string
	MIMEType    string // always MIMEType for gomukit widgets
	UI          *ResourceUIMeta
}

ResourceDescriptor carries everything needed to register a widget's template resource with an MCP server, independent of the SDK in use.

func (ResourceDescriptor) MetaMap

func (d ResourceDescriptor) MetaMap() map[string]any

MetaMap returns the descriptor's resource _meta map, or nil when the descriptor declares no UI metadata.

type ResourceUIMeta

type ResourceUIMeta struct {
	CSP           *CSP         `json:"csp,omitempty"`
	Permissions   *Permissions `json:"permissions,omitempty"`
	Domain        string       `json:"domain,omitempty"`
	PrefersBorder *bool        `json:"prefersBorder,omitempty"`
}

ResourceUIMeta is the _meta.ui payload attached to a ui:// resource.

func (ResourceUIMeta) MetaMap

func (m ResourceUIMeta) MetaMap() map[string]any

MetaMap returns the resource _meta map: {"ui": {...}}.

type ToolUIMeta

type ToolUIMeta struct {
	ResourceURI string   `json:"resourceUri"`
	Visibility  []string `json:"visibility,omitempty"`
}

ToolUIMeta is the _meta.ui payload attached to a tool, linking it to its UI template resource.

func (ToolUIMeta) MetaMap

func (m ToolUIMeta) MetaMap() map[string]any

MetaMap returns the tool _meta map: {"ui": {"resourceUri": ..., ...}}.

Jump to

Keyboard shortcuts

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