import { App, McpUiHostContext, McpUiToolInputNotification, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps"; import { CallToolResult, ServerNotification, ServerRequest, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js"; import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js"; //#region src/openai.d.ts /** * @see https://developers.openai.com/apps-sdk/reference */ declare const SECURITY_SCHEMES = "securitySchemes"; declare const OUTPUT_TEMPLATE = "openai/outputTemplate"; declare const WIDGET_ACCESSIBLE = "openai/widgetAccessible"; declare const TOOL_INVOCATION_INVOKING = "openai/toolInvocation/invoking"; declare const TOOL_INVOCATION_INVOKED = "openai/toolInvocation/invoked"; /** * @see https://developers.openai.com/apps-sdk/reference#tool-descriptor-parameters */ type ToolDescriptorMeta = { [SECURITY_SCHEMES]?: string[]; /** Resource URI for component HTML template */ [OUTPUT_TEMPLATE]?: string; /** * Allow component→tool calls through the client bridge * @default false */ [WIDGET_ACCESSIBLE]?: boolean; /** * Short status text while the tool runs * @maxLength 64 */ [TOOL_INVOCATION_INVOKING]?: string; /** * Short status text after the tool completes * @maxLength 64 */ [TOOL_INVOCATION_INVOKED]?: string; }; /** * @see https://developers.openai.com/apps-sdk/build/custom-ux#understand-the-windowopenai-api */ declare global { interface Window { openai: API & OpenAiGlobals; } interface WindowEventMap { [SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent; } } declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals"; type UnknownObject = Record; type OpenAiGlobals = { readonly theme: Theme; readonly userAgent: UserAgent; readonly locale: string; readonly maxHeight: number; readonly displayMode: DisplayMode; readonly safeArea: SafeArea; readonly toolInput: ToolInput; readonly toolOutput: ToolOutput | null; readonly toolResponseMetadata: ToolResponseMetadata | null; readonly widgetState: WidgetState | null; }; type Theme = "light" | "dark"; type UserAgent = { device: { type: DeviceType; }; capabilities: { hover: boolean; touch: boolean; }; }; type DeviceType = "mobile" | "tablet" | "desktop" | "unknown"; type DisplayMode = "pip" | "inline" | "fullscreen"; type SafeArea = { insets: SafeAreaInsets; }; type SafeAreaInsets = { top: number; bottom: number; left: number; right: number; }; declare class SetGlobalsEvent extends CustomEvent<{ globals: Partial; }> { readonly type = "openai:set_globals"; } type API = { /** Calls a tool on your MCP. Returns the full response. */callTool(name: string, args: Record): Promise; /** Triggers a followup turn in the ChatGPT conversation */ sendFollowUpMessage(args: { prompt: string; }): Promise; /** Opens an external link, redirects web page or mobile app */ openExternal(payload: { href: string; }): void; /** For transitioning an app from inline to fullscreen or pip */ requestDisplayMode(args: { mode: DisplayMode; }): Promise<{ /** * The granted display mode. The host may reject the request. * For mobile, PiP is always coerced to fullscreen. */ mode: DisplayMode; }>; setWidgetState(state: WidgetState): Promise; }; //#endregion //#region src/types.d.ts /** * Minimal schema contract for Zod compatibility. * * We intentionally avoid depending on concrete `z.ZodType` from a specific * zod package instance/version, because consumers can bring a different zod * minor version in workspace setups. */ type ZodSchemaLike = { _output: unknown; } | { _zod: { output: unknown; }; }; /** Zod raw shape (object schema definition) */ type ZodRawShape = Record; /** Infer output type from schema-like type */ type InferSchemaOutput = TSchema extends { _output: infer TOutput; } ? TOutput : TSchema extends { _zod: { output: infer TOutput; }; } ? TOutput : unknown; /** Infer output type from Zod raw shape */ type InferShapeOutput = { [K in keyof T]: InferSchemaOutput }; /** Tool configuration */ interface ToolConfig { /** Display title (optional) */ title?: string; /** Description for LLM (required) */ description: string; /** Input schema using Zod */ inputSchema: TInput; /** Output schema using Zod (optional) */ outputSchema: TOutput; /** Tool annotations */ annotations?: ToolAnnotations; /** Metadata */ _meta?: Record & ToolDescriptorMeta; } /** Extra context passed to tool handler */ type ToolHandlerExtra = RequestHandlerExtra; /** Tool handler function */ type ToolHandler = Record> = (args: InferShapeOutput, extra: ToolHandlerExtra) => Promise; _meta?: TMeta; }>; /** Exports required from a tool file */ interface ToolExports { /** Tool name (unique identifier) */ name: string; /** Tool configuration */ config: ToolConfig; /** Tool handler */ handler: ToolHandler; /** MCP App metadata (required if App is exported) */ appMeta?: AppMeta; /** MCP App component (optional) */ App?: (props: AppProps) => unknown; } /** Resource configuration */ interface ResourceConfig { /** Resource URI */ uri: string; /** Display title (optional) */ title?: string; /** Description */ description?: string; /** MIME type (default: application/json) */ mimeType?: string; } /** Resource content item */ interface ResourceContent { uri: string; mimeType?: string; text?: string; blob?: string; } /** Resource handler result */ interface ResourceResult { contents: ResourceContent[]; } /** Resource handler function */ type ResourceHandler = (uri: URL) => Promise; /** Exports required from a resource file */ interface ResourceExports { /** Resource name */ name: string; /** Resource configuration */ config: ResourceConfig; /** Resource handler */ handler: ResourceHandler; } /** Prompt configuration */ interface PromptConfig { /** Display title (optional) */ title?: string; /** Description */ description?: string; /** Arguments schema using Zod */ argsSchema?: TArgs; } /** Prompt message */ interface PromptMessage { role: "user" | "assistant"; content: { type: "text"; text: string; } | { type: "image"; data: string; mimeType: string; } | { type: "resource"; resource: { uri: string; text?: string; blob?: string; mimeType?: string; }; }; } /** Prompt handler result */ interface PromptResult { messages: PromptMessage[]; description?: string; } /** Prompt handler function */ type PromptHandler = (args: InferShapeOutput) => PromptResult; /** Exports required from a prompt file */ interface PromptExports { /** Prompt name */ name: string; /** Prompt configuration */ config: PromptConfig; /** Prompt handler */ handler: PromptHandler; } /** MCP App metadata (from @modelcontextprotocol/ext-apps) */ interface AppMeta { /** Content Security Policy settings */ csp?: { /** Allowed origins for fetch/XHR/WebSocket */connectDomains?: string[]; /** Allowed origins for images/scripts/styles/fonts */ resourceDomains?: string[]; /** Allowed origins for iframes */ frameDomains?: string[]; /** Allowed origins for base URI */ baseUriDomains?: string[]; }; /** Sandbox permissions */ permissions?: { camera?: object; microphone?: object; geolocation?: object; clipboardWrite?: object; }; /** Dedicated origin for CORS/OAuth */ domain?: string; /** Show border around the app */ prefersBorder?: boolean; } /** Props passed to MCP App component */ interface AppProps = Record> { /** Tool input arguments */ input?: McpUiToolInputNotification["params"] & { arguments?: InferShapeOutput; }; /** Tool output (null if not yet executed) */ output?: McpUiToolResultNotification["params"] & { structuredContent?: InferShapeOutput | null; _meta?: TMeta; }; /** Host context from MCP UI */ hostContext?: McpUiHostContext; } //#endregion //#region src/define.d.ts /** * Define a tool with type inference. * The input, output, and meta types are automatically inferred from schemas and handler return type. * * @example * ```ts * export const tool = defineTool({ * name: "get_weather", * config: { * description: "Get weather for a city", * inputSchema: { city: z.string() }, * outputSchema: { temperature: z.number() }, * }, * handler: async (args) => { * // args.city is typed as string * return { * content: [], * structuredContent: { temperature: 20 }, * _meta: { chartData: [...] }, // UI-only data (not sent to LLM) * }; * }, * }); * ``` */ declare function defineTool = Record>(options: { name: TName; config: ToolConfig; handler: (args: InferShapeOutput, extra: ToolHandlerExtra) => Promise; _meta?: TMeta; }>; }): { name: TName; config: ToolConfig; handler: ToolHandler; }; /** Type alias for the return type of defineTool */ type DefinedTool = { name: TName; config: ToolConfig; handler: ToolHandler; }; /** Helper type to extract input type from a tool definition */ type InferToolInput = T["config"]["inputSchema"] extends ZodRawShape ? InferShapeOutput : Record; /** Helper type to extract output type from a tool definition */ type InferToolOutput = T["config"]["outputSchema"] extends ZodRawShape ? InferShapeOutput : unknown; type AppParams = ConstructorParameters; /** Base interface for app definition */ interface AppDefinition = Record> { meta?: AppMeta; /** * App configuration * @see {@link App}'s constructor */ config: { appInfo: AppParams[0]; capabilities?: AppParams[1]; options?: AppParams[2]; }; ui: (props: AppProps) => unknown; } /** Helper type to extract _meta type from handler return type */ type ExtractMeta = T extends { handler: (...args: never[]) => Promise; } ? R extends { _meta?: infer M; } ? M extends Record ? M : Record : Record : Record; /** * Define an MCP App with type inference. * * You must pass a type argument: `defineApp({ ... })`. Omitting it * will cause a type error so that `props.input`, `props.output`, and `props.hostContext` * in the UI are correctly typed from the tool definition. * * @example * ```tsx * export const tool = defineTool({ * ..., * handler: async (args) => ({ * content: [], * _meta: { chartData: [...] }, * }), * }); * export const app = defineApp({ * config: { appInfo: { name: "my-app", version: "1.0.0" } }, * ui: (props) => { * // props.output._meta is typed as { chartData: ... } | undefined * return ; * }, * }); * ``` */ declare function defineApp Promise; } = never>(app: [TTool] extends [never] ? { "defineApp requires a type argument: defineApp({ ... })": never; } : AppDefinition>): typeof app; /** Options passed to defineResource */ interface DefineResourceOptions { name: string; config: ResourceConfig; handler: ResourceHandler; } declare function defineResource(options: T): T; /** * Define a prompt with type inference. * The args type is automatically inferred from config.argsSchema. */ declare function definePrompt(options: { name: TName; config: { title?: string; description?: string; argsSchema?: TArgs; }; handler: PromptHandler; }): { name: TName; config: PromptConfig; handler: PromptHandler; }; /** Type alias for the return type of definePrompt */ type DefinedPrompt = { name: TName; config: PromptConfig; handler: PromptHandler; }; //#endregion export { ResourceExports as _, InferToolInput as a, ToolExports as b, definePrompt as c, AppMeta as d, AppProps as f, ResourceConfig as g, PromptHandler as h, DefinedTool as i, defineResource as l, PromptExports as m, DefineResourceOptions as n, InferToolOutput as o, PromptConfig as p, DefinedPrompt as r, defineApp as s, AppDefinition as t, defineTool as u, ResourceHandler as v, ToolHandler as x, ToolConfig as y }; //# sourceMappingURL=define-CLunBceb.d.ts.map