open-mcp-app 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.d.ts +1095 -0
- package/dist/core/index.js +11052 -0
- package/dist/core/index.js.map +1 -0
- package/dist/react/index.d.ts +421 -0
- package/dist/react/index.js +11301 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +1332 -0
- package/dist/server/index.js +15248 -0
- package/dist/server/index.js.map +1 -0
- package/dist/vite/index.d.ts +56 -0
- package/dist/vite/index.js +382 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,1095 @@
|
|
|
1
|
+
export { applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core SDK Types
|
|
5
|
+
*
|
|
6
|
+
* Unified type definitions for the MCP Apps SDK.
|
|
7
|
+
* Provides a single, consistent API across all host environments.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Environment types for host detection.
|
|
11
|
+
* The SDK automatically detects which environment it's running in.
|
|
12
|
+
*/
|
|
13
|
+
type Environment = "chatgpt" | "mcp-apps" | "standalone";
|
|
14
|
+
/**
|
|
15
|
+
* Display modes for UI resources.
|
|
16
|
+
* - "inline": Embedded within the conversation flow
|
|
17
|
+
* - "pip": Picture-in-picture floating panel
|
|
18
|
+
* - "fullscreen": Full-screen overlay
|
|
19
|
+
*/
|
|
20
|
+
type DisplayMode = "inline" | "pip" | "fullscreen";
|
|
21
|
+
/**
|
|
22
|
+
* Log severity levels matching MCP protocol LoggingLevel.
|
|
23
|
+
* Logs are displayed in the host's DevConsole with appropriate colors.
|
|
24
|
+
*/
|
|
25
|
+
type LogLevel = "debug" | "info" | "notice" | "warning" | "error";
|
|
26
|
+
/**
|
|
27
|
+
* Structured widget state format (ChatGPT-compatible).
|
|
28
|
+
* Allows separating model-visible content from private UI state.
|
|
29
|
+
*/
|
|
30
|
+
interface StructuredWidgetState {
|
|
31
|
+
/** Content visible to the AI model on follow-up turns */
|
|
32
|
+
modelContent?: string | Record<string, unknown> | null;
|
|
33
|
+
/** UI-only state, hidden from model */
|
|
34
|
+
privateContent?: Record<string, unknown> | null;
|
|
35
|
+
/** File IDs for images the model can see */
|
|
36
|
+
imageIds?: string[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Widget state can be structured (with modelContent/privateContent)
|
|
40
|
+
* or a simple key-value object.
|
|
41
|
+
*/
|
|
42
|
+
type WidgetState = StructuredWidgetState | Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Tool call result structure.
|
|
45
|
+
*/
|
|
46
|
+
interface ToolResult<T = Record<string, unknown>> {
|
|
47
|
+
content?: Array<{
|
|
48
|
+
type: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}>;
|
|
51
|
+
structuredContent?: T;
|
|
52
|
+
isError?: boolean;
|
|
53
|
+
source?: "agent" | "ui";
|
|
54
|
+
/** Tool name that produced this result (for view routing) */
|
|
55
|
+
toolName?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Context about how the view was opened.
|
|
59
|
+
* SDK uses this to determine initialization behavior.
|
|
60
|
+
*/
|
|
61
|
+
interface OpenContext {
|
|
62
|
+
/**
|
|
63
|
+
* How the view was opened:
|
|
64
|
+
* - "tool": Opened by an agent tool call (expect tool-input/tool-result)
|
|
65
|
+
* - "user": Opened directly by user (no tool notifications coming)
|
|
66
|
+
* - "restore": Restoring previous state (popout, pop-back-in, refresh).
|
|
67
|
+
* Uses widgetState.modelContent.view for initial view.
|
|
68
|
+
*/
|
|
69
|
+
triggeredBy: "tool" | "user" | "restore";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Host context sent from MCP Apps host.
|
|
73
|
+
* Follows MCP Apps spec with extensions via [key: string]: unknown.
|
|
74
|
+
*/
|
|
75
|
+
interface HostContext {
|
|
76
|
+
theme?: "light" | "dark";
|
|
77
|
+
styles?: {
|
|
78
|
+
variables?: Record<string, string>;
|
|
79
|
+
css?: {
|
|
80
|
+
fonts?: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
displayMode?: DisplayMode;
|
|
84
|
+
availableDisplayModes?: DisplayMode[];
|
|
85
|
+
viewport?: {
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
};
|
|
89
|
+
platform?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Host application identifier per MCP Apps spec.
|
|
92
|
+
* Format: "<host>/<version>" (e.g. "creature/1.0.0", "chatgpt/2.0.0").
|
|
93
|
+
*/
|
|
94
|
+
userAgent?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Widget state restored from previous widget instance.
|
|
97
|
+
*/
|
|
98
|
+
widgetState?: WidgetState;
|
|
99
|
+
/**
|
|
100
|
+
* Context about how the view was opened.
|
|
101
|
+
* Per MCP Apps spec extensibility, sent in hostContext.
|
|
102
|
+
*/
|
|
103
|
+
openContext?: OpenContext;
|
|
104
|
+
/**
|
|
105
|
+
* Experimental (non-standard) extensions.
|
|
106
|
+
* Follows the SDK's `experimental` namespace paradigm.
|
|
107
|
+
*/
|
|
108
|
+
experimental?: {
|
|
109
|
+
/**
|
|
110
|
+
* Additional CSS variables beyond the MCP Apps spec.
|
|
111
|
+
* Apps should apply these alongside spec styles for enhanced theming.
|
|
112
|
+
*/
|
|
113
|
+
styles?: {
|
|
114
|
+
variables?: Record<string, string | undefined>;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Allow additional host-specific properties.
|
|
119
|
+
*/
|
|
120
|
+
[key: string]: unknown;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Content block types for model context updates.
|
|
124
|
+
*/
|
|
125
|
+
interface TextContentBlock {
|
|
126
|
+
type: "text";
|
|
127
|
+
text: string;
|
|
128
|
+
}
|
|
129
|
+
interface ImageContentBlock {
|
|
130
|
+
type: "image";
|
|
131
|
+
data: string;
|
|
132
|
+
mimeType: string;
|
|
133
|
+
}
|
|
134
|
+
type ContentBlock = TextContentBlock | ImageContentBlock;
|
|
135
|
+
/**
|
|
136
|
+
* Configuration for creating a host client.
|
|
137
|
+
*/
|
|
138
|
+
interface HostClientConfig {
|
|
139
|
+
/** Name of the client (for protocol handshake) */
|
|
140
|
+
name: string;
|
|
141
|
+
/** Version of the client */
|
|
142
|
+
version: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* State managed by the host client.
|
|
146
|
+
*/
|
|
147
|
+
interface HostClientState {
|
|
148
|
+
/** Whether the host connection is ready */
|
|
149
|
+
isReady: boolean;
|
|
150
|
+
/** The detected environment */
|
|
151
|
+
environment: Environment;
|
|
152
|
+
/** Current widget state */
|
|
153
|
+
widgetState: WidgetState | null;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Listener for state changes.
|
|
157
|
+
*/
|
|
158
|
+
type StateListener = (state: HostClientState, prevState: HostClientState) => void;
|
|
159
|
+
/**
|
|
160
|
+
* All events supported by the unified host client.
|
|
161
|
+
* Events that aren't supported by a host are no-op subscriptions.
|
|
162
|
+
*/
|
|
163
|
+
interface HostClientEvents {
|
|
164
|
+
/** Called when tool input is received (before execution) */
|
|
165
|
+
"tool-input": (args: Record<string, unknown>) => void;
|
|
166
|
+
/** Called when tool result is received */
|
|
167
|
+
"tool-result": (result: ToolResult) => void;
|
|
168
|
+
/** Called when widget state changes (restored or updated) */
|
|
169
|
+
"widget-state-change": (widgetState: WidgetState | null) => void;
|
|
170
|
+
/** Called when theme changes (MCP Apps only, no-op on ChatGPT) */
|
|
171
|
+
"theme-change": (theme: "light" | "dark") => void;
|
|
172
|
+
/** Called when host requests teardown (MCP Apps only, no-op on ChatGPT) */
|
|
173
|
+
"teardown": () => Promise<void> | void;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Experimental host APIs that are not part of the MCP Apps spec.
|
|
177
|
+
*
|
|
178
|
+
* These APIs provide access to host-specific features that may not be
|
|
179
|
+
* supported by all hosts. Methods gracefully degrade (no-op or return null)
|
|
180
|
+
* when called on unsupported hosts.
|
|
181
|
+
*/
|
|
182
|
+
interface ExpHostApi {
|
|
183
|
+
/**
|
|
184
|
+
* Set widget state and notify the host.
|
|
185
|
+
*
|
|
186
|
+
* Widget state is synchronized with the host for persistence across
|
|
187
|
+
* sessions and visibility to the AI model.
|
|
188
|
+
*
|
|
189
|
+
* - ChatGPT: Native support via `window.openai.setWidgetState`
|
|
190
|
+
* - Creature: Extension via `ui/notifications/widget-state-changed`
|
|
191
|
+
* - Generic MCP Apps hosts: May not support (state stored locally)
|
|
192
|
+
* - Standalone: Stores locally
|
|
193
|
+
*/
|
|
194
|
+
setWidgetState(state: WidgetState | null): void;
|
|
195
|
+
/**
|
|
196
|
+
* Set the pip/widget title displayed in the host UI.
|
|
197
|
+
*
|
|
198
|
+
* Creature only - no-op on ChatGPT and generic MCP Apps hosts.
|
|
199
|
+
*/
|
|
200
|
+
setTitle(title: string): void;
|
|
201
|
+
/**
|
|
202
|
+
* Update the model context for future turns.
|
|
203
|
+
*
|
|
204
|
+
* In MCP Apps spec as `ui/update-model-context`. Context is available
|
|
205
|
+
* to the model in future turns without triggering immediate response.
|
|
206
|
+
* Each call overwrites previous context.
|
|
207
|
+
*
|
|
208
|
+
* - MCP Apps hosts: Supported (if host declares capability)
|
|
209
|
+
* - ChatGPT: No-op
|
|
210
|
+
*/
|
|
211
|
+
updateModelContext(content: ContentBlock[]): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Send a raw notification to the host.
|
|
214
|
+
*
|
|
215
|
+
* Low-level API for power users. Most apps should use higher-level methods.
|
|
216
|
+
* MCP Apps only - no-op on ChatGPT.
|
|
217
|
+
*/
|
|
218
|
+
sendNotification(method: string, params: unknown): void;
|
|
219
|
+
/**
|
|
220
|
+
* Get the instance ID for this widget.
|
|
221
|
+
*
|
|
222
|
+
* Multi-instance support is a Creature extension.
|
|
223
|
+
* - Creature: Full support for multiple instances with independent state
|
|
224
|
+
* - ChatGPT: May return session ID, singleton behavior
|
|
225
|
+
* - Generic MCP Apps hosts: Returns null
|
|
226
|
+
*/
|
|
227
|
+
getInstanceId(): string | null;
|
|
228
|
+
/**
|
|
229
|
+
* Check if the host supports multi-instance resources.
|
|
230
|
+
*
|
|
231
|
+
* - Creature: true
|
|
232
|
+
* - ChatGPT: false (singleton only)
|
|
233
|
+
* - Generic MCP Apps hosts: false
|
|
234
|
+
*/
|
|
235
|
+
supportsMultiInstance(): boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Get the initial tool result if view was opened by an agent tool call.
|
|
238
|
+
*
|
|
239
|
+
* Returns the first tool result received, or null if:
|
|
240
|
+
* - View was opened directly by user (no tool call)
|
|
241
|
+
* - Tool result hasn't arrived yet (shouldn't happen after isReady=true)
|
|
242
|
+
*
|
|
243
|
+
* This enables clean initialization:
|
|
244
|
+
* ```typescript
|
|
245
|
+
* const { isReady, getInitialToolResult } = useHost();
|
|
246
|
+
* useEffect(() => {
|
|
247
|
+
* if (!isReady) return;
|
|
248
|
+
* const initial = getInitialToolResult();
|
|
249
|
+
* if (initial) {
|
|
250
|
+
* // View opened by agent - use the tool result data
|
|
251
|
+
* processData(initial.structuredContent);
|
|
252
|
+
* } else {
|
|
253
|
+
* // View opened by user - fetch initial data
|
|
254
|
+
* fetchData();
|
|
255
|
+
* }
|
|
256
|
+
* }, [isReady]);
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
getInitialToolResult(): ToolResult | null;
|
|
260
|
+
/**
|
|
261
|
+
* Send a follow-up message to the conversation.
|
|
262
|
+
*
|
|
263
|
+
* ChatGPT only. Triggers a new model turn with the given prompt.
|
|
264
|
+
* No-op on MCP Apps hosts.
|
|
265
|
+
*/
|
|
266
|
+
sendFollowUpMessage(prompt: string): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Open a modal dialog from the host.
|
|
269
|
+
*
|
|
270
|
+
* ChatGPT only. Returns null on MCP Apps hosts.
|
|
271
|
+
*/
|
|
272
|
+
requestModal(options: {
|
|
273
|
+
title?: string;
|
|
274
|
+
params?: Record<string, unknown>;
|
|
275
|
+
}): Promise<unknown | null>;
|
|
276
|
+
/**
|
|
277
|
+
* Request the host to close this widget.
|
|
278
|
+
*
|
|
279
|
+
* ChatGPT only. No-op on MCP Apps hosts.
|
|
280
|
+
*/
|
|
281
|
+
requestClose(): Promise<void>;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Unified host client interface.
|
|
285
|
+
*
|
|
286
|
+
* This is the primary interface returned by `createHost()`.
|
|
287
|
+
* Provides a consistent API across all host environments (ChatGPT, MCP Apps, Standalone).
|
|
288
|
+
*/
|
|
289
|
+
interface UnifiedHostClient {
|
|
290
|
+
/**
|
|
291
|
+
* The detected environment.
|
|
292
|
+
*/
|
|
293
|
+
readonly environment: Environment;
|
|
294
|
+
/**
|
|
295
|
+
* Get current client state.
|
|
296
|
+
*/
|
|
297
|
+
getState(): HostClientState;
|
|
298
|
+
/**
|
|
299
|
+
* Subscribe to state changes. Returns unsubscribe function.
|
|
300
|
+
*/
|
|
301
|
+
subscribe(listener: StateListener): () => void;
|
|
302
|
+
/**
|
|
303
|
+
* Get the host context received from the host.
|
|
304
|
+
* Contains theme, styles, userAgent, and host-specific properties.
|
|
305
|
+
* Returns null before connection is established or on ChatGPT.
|
|
306
|
+
*/
|
|
307
|
+
getHostContext(): HostContext | null;
|
|
308
|
+
/**
|
|
309
|
+
* Call a tool on the MCP server.
|
|
310
|
+
*/
|
|
311
|
+
callTool<T = Record<string, unknown>>(toolName: string, args: Record<string, unknown>): Promise<ToolResult<T>>;
|
|
312
|
+
/**
|
|
313
|
+
* Request a display mode change from the host.
|
|
314
|
+
*/
|
|
315
|
+
requestDisplayMode(params: {
|
|
316
|
+
mode: DisplayMode;
|
|
317
|
+
}): Promise<{
|
|
318
|
+
mode: DisplayMode;
|
|
319
|
+
}>;
|
|
320
|
+
/**
|
|
321
|
+
* Send a log message to host DevConsole.
|
|
322
|
+
* Falls back to browser console on ChatGPT.
|
|
323
|
+
*/
|
|
324
|
+
log(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
325
|
+
/**
|
|
326
|
+
* Register an event handler. Returns unsubscribe function.
|
|
327
|
+
*/
|
|
328
|
+
on<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
329
|
+
/**
|
|
330
|
+
* Start listening for host messages.
|
|
331
|
+
*/
|
|
332
|
+
connect(): void;
|
|
333
|
+
/**
|
|
334
|
+
* Stop listening for host messages.
|
|
335
|
+
*/
|
|
336
|
+
disconnect(): void;
|
|
337
|
+
/**
|
|
338
|
+
* Experimental APIs for non-standard features.
|
|
339
|
+
*
|
|
340
|
+
* These APIs provide access to host-specific features that may not be
|
|
341
|
+
* supported by all hosts. Methods gracefully degrade when unsupported.
|
|
342
|
+
*/
|
|
343
|
+
readonly exp: ExpHostApi;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* WebSocket connection status.
|
|
347
|
+
*/
|
|
348
|
+
type WebSocketStatus = "disconnected" | "connecting" | "connected" | "error";
|
|
349
|
+
/**
|
|
350
|
+
* Configuration for creating a WebSocket client.
|
|
351
|
+
*/
|
|
352
|
+
interface WebSocketClientConfig<TReceive = unknown> {
|
|
353
|
+
/** Called when a message is received */
|
|
354
|
+
onMessage?: (message: TReceive) => void;
|
|
355
|
+
/** Called when connection status changes */
|
|
356
|
+
onStatusChange?: (status: WebSocketStatus, error?: string) => void;
|
|
357
|
+
/** Whether to auto-reconnect on disconnect (default: true) */
|
|
358
|
+
reconnect?: boolean;
|
|
359
|
+
/** Base interval for reconnection attempts in ms (default: 1000) */
|
|
360
|
+
reconnectInterval?: number;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* WebSocket client interface.
|
|
364
|
+
*/
|
|
365
|
+
interface WebSocketClient<TSend = unknown, TReceive = unknown> {
|
|
366
|
+
/** Current connection status */
|
|
367
|
+
readonly status: WebSocketStatus;
|
|
368
|
+
/** Error message if status is "error" */
|
|
369
|
+
readonly error: string | undefined;
|
|
370
|
+
/** Connect to the WebSocket server */
|
|
371
|
+
connect(): void;
|
|
372
|
+
/** Disconnect from the WebSocket server */
|
|
373
|
+
disconnect(): void;
|
|
374
|
+
/** Send a message to the server */
|
|
375
|
+
send(message: TSend): void;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Subscribable Base Class
|
|
380
|
+
*
|
|
381
|
+
* Provides event emitter pattern for state changes and host events.
|
|
382
|
+
* Used as a base class for all host client implementations.
|
|
383
|
+
*/
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Base class for subscribable host clients.
|
|
387
|
+
* Provides unified event handling for state changes and host events.
|
|
388
|
+
*/
|
|
389
|
+
declare abstract class Subscribable {
|
|
390
|
+
private stateListeners;
|
|
391
|
+
private eventHandlers;
|
|
392
|
+
private mcpEventHandlers;
|
|
393
|
+
/**
|
|
394
|
+
* Subscribe to state changes.
|
|
395
|
+
*
|
|
396
|
+
* @param listener - Callback invoked when state changes
|
|
397
|
+
* @returns Unsubscribe function
|
|
398
|
+
*/
|
|
399
|
+
protected subscribeToState(listener: StateListener): () => void;
|
|
400
|
+
/**
|
|
401
|
+
* Register a handler for base events.
|
|
402
|
+
*
|
|
403
|
+
* @param event - The event name
|
|
404
|
+
* @param handler - The event handler
|
|
405
|
+
* @returns Unsubscribe function
|
|
406
|
+
*/
|
|
407
|
+
protected onEvent<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
408
|
+
/**
|
|
409
|
+
* Get the number of subscribers for an event.
|
|
410
|
+
*
|
|
411
|
+
* @param event - The event name
|
|
412
|
+
* @returns Number of subscribers
|
|
413
|
+
*/
|
|
414
|
+
protected getSubscriberCount(event: keyof HostClientEvents): number;
|
|
415
|
+
/**
|
|
416
|
+
* Register a handler for MCP-specific events (theme-change, teardown).
|
|
417
|
+
*
|
|
418
|
+
* @param event - The event name
|
|
419
|
+
* @param handler - The event handler
|
|
420
|
+
* @returns Unsubscribe function
|
|
421
|
+
*/
|
|
422
|
+
protected onMcpEvent<K extends "theme-change" | "teardown">(event: K, handler: K extends "theme-change" ? (theme: "light" | "dark") => void : () => Promise<void> | void): () => void;
|
|
423
|
+
/**
|
|
424
|
+
* Notify all state listeners of a state change.
|
|
425
|
+
*/
|
|
426
|
+
protected notifyStateChange(state: HostClientState, prevState: HostClientState): void;
|
|
427
|
+
/**
|
|
428
|
+
* Emit a base event to all registered handlers.
|
|
429
|
+
*/
|
|
430
|
+
protected emit<K extends keyof HostClientEvents>(event: K, ...args: Parameters<HostClientEvents[K]>): void;
|
|
431
|
+
/**
|
|
432
|
+
* Emit an MCP-specific event to all registered handlers.
|
|
433
|
+
*/
|
|
434
|
+
protected emitMcpEvent<K extends "theme-change" | "teardown">(event: K, ...args: K extends "theme-change" ? ["light" | "dark"] : []): void | Promise<void>;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Creature Desktop Host Client
|
|
439
|
+
*
|
|
440
|
+
* Host client for the Creature Desktop environment.
|
|
441
|
+
* Handles iframe postMessage communication with the Creature host application.
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Creature Desktop host client implementation.
|
|
446
|
+
*
|
|
447
|
+
* Provides full MCP Apps support with Creature-specific extensions:
|
|
448
|
+
* - Multi-instance support
|
|
449
|
+
* - Dynamic title changes
|
|
450
|
+
* - Views-based routing
|
|
451
|
+
*
|
|
452
|
+
* Event Buffering:
|
|
453
|
+
* Tool-input and tool-result events may arrive before React components
|
|
454
|
+
* have subscribed (due to useEffect timing). We buffer these events and
|
|
455
|
+
* replay them when the first subscriber is added, ensuring no data is lost.
|
|
456
|
+
*/
|
|
457
|
+
declare class CreatureDesktopHostClient extends Subscribable implements UnifiedHostClient {
|
|
458
|
+
readonly environment: "mcp-apps";
|
|
459
|
+
private state;
|
|
460
|
+
private config;
|
|
461
|
+
private app;
|
|
462
|
+
private connected;
|
|
463
|
+
private hostContext;
|
|
464
|
+
private instanceId;
|
|
465
|
+
/**
|
|
466
|
+
* Whether this view was triggered by a tool call.
|
|
467
|
+
* Determined from openContext.triggeredBy in hostContext.
|
|
468
|
+
*/
|
|
469
|
+
private triggeredByTool;
|
|
470
|
+
/**
|
|
471
|
+
* Whether we've received the initial tool-result notification.
|
|
472
|
+
* Used to gate isReady when triggeredByTool is true.
|
|
473
|
+
*/
|
|
474
|
+
private hasReceivedToolResult;
|
|
475
|
+
/**
|
|
476
|
+
* The initial tool result received when view was opened by agent.
|
|
477
|
+
* Stored for getInitialToolResult() access.
|
|
478
|
+
*/
|
|
479
|
+
private initialToolResult;
|
|
480
|
+
/**
|
|
481
|
+
* Buffered events for replay when subscribers are added.
|
|
482
|
+
*
|
|
483
|
+
* Events may arrive before React's useEffect sets up subscriptions.
|
|
484
|
+
* We buffer them here and replay when the first subscriber is added.
|
|
485
|
+
*/
|
|
486
|
+
private bufferedToolInput;
|
|
487
|
+
private bufferedToolResult;
|
|
488
|
+
constructor(config: HostClientConfig);
|
|
489
|
+
/**
|
|
490
|
+
* Create a Creature Desktop host client instance.
|
|
491
|
+
*/
|
|
492
|
+
static create(config: HostClientConfig): CreatureDesktopHostClient;
|
|
493
|
+
getState(): HostClientState;
|
|
494
|
+
getHostContext(): HostContext | null;
|
|
495
|
+
subscribe(listener: StateListener): () => void;
|
|
496
|
+
/**
|
|
497
|
+
* Connect to the Creature Desktop host.
|
|
498
|
+
*
|
|
499
|
+
* Creates the App instance, registers notification handlers, and initiates
|
|
500
|
+
* the protocol handshake. The host responds with hostContext including
|
|
501
|
+
* theme, styles, and widgetState.
|
|
502
|
+
*/
|
|
503
|
+
connect(): void;
|
|
504
|
+
/**
|
|
505
|
+
* Disconnect from the host.
|
|
506
|
+
*/
|
|
507
|
+
disconnect(): void;
|
|
508
|
+
/**
|
|
509
|
+
* Call a tool on the MCP server via the host.
|
|
510
|
+
*/
|
|
511
|
+
callTool<T = Record<string, unknown>>(toolName: string, args: Record<string, unknown>): Promise<ToolResult<T>>;
|
|
512
|
+
/**
|
|
513
|
+
* Request a display mode change from the host.
|
|
514
|
+
*/
|
|
515
|
+
requestDisplayMode(params: {
|
|
516
|
+
mode: DisplayMode;
|
|
517
|
+
}): Promise<{
|
|
518
|
+
mode: DisplayMode;
|
|
519
|
+
}>;
|
|
520
|
+
/**
|
|
521
|
+
* Send a log message to the host's DevConsole.
|
|
522
|
+
*/
|
|
523
|
+
log(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
524
|
+
on<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
525
|
+
/**
|
|
526
|
+
* Experimental APIs (shared across all hosts).
|
|
527
|
+
* Behavior varies by host - see ExpHostApi for details.
|
|
528
|
+
*/
|
|
529
|
+
get exp(): ExpHostApi;
|
|
530
|
+
/**
|
|
531
|
+
* Send a notification to the host.
|
|
532
|
+
*/
|
|
533
|
+
private sendNotification;
|
|
534
|
+
/**
|
|
535
|
+
* Update internal state and notify listeners.
|
|
536
|
+
*/
|
|
537
|
+
private setState;
|
|
538
|
+
/**
|
|
539
|
+
* Check if there are any subscribers for an event type.
|
|
540
|
+
*/
|
|
541
|
+
private hasSubscribers;
|
|
542
|
+
/**
|
|
543
|
+
* Set up notification handlers on the App instance.
|
|
544
|
+
*
|
|
545
|
+
* Events are buffered if no subscribers exist yet. When a subscriber
|
|
546
|
+
* is added via on(), buffered events are replayed immediately.
|
|
547
|
+
*
|
|
548
|
+
* For tool-triggered views, isReady is set after tool-result is received.
|
|
549
|
+
* This ensures getInitialToolResult() has data when the app initializes.
|
|
550
|
+
*/
|
|
551
|
+
private setupHandlers;
|
|
552
|
+
/**
|
|
553
|
+
* Initiate connection using PostMessageTransport.
|
|
554
|
+
*
|
|
555
|
+
* For user-triggered views: Sets isReady immediately after connection.
|
|
556
|
+
* For tool-triggered views: Waits for tool-result before setting isReady.
|
|
557
|
+
* This ensures getInitialToolResult() has data when the app initializes.
|
|
558
|
+
*
|
|
559
|
+
* Events that arrive before React subscribes are buffered and replayed.
|
|
560
|
+
*/
|
|
561
|
+
private initiateConnection;
|
|
562
|
+
/**
|
|
563
|
+
* Apply theme, styles, and fonts from host context.
|
|
564
|
+
*/
|
|
565
|
+
private applyHostContext;
|
|
566
|
+
/**
|
|
567
|
+
* Apply experimental CSS variables to the document root.
|
|
568
|
+
* These are non-standard extensions that enhance the spec styles.
|
|
569
|
+
*/
|
|
570
|
+
private applyExperimentalStyles;
|
|
571
|
+
/**
|
|
572
|
+
* Extract text content from SDK result content array.
|
|
573
|
+
*/
|
|
574
|
+
private extractTextContent;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Claude Desktop Host Client
|
|
579
|
+
*
|
|
580
|
+
* Host client for the Claude Desktop environment.
|
|
581
|
+
* Handles iframe postMessage communication with the Claude Desktop host application.
|
|
582
|
+
*/
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Claude Desktop host client implementation.
|
|
586
|
+
*
|
|
587
|
+
* Provides MCP Apps support for Claude Desktop:
|
|
588
|
+
* - Single-instance only (no multi-instance support)
|
|
589
|
+
* - No dynamic title changes
|
|
590
|
+
* - Inline display mode only
|
|
591
|
+
*
|
|
592
|
+
* Event Buffering:
|
|
593
|
+
* Tool-input and tool-result events may arrive before React components
|
|
594
|
+
* have subscribed (due to useEffect timing). We buffer these events and
|
|
595
|
+
* replay them when the first subscriber is added, ensuring no data is lost.
|
|
596
|
+
*/
|
|
597
|
+
declare class ClaudeDesktopHostClient extends Subscribable implements UnifiedHostClient {
|
|
598
|
+
readonly environment: "mcp-apps";
|
|
599
|
+
private state;
|
|
600
|
+
private config;
|
|
601
|
+
private app;
|
|
602
|
+
private connected;
|
|
603
|
+
private hostContext;
|
|
604
|
+
/**
|
|
605
|
+
* Whether this view was triggered by a tool call.
|
|
606
|
+
* Determined from openContext.triggeredBy in hostContext.
|
|
607
|
+
*/
|
|
608
|
+
private triggeredByTool;
|
|
609
|
+
/**
|
|
610
|
+
* Whether we've received the initial tool-result notification.
|
|
611
|
+
* Used to gate isReady when triggeredByTool is true.
|
|
612
|
+
*/
|
|
613
|
+
private hasReceivedToolResult;
|
|
614
|
+
/**
|
|
615
|
+
* The initial tool result received when view was opened by agent.
|
|
616
|
+
* Stored for getInitialToolResult() access.
|
|
617
|
+
*/
|
|
618
|
+
private initialToolResult;
|
|
619
|
+
/**
|
|
620
|
+
* Buffered events for replay when subscribers are added.
|
|
621
|
+
*
|
|
622
|
+
* Events may arrive before React's useEffect sets up subscriptions.
|
|
623
|
+
* We buffer them here and replay when the first subscriber is added.
|
|
624
|
+
*/
|
|
625
|
+
private bufferedToolInput;
|
|
626
|
+
private bufferedToolResult;
|
|
627
|
+
constructor(config: HostClientConfig);
|
|
628
|
+
/**
|
|
629
|
+
* Create a Claude Desktop host client instance.
|
|
630
|
+
*/
|
|
631
|
+
static create(config: HostClientConfig): ClaudeDesktopHostClient;
|
|
632
|
+
getState(): HostClientState;
|
|
633
|
+
getHostContext(): HostContext | null;
|
|
634
|
+
subscribe(listener: StateListener): () => void;
|
|
635
|
+
/**
|
|
636
|
+
* Connect to the Claude Desktop host.
|
|
637
|
+
*
|
|
638
|
+
* Creates the App instance, registers notification handlers, and initiates
|
|
639
|
+
* the protocol handshake. The host responds with hostContext including
|
|
640
|
+
* theme, styles, and widgetState.
|
|
641
|
+
*/
|
|
642
|
+
connect(): void;
|
|
643
|
+
/**
|
|
644
|
+
* Disconnect from the host.
|
|
645
|
+
*/
|
|
646
|
+
disconnect(): void;
|
|
647
|
+
/**
|
|
648
|
+
* Call a tool on the MCP server via the host.
|
|
649
|
+
*/
|
|
650
|
+
callTool<T = Record<string, unknown>>(toolName: string, args: Record<string, unknown>): Promise<ToolResult<T>>;
|
|
651
|
+
/**
|
|
652
|
+
* Request a display mode change from the host.
|
|
653
|
+
* Claude Desktop only supports inline mode.
|
|
654
|
+
*/
|
|
655
|
+
requestDisplayMode(params: {
|
|
656
|
+
mode: DisplayMode;
|
|
657
|
+
}): Promise<{
|
|
658
|
+
mode: DisplayMode;
|
|
659
|
+
}>;
|
|
660
|
+
/**
|
|
661
|
+
* Send a log message to the host's DevConsole.
|
|
662
|
+
*/
|
|
663
|
+
log(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
664
|
+
on<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
665
|
+
/**
|
|
666
|
+
* Experimental APIs (shared across all hosts).
|
|
667
|
+
* Behavior varies by host - see ExpHostApi for details.
|
|
668
|
+
*/
|
|
669
|
+
get exp(): ExpHostApi;
|
|
670
|
+
/**
|
|
671
|
+
* Send a notification to the host.
|
|
672
|
+
*/
|
|
673
|
+
private sendNotification;
|
|
674
|
+
/**
|
|
675
|
+
* Update internal state and notify listeners.
|
|
676
|
+
*/
|
|
677
|
+
private setState;
|
|
678
|
+
/**
|
|
679
|
+
* Check if there are any subscribers for an event type.
|
|
680
|
+
*/
|
|
681
|
+
private hasSubscribers;
|
|
682
|
+
/**
|
|
683
|
+
* Set up notification handlers on the App instance.
|
|
684
|
+
*
|
|
685
|
+
* Events are buffered if no subscribers exist yet. When a subscriber
|
|
686
|
+
* is added via on(), buffered events are replayed immediately.
|
|
687
|
+
*
|
|
688
|
+
* For tool-triggered views, isReady is set after tool-result is received.
|
|
689
|
+
* This ensures getInitialToolResult() has data when the app initializes.
|
|
690
|
+
*/
|
|
691
|
+
private setupHandlers;
|
|
692
|
+
/**
|
|
693
|
+
* Initiate connection using PostMessageTransport.
|
|
694
|
+
*
|
|
695
|
+
* For user-triggered views: Sets isReady immediately after connection.
|
|
696
|
+
* For tool-triggered views: Waits for tool-result before setting isReady.
|
|
697
|
+
* This ensures getInitialToolResult() has data when the app initializes.
|
|
698
|
+
*
|
|
699
|
+
* Events that arrive before React subscribes are buffered and replayed.
|
|
700
|
+
*/
|
|
701
|
+
private initiateConnection;
|
|
702
|
+
/**
|
|
703
|
+
* Apply theme, styles, and fonts from host context.
|
|
704
|
+
*/
|
|
705
|
+
private applyHostContext;
|
|
706
|
+
/**
|
|
707
|
+
* Apply experimental CSS variables to the document root.
|
|
708
|
+
* These are non-standard extensions that enhance the spec styles.
|
|
709
|
+
*/
|
|
710
|
+
private applyExperimentalStyles;
|
|
711
|
+
/**
|
|
712
|
+
* Extract text content from SDK result content array.
|
|
713
|
+
*/
|
|
714
|
+
private extractTextContent;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* ChatGPT Web Host Client
|
|
719
|
+
*
|
|
720
|
+
* Host client for the ChatGPT web environment.
|
|
721
|
+
* Bridges the ChatGPT Apps SDK (`window.openai`) to the unified interface.
|
|
722
|
+
*/
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* OpenAI bridge interface exposed by ChatGPT Apps SDK.
|
|
726
|
+
* Available on `window.openai` when running inside ChatGPT.
|
|
727
|
+
*/
|
|
728
|
+
interface OpenAIBridge {
|
|
729
|
+
toolOutput?: Record<string, unknown>;
|
|
730
|
+
widgetState?: WidgetState;
|
|
731
|
+
setWidgetState?: (state: WidgetState) => void;
|
|
732
|
+
callTool?: (name: string, args: Record<string, unknown>) => Promise<{
|
|
733
|
+
structuredContent?: Record<string, unknown>;
|
|
734
|
+
content?: Array<{
|
|
735
|
+
type: string;
|
|
736
|
+
text?: string;
|
|
737
|
+
}>;
|
|
738
|
+
}>;
|
|
739
|
+
requestDisplayMode?: (args: {
|
|
740
|
+
mode: string;
|
|
741
|
+
}) => Promise<{
|
|
742
|
+
mode: string;
|
|
743
|
+
}>;
|
|
744
|
+
sendFollowUpMessage?: (prompt: string) => Promise<void>;
|
|
745
|
+
requestModal?: (options: {
|
|
746
|
+
title?: string;
|
|
747
|
+
params?: Record<string, unknown>;
|
|
748
|
+
}) => Promise<unknown>;
|
|
749
|
+
requestClose?: () => Promise<void>;
|
|
750
|
+
}
|
|
751
|
+
declare global {
|
|
752
|
+
interface Window {
|
|
753
|
+
openai?: OpenAIBridge;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* ChatGPT Web host client implementation.
|
|
758
|
+
*
|
|
759
|
+
* Bridges the ChatGPT Apps SDK to provide a unified interface.
|
|
760
|
+
* MCP-specific features are no-ops.
|
|
761
|
+
*/
|
|
762
|
+
declare class ChatGptWebHostClient extends Subscribable implements UnifiedHostClient {
|
|
763
|
+
readonly environment: "chatgpt";
|
|
764
|
+
private state;
|
|
765
|
+
private config;
|
|
766
|
+
private connected;
|
|
767
|
+
private hasProcessedInitialData;
|
|
768
|
+
private globalsHandler;
|
|
769
|
+
private lastToolOutputJson;
|
|
770
|
+
private lastWidgetStateJson;
|
|
771
|
+
constructor(config: HostClientConfig);
|
|
772
|
+
/**
|
|
773
|
+
* Create a ChatGPT Web host client instance.
|
|
774
|
+
*/
|
|
775
|
+
static create(config: HostClientConfig): ChatGptWebHostClient;
|
|
776
|
+
/**
|
|
777
|
+
* Check if the current environment is ChatGPT.
|
|
778
|
+
*/
|
|
779
|
+
static detect(): boolean;
|
|
780
|
+
getState(): HostClientState;
|
|
781
|
+
/**
|
|
782
|
+
* Get host context - returns null for ChatGPT as it doesn't use MCP Apps protocol.
|
|
783
|
+
*/
|
|
784
|
+
getHostContext(): HostContext | null;
|
|
785
|
+
subscribe(listener: StateListener): () => void;
|
|
786
|
+
/**
|
|
787
|
+
* Connect to the ChatGPT host.
|
|
788
|
+
*
|
|
789
|
+
* Processes initial data from `window.openai` and sets up a listener
|
|
790
|
+
* for subsequent `openai:set_globals` events.
|
|
791
|
+
*/
|
|
792
|
+
connect(): void;
|
|
793
|
+
/**
|
|
794
|
+
* Disconnect from the host.
|
|
795
|
+
*/
|
|
796
|
+
disconnect(): void;
|
|
797
|
+
/**
|
|
798
|
+
* Call a tool on the MCP server via the ChatGPT bridge.
|
|
799
|
+
*/
|
|
800
|
+
callTool<T = Record<string, unknown>>(toolName: string, args: Record<string, unknown>): Promise<ToolResult<T>>;
|
|
801
|
+
/**
|
|
802
|
+
* Request a display mode change from the ChatGPT host.
|
|
803
|
+
*/
|
|
804
|
+
requestDisplayMode(params: {
|
|
805
|
+
mode: DisplayMode;
|
|
806
|
+
}): Promise<{
|
|
807
|
+
mode: DisplayMode;
|
|
808
|
+
}>;
|
|
809
|
+
/**
|
|
810
|
+
* Log a message to the console.
|
|
811
|
+
* ChatGPT doesn't have a DevConsole, so logs go to browser console only.
|
|
812
|
+
*/
|
|
813
|
+
log(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
814
|
+
on<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
815
|
+
/**
|
|
816
|
+
* Experimental APIs (shared across all hosts).
|
|
817
|
+
* Behavior varies by host - see ExpHostApi for details.
|
|
818
|
+
*/
|
|
819
|
+
get exp(): ExpHostApi;
|
|
820
|
+
/**
|
|
821
|
+
* Update internal state and notify listeners.
|
|
822
|
+
*/
|
|
823
|
+
private setState;
|
|
824
|
+
/**
|
|
825
|
+
* Process initial data from `window.openai`.
|
|
826
|
+
*/
|
|
827
|
+
private processInitialData;
|
|
828
|
+
/**
|
|
829
|
+
* Set up listener for `openai:set_globals` events.
|
|
830
|
+
*/
|
|
831
|
+
private setupGlobalsListener;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Standalone Host Client
|
|
836
|
+
*
|
|
837
|
+
* A minimal fallback for when running outside any host environment.
|
|
838
|
+
* Useful for development and testing scenarios.
|
|
839
|
+
*/
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Standalone host client implementation.
|
|
843
|
+
*
|
|
844
|
+
* A minimal fallback for development and testing scenarios.
|
|
845
|
+
* Host-specific features are no-ops or console-logged.
|
|
846
|
+
*/
|
|
847
|
+
declare class StandaloneHostClient extends Subscribable implements UnifiedHostClient {
|
|
848
|
+
readonly environment: "standalone";
|
|
849
|
+
private state;
|
|
850
|
+
private config;
|
|
851
|
+
private connected;
|
|
852
|
+
constructor(config: HostClientConfig);
|
|
853
|
+
/**
|
|
854
|
+
* Create a Standalone host client instance.
|
|
855
|
+
*/
|
|
856
|
+
static create(config: HostClientConfig): StandaloneHostClient;
|
|
857
|
+
/**
|
|
858
|
+
* Check if the current environment is standalone.
|
|
859
|
+
* Returns true when not in ChatGPT or MCP Apps.
|
|
860
|
+
*/
|
|
861
|
+
static detect(): boolean;
|
|
862
|
+
getState(): HostClientState;
|
|
863
|
+
/**
|
|
864
|
+
* Get host context - returns null for standalone mode.
|
|
865
|
+
*/
|
|
866
|
+
getHostContext(): HostContext | null;
|
|
867
|
+
subscribe(listener: StateListener): () => void;
|
|
868
|
+
/**
|
|
869
|
+
* Connect in standalone mode.
|
|
870
|
+
* Simply marks the client as ready since there's no host to connect to.
|
|
871
|
+
*/
|
|
872
|
+
connect(): void;
|
|
873
|
+
/**
|
|
874
|
+
* Disconnect in standalone mode.
|
|
875
|
+
*/
|
|
876
|
+
disconnect(): void;
|
|
877
|
+
/**
|
|
878
|
+
* Call a tool - not available in standalone mode.
|
|
879
|
+
*/
|
|
880
|
+
callTool<T = Record<string, unknown>>(toolName: string, _args: Record<string, unknown>): Promise<ToolResult<T>>;
|
|
881
|
+
/**
|
|
882
|
+
* Request a display mode - returns the requested mode since there's no host.
|
|
883
|
+
*/
|
|
884
|
+
requestDisplayMode(params: {
|
|
885
|
+
mode: DisplayMode;
|
|
886
|
+
}): Promise<{
|
|
887
|
+
mode: DisplayMode;
|
|
888
|
+
}>;
|
|
889
|
+
/**
|
|
890
|
+
* Log a message to the console.
|
|
891
|
+
*/
|
|
892
|
+
log(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
893
|
+
on<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
894
|
+
/**
|
|
895
|
+
* Experimental APIs for non-standard features.
|
|
896
|
+
* All methods are logged for development/debugging purposes.
|
|
897
|
+
*/
|
|
898
|
+
get exp(): ExpHostApi;
|
|
899
|
+
/**
|
|
900
|
+
* Update internal state and notify listeners.
|
|
901
|
+
*/
|
|
902
|
+
private setState;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Environment-Aware Default Styles
|
|
907
|
+
*
|
|
908
|
+
* This module provides default CSS variable values for MCP Apps and ChatGPT Apps.
|
|
909
|
+
* Import `initDefaultStyles` early in your app entry point to prevent flash of unstyled content.
|
|
910
|
+
*
|
|
911
|
+
* The MCP Apps spec defines CSS variable names (e.g., --color-background-primary).
|
|
912
|
+
* This module provides environment-specific VALUES for those variables as sensible
|
|
913
|
+
* defaults until the host injects its own values.
|
|
914
|
+
*
|
|
915
|
+
* Flow:
|
|
916
|
+
* 1. Detect environment (ChatGPT, MCP Apps, or Standalone)
|
|
917
|
+
* 2. Detect theme (light or dark)
|
|
918
|
+
* 3. Inject defaults immediately on document.documentElement
|
|
919
|
+
* 4. When host connects, host variables override these defaults
|
|
920
|
+
*
|
|
921
|
+
* IMPORTANT: MCP Apps defaults match Creature's actual values exactly.
|
|
922
|
+
* The observer only runs for ChatGPT (MCP Apps hosts handle theme changes themselves).
|
|
923
|
+
*/
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Theme mode for styling.
|
|
927
|
+
*/
|
|
928
|
+
type Theme = "light" | "dark";
|
|
929
|
+
/**
|
|
930
|
+
* Options for initializing styles.
|
|
931
|
+
*/
|
|
932
|
+
interface InitStylesOptions {
|
|
933
|
+
/** Whether to set up a MutationObserver for dynamic theme changes. Default: true for ChatGPT only */
|
|
934
|
+
observeThemeChanges?: boolean;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* MCP Apps / Creature default values - DARK mode.
|
|
938
|
+
* These values are extracted directly from Creature's globals.css.
|
|
939
|
+
* They MUST match exactly what Creature sends via hostContext.styles.variables.
|
|
940
|
+
*/
|
|
941
|
+
declare const MCP_APPS_DARK_DEFAULTS: Record<string, string>;
|
|
942
|
+
/**
|
|
943
|
+
* MCP Apps / Creature default values - LIGHT mode.
|
|
944
|
+
* These values are extracted directly from Creature's globals.css.
|
|
945
|
+
*/
|
|
946
|
+
declare const MCP_APPS_LIGHT_DEFAULTS: Record<string, string>;
|
|
947
|
+
/**
|
|
948
|
+
* Shared MCP Apps / Creature typography and layout tokens (same for light/dark).
|
|
949
|
+
* These values are extracted directly from Creature's globals.css.
|
|
950
|
+
*/
|
|
951
|
+
declare const MCP_APPS_SHARED_DEFAULTS: Record<string, string>;
|
|
952
|
+
/**
|
|
953
|
+
* ChatGPT Apps default values - LIGHT mode.
|
|
954
|
+
* Ported from @openai/apps-sdk-ui design tokens.
|
|
955
|
+
*/
|
|
956
|
+
declare const CHATGPT_LIGHT_DEFAULTS: Record<string, string>;
|
|
957
|
+
/**
|
|
958
|
+
* ChatGPT Apps default values - DARK mode.
|
|
959
|
+
*/
|
|
960
|
+
declare const CHATGPT_DARK_DEFAULTS: Record<string, string>;
|
|
961
|
+
/**
|
|
962
|
+
* Shared ChatGPT typography and layout tokens (same for light/dark).
|
|
963
|
+
*/
|
|
964
|
+
declare const CHATGPT_SHARED_DEFAULTS: Record<string, string>;
|
|
965
|
+
/**
|
|
966
|
+
* Get MCP Apps default styles for the specified theme.
|
|
967
|
+
* Returns CSS variable names with their default values.
|
|
968
|
+
* These values match exactly what Creature sends via hostContext.styles.variables.
|
|
969
|
+
*
|
|
970
|
+
* @param theme - The theme to get defaults for
|
|
971
|
+
* @returns Record of CSS variable names to their values
|
|
972
|
+
*/
|
|
973
|
+
declare const getMcpAppDefaultStyles: ({ theme }: {
|
|
974
|
+
theme: Theme;
|
|
975
|
+
}) => Record<string, string>;
|
|
976
|
+
/**
|
|
977
|
+
* Get ChatGPT Apps default styles for the specified theme.
|
|
978
|
+
* Returns CSS variable names with their values matching the @openai/apps-sdk-ui design tokens.
|
|
979
|
+
*
|
|
980
|
+
* @param theme - The theme to get defaults for
|
|
981
|
+
* @returns Record of CSS variable names to their values
|
|
982
|
+
*/
|
|
983
|
+
declare const getChatGptDefaultStyles: ({ theme }: {
|
|
984
|
+
theme: Theme;
|
|
985
|
+
}) => Record<string, string>;
|
|
986
|
+
/**
|
|
987
|
+
* Detect the current theme from the document.
|
|
988
|
+
* Checks data-theme attribute, dark class (Tailwind), and prefers-color-scheme.
|
|
989
|
+
*
|
|
990
|
+
* @returns The detected theme
|
|
991
|
+
*/
|
|
992
|
+
declare const detectTheme: () => Theme;
|
|
993
|
+
/**
|
|
994
|
+
* Apply CSS variables to the document root.
|
|
995
|
+
*
|
|
996
|
+
* @param styles - Record of CSS variable names to their values
|
|
997
|
+
*/
|
|
998
|
+
declare const applyStyles: ({ styles }: {
|
|
999
|
+
styles: Record<string, string>;
|
|
1000
|
+
}) => void;
|
|
1001
|
+
/**
|
|
1002
|
+
* Initialize default styles based on detected environment and theme.
|
|
1003
|
+
* This should be called early in your app entry point to prevent FOUC.
|
|
1004
|
+
*
|
|
1005
|
+
* For MCP Apps (Creature): Applies defaults once. The host handles theme changes
|
|
1006
|
+
* and sends new styles via hostContext, which override these defaults.
|
|
1007
|
+
*
|
|
1008
|
+
* For ChatGPT: Applies defaults and sets up an observer to handle theme changes,
|
|
1009
|
+
* since ChatGPT may change theme before sending new hostContext.
|
|
1010
|
+
*
|
|
1011
|
+
* @param environment - The detected environment (from detectEnvironment)
|
|
1012
|
+
* @param options - Configuration options
|
|
1013
|
+
*/
|
|
1014
|
+
declare const initDefaultStyles: ({ environment, options, }: {
|
|
1015
|
+
environment: Environment;
|
|
1016
|
+
options?: InitStylesOptions;
|
|
1017
|
+
}) => void;
|
|
1018
|
+
|
|
1019
|
+
/**
|
|
1020
|
+
* Create a WebSocket client with automatic reconnection.
|
|
1021
|
+
*
|
|
1022
|
+
* @param url - WebSocket server URL
|
|
1023
|
+
* @param config - Client configuration
|
|
1024
|
+
* @returns WebSocket client instance
|
|
1025
|
+
*/
|
|
1026
|
+
declare function createWebSocket<TSend = unknown, TReceive = unknown>(url: string, config?: WebSocketClientConfig<TReceive>): WebSocketClient<TSend, TReceive>;
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Core Host Client Module
|
|
1030
|
+
*
|
|
1031
|
+
* Provides the unified host client factory and all related types.
|
|
1032
|
+
* This is the main entry point for client-side SDK usage.
|
|
1033
|
+
*/
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Detect the current host environment.
|
|
1037
|
+
*
|
|
1038
|
+
* Used to auto-select the appropriate host client implementation:
|
|
1039
|
+
* - "chatgpt": Running inside ChatGPT's widget system
|
|
1040
|
+
* - "mcp-apps": Running inside an MCP Apps host (iframe with parent)
|
|
1041
|
+
* - "standalone": Running outside any host environment
|
|
1042
|
+
*
|
|
1043
|
+
* @returns The detected environment
|
|
1044
|
+
*/
|
|
1045
|
+
declare const detectEnvironment: () => Environment;
|
|
1046
|
+
/**
|
|
1047
|
+
* Create a host client for the detected environment.
|
|
1048
|
+
*
|
|
1049
|
+
* Automatically selects the appropriate client based on runtime detection:
|
|
1050
|
+
* - ChatGPT Web: Uses ChatGptWebHostClient (detects window.openai)
|
|
1051
|
+
* - MCP Apps: Uses CreatureDesktopHostClient (detects iframe with parent)
|
|
1052
|
+
* - Standalone: Uses StandaloneHostClient for development/testing
|
|
1053
|
+
*
|
|
1054
|
+
* Note: For MCP Apps environments, this returns CreatureDesktopHostClient by default.
|
|
1055
|
+
* Use createHostAsync() for proper host detection via userAgent after connection.
|
|
1056
|
+
*
|
|
1057
|
+
* @param config - Configuration for the host client
|
|
1058
|
+
* @returns The appropriate host client for the environment
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* ```typescript
|
|
1062
|
+
* const host = createHost({ name: "my-app", version: "1.0.0" });
|
|
1063
|
+
* host.connect();
|
|
1064
|
+
*
|
|
1065
|
+
* // Call tools
|
|
1066
|
+
* const result = await host.callTool("get_todos", {});
|
|
1067
|
+
*
|
|
1068
|
+
* // Use experimental features (graceful degradation)
|
|
1069
|
+
* host.exp.setTitle("My Widget");
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
declare const createHost: (config: HostClientConfig) => UnifiedHostClient;
|
|
1073
|
+
/**
|
|
1074
|
+
* Create a host client asynchronously with proper host detection.
|
|
1075
|
+
*
|
|
1076
|
+
* Unlike createHost(), this function:
|
|
1077
|
+
* 1. Connects to the host
|
|
1078
|
+
* 2. Detects the specific host type via userAgent
|
|
1079
|
+
* 3. Returns the appropriate client (CreatureDesktop, ClaudeDesktop, etc.)
|
|
1080
|
+
*
|
|
1081
|
+
* For MCP Apps environments, this performs deferred detection by connecting
|
|
1082
|
+
* first, then checking the userAgent to select the correct client.
|
|
1083
|
+
*
|
|
1084
|
+
* @param config - Configuration for the host client
|
|
1085
|
+
* @returns Promise that resolves to the configured host client after connection
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* const host = await createHostAsync({ name: "my-app", version: "1.0.0" });
|
|
1090
|
+
* // host is now ready to use with correct host-specific behavior
|
|
1091
|
+
* ```
|
|
1092
|
+
*/
|
|
1093
|
+
declare const createHostAsync: (config: HostClientConfig) => Promise<UnifiedHostClient>;
|
|
1094
|
+
|
|
1095
|
+
export { CHATGPT_DARK_DEFAULTS, CHATGPT_LIGHT_DEFAULTS, CHATGPT_SHARED_DEFAULTS, ChatGptWebHostClient, ClaudeDesktopHostClient, type ContentBlock, CreatureDesktopHostClient, type DisplayMode, type Environment, type ExpHostApi, type HostClientConfig, type HostClientEvents, type HostClientState, type HostContext, type ImageContentBlock, type InitStylesOptions, type LogLevel, MCP_APPS_DARK_DEFAULTS, MCP_APPS_LIGHT_DEFAULTS, MCP_APPS_SHARED_DEFAULTS, type OpenContext, StandaloneHostClient, type StateListener, type StructuredWidgetState, type TextContentBlock, type Theme, type ToolResult, type UnifiedHostClient, type WebSocketClient, type WebSocketClientConfig, type WebSocketStatus, type WidgetState, applyStyles, createHost, createHostAsync, createWebSocket, detectEnvironment, detectTheme, getChatGptDefaultStyles, getMcpAppDefaultStyles, initDefaultStyles };
|