UNPKG

mcp-use

Version:

Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.

63 lines 3.27 kB
/** * UI Resource Registration * * This module handles the registration of UI widgets as both tools and resources * in the MCP server. It creates a unified interface for MCP-UI compatible widgets. */ import type { UIResourceDefinition, ResourceDefinition, ResourceDefinitionWithoutCallback, ResourceTemplateDefinition, ResourceTemplateDefinitionWithoutCallback, FlatResourceTemplateDefinition, FlatResourceTemplateDefinitionWithoutCallback, ToolDefinition } from "../types/index.js"; /** * Minimal server interface for UI resource registration * * This interface defines the minimal contract needed by uiResourceRegistration. * It uses broad types to be compatible with the various wrapped method signatures * in MCPServer while still providing type safety at the call sites. */ export interface UIResourceServer { readonly buildId?: string; readonly serverHost: string; readonly serverPort?: number; readonly serverBaseUrl?: string; /** Storage for widget definitions, used to inject metadata into tool responses */ widgetDefinitions: Map<string, Record<string, unknown>>; resource: (definition: ResourceDefinition | ResourceDefinitionWithoutCallback, callback?: any) => any; resourceTemplate: (definition: ResourceTemplateDefinition | ResourceTemplateDefinitionWithoutCallback | FlatResourceTemplateDefinition | FlatResourceTemplateDefinitionWithoutCallback, callback?: any) => any; tool: (definition: ToolDefinition, callback?: any) => any; } /** * Register a UI widget as both a tool and a resource * * Creates a unified interface for MCP-UI compatible widgets that can be accessed * either as tools (with parameters) or as resources (static access). The tool * allows dynamic parameter passing while the resource provides discoverable access. * * Supports multiple UI resource types: * - externalUrl: Legacy MCP-UI iframe-based widgets * - rawHtml: Legacy MCP-UI raw HTML content * - remoteDom: Legacy MCP-UI Remote DOM scripting * - appsSdk: OpenAI Apps SDK compatible widgets (text/html+skybridge) * * @param server - MCPServer instance with registration methods * @param definition - Widget configuration object * @param definition.name - Unique identifier for the resource * @param definition.type - Type of UI resource (externalUrl, rawHtml, remoteDom, appsSdk) * @param definition.title - Human-readable title for the widget * @param definition.description - Description of the widget's functionality * @param definition.props - Widget properties configuration with types and defaults * @param definition.size - Preferred iframe size [width, height] (e.g., ['900px', '600px']) * @param definition.annotations - Resource annotations for discovery * @param definition.appsSdkMetadata - Apps SDK specific metadata (CSP, widget description, etc.) * * @example * ```typescript * server.uiResource({ * type: 'appsSdk', * name: 'kanban-board', * title: 'Kanban Board', * description: 'Interactive task management board', * htmlTemplate: '<div>...</div>', * appsSdkMetadata: { ... } * }) * ``` */ export declare function uiResourceRegistration<T extends UIResourceServer>(server: T, definition: UIResourceDefinition): T; //# sourceMappingURL=ui-resource-registration.d.ts.map