@sidecar-ai/client 0.1.0-alpha.0
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/index.d.ts +290 -0
- package/dist/index.js +449 -0
- package/dist/index.js.map +1 -0
- package/package.json +21 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/** Standard result shape for host-only capabilities that may not exist everywhere. */
|
|
2
|
+
type HostFeatureResult<T = void> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
value: T;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
reason: "unsupported" | "denied" | "cancelled" | "failed";
|
|
8
|
+
message?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Host families Sidecar can theme and feature-detect at runtime. */
|
|
11
|
+
type SidecarHostName = "chatgpt" | "claude" | "generic";
|
|
12
|
+
/** Display theme reported by the host or inferred from browser settings. */
|
|
13
|
+
type SidecarTheme = "light" | "dark";
|
|
14
|
+
/** Display modes defined by the MCP Apps extension. */
|
|
15
|
+
type SidecarDisplayMode = "inline" | "fullscreen" | "pip";
|
|
16
|
+
/** Runtime host information used by React/native packages. */
|
|
17
|
+
type SidecarHostContext = {
|
|
18
|
+
/** Host family currently embedding the widget. */
|
|
19
|
+
name: SidecarHostName;
|
|
20
|
+
/** Light/dark theme for host-aligned native components. */
|
|
21
|
+
theme: SidecarTheme;
|
|
22
|
+
/** Whether the context came from the MCP Apps bridge, a host fallback, or browser inference. */
|
|
23
|
+
source: "mcp-apps" | "claude-css" | "media-query" | "fallback";
|
|
24
|
+
/** Raw MCP Apps host context when supplied by the host. */
|
|
25
|
+
raw?: unknown;
|
|
26
|
+
};
|
|
27
|
+
/** Listener called when the embedding host changes theme or capability context. */
|
|
28
|
+
type HostContextListener = (context: SidecarHostContext) => void;
|
|
29
|
+
/** Minimal MCP content block shape used by client-side bridge calls. */
|
|
30
|
+
type ClientContentBlock = {
|
|
31
|
+
type: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
/** Tool result data made available to a rendered widget. */
|
|
35
|
+
type WidgetToolResult<Structured = unknown, Meta = Record<string, unknown>> = {
|
|
36
|
+
/** Structured data sent through the standard MCP `structuredContent` field. */
|
|
37
|
+
structuredContent: Structured | undefined;
|
|
38
|
+
/** Backward-compatible alias for early Sidecar examples. Prefer `structuredContent`. */
|
|
39
|
+
structured: Structured | undefined;
|
|
40
|
+
/** Model-visible MCP content blocks. */
|
|
41
|
+
content: unknown[];
|
|
42
|
+
/** Host/widget-only metadata from MCP `_meta`. */
|
|
43
|
+
meta: Meta;
|
|
44
|
+
/** Standard MCP metadata field. */
|
|
45
|
+
_meta?: Meta;
|
|
46
|
+
/** Whether the tool result represents a tool execution error. */
|
|
47
|
+
isError?: boolean;
|
|
48
|
+
};
|
|
49
|
+
/** Message a widget wants to send back into the model conversation. */
|
|
50
|
+
type ModelMessage = {
|
|
51
|
+
/** Convenience text. Sidecar normalizes this to one MCP text content block. */
|
|
52
|
+
text?: string;
|
|
53
|
+
/** Exact MCP content blocks for richer messages. Takes precedence over `text`. */
|
|
54
|
+
content?: ClientContentBlock[];
|
|
55
|
+
};
|
|
56
|
+
/** Resource descriptor returned by standard MCP `resources/list`. */
|
|
57
|
+
type ServerResource = {
|
|
58
|
+
uri: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
mimeType?: string;
|
|
62
|
+
_meta?: Record<string, unknown>;
|
|
63
|
+
[key: string]: unknown;
|
|
64
|
+
};
|
|
65
|
+
/** Resource content returned by standard MCP `resources/read`. */
|
|
66
|
+
type ServerResourceContent = {
|
|
67
|
+
uri: string;
|
|
68
|
+
mimeType?: string;
|
|
69
|
+
text?: string;
|
|
70
|
+
blob?: string;
|
|
71
|
+
_meta?: Record<string, unknown>;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
};
|
|
74
|
+
/** Result of standard MCP `resources/list` proxied through the Apps host. */
|
|
75
|
+
type ServerResourceListResult = {
|
|
76
|
+
resources: ServerResource[];
|
|
77
|
+
nextCursor?: string;
|
|
78
|
+
_meta?: Record<string, unknown>;
|
|
79
|
+
[key: string]: unknown;
|
|
80
|
+
};
|
|
81
|
+
/** Result of standard MCP `resources/read` proxied through the Apps host. */
|
|
82
|
+
type ServerResourceReadResult = {
|
|
83
|
+
contents: ServerResourceContent[];
|
|
84
|
+
_meta?: Record<string, unknown>;
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
};
|
|
87
|
+
/** Standard MCP sampling request params passed through the Apps host. */
|
|
88
|
+
type SamplingMessageRequest = Record<string, unknown>;
|
|
89
|
+
/** Standard MCP sampling result returned by the Apps host. */
|
|
90
|
+
type SamplingMessageResult = Record<string, unknown>;
|
|
91
|
+
/** Standard MCP log message levels. */
|
|
92
|
+
type HostLogLevel = "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency";
|
|
93
|
+
/** Standard MCP log notification payload sent through the Apps host. */
|
|
94
|
+
type HostLogMessage = {
|
|
95
|
+
level: HostLogLevel;
|
|
96
|
+
data: unknown;
|
|
97
|
+
logger?: string;
|
|
98
|
+
};
|
|
99
|
+
/** Standard MCP Apps size-change notification payload. */
|
|
100
|
+
type SizeChangedMessage = {
|
|
101
|
+
width: number;
|
|
102
|
+
height: number;
|
|
103
|
+
};
|
|
104
|
+
/** Complete or partial tool input sent by the host before a tool result arrives. */
|
|
105
|
+
type ToolInput = {
|
|
106
|
+
arguments?: Record<string, unknown>;
|
|
107
|
+
[key: string]: unknown;
|
|
108
|
+
};
|
|
109
|
+
/** Host bridge capabilities available to widget code. */
|
|
110
|
+
type WidgetBridge = {
|
|
111
|
+
callServerTool<TParams extends Record<string, unknown> = Record<string, unknown>, Structured = unknown, Meta = Record<string, unknown>>(params: {
|
|
112
|
+
name: string;
|
|
113
|
+
arguments?: TParams;
|
|
114
|
+
}): Promise<WidgetToolResult<Structured, Meta>>;
|
|
115
|
+
callTool<TParams extends Record<string, unknown>, TResult>(name: string, params: TParams): Promise<TResult>;
|
|
116
|
+
readServerResource(params: {
|
|
117
|
+
uri: string;
|
|
118
|
+
}): Promise<HostFeatureResult<ServerResourceReadResult>>;
|
|
119
|
+
listServerResources(params?: {
|
|
120
|
+
cursor?: string;
|
|
121
|
+
}): Promise<HostFeatureResult<ServerResourceListResult>>;
|
|
122
|
+
createSamplingMessage(params: SamplingMessageRequest): Promise<HostFeatureResult<SamplingMessageResult>>;
|
|
123
|
+
sendMessage(message: ModelMessage): Promise<HostFeatureResult>;
|
|
124
|
+
updateModelContext(context: Record<string, unknown>): Promise<HostFeatureResult>;
|
|
125
|
+
sendLog(message: HostLogMessage): Promise<HostFeatureResult>;
|
|
126
|
+
openLink(url: string): Promise<HostFeatureResult>;
|
|
127
|
+
downloadFile(contents: ClientContentBlock[]): Promise<HostFeatureResult>;
|
|
128
|
+
requestTeardown(params?: Record<string, never>): Promise<HostFeatureResult>;
|
|
129
|
+
requestDisplayMode(mode: SidecarDisplayMode): Promise<HostFeatureResult<SidecarDisplayMode>>;
|
|
130
|
+
sendSizeChanged(size: SizeChangedMessage): Promise<HostFeatureResult>;
|
|
131
|
+
getToolResult<Structured, Meta = Record<string, unknown>>(): WidgetToolResult<Structured, Meta>;
|
|
132
|
+
subscribeToolInput(listener: ToolInputListener): () => void;
|
|
133
|
+
subscribeToolInputPartial(listener: ToolInputListener): () => void;
|
|
134
|
+
subscribeToolResult(listener: ToolResultListener): () => void;
|
|
135
|
+
subscribeToolCancelled(listener: ToolCancelledListener): () => void;
|
|
136
|
+
getHostContext(): SidecarHostContext;
|
|
137
|
+
getHostCapabilities(): Record<string, unknown> | undefined;
|
|
138
|
+
subscribeHostContext(listener: HostContextListener): () => void;
|
|
139
|
+
};
|
|
140
|
+
/** Listener called when the host sends standard MCP Apps tool input. */
|
|
141
|
+
type ToolInputListener = (input: ToolInput) => void;
|
|
142
|
+
/** Listener called when the host sends a standard MCP Apps tool-result notification. */
|
|
143
|
+
type ToolResultListener = (result: WidgetToolResult) => void;
|
|
144
|
+
/** Listener called when the host cancels the active tool execution. */
|
|
145
|
+
type ToolCancelledListener = (params: {
|
|
146
|
+
reason?: string;
|
|
147
|
+
}) => void;
|
|
148
|
+
/** Structural constraint for generated typed tool clients. */
|
|
149
|
+
type ToolClientShape = object;
|
|
150
|
+
/** Creates a browser bridge that speaks MCP Apps first and ChatGPT globals second. */
|
|
151
|
+
declare function createBrowserBridge(): WidgetBridge;
|
|
152
|
+
/** Default browser bridge used by generated widget clients. */
|
|
153
|
+
declare const browserBridge: WidgetBridge;
|
|
154
|
+
/** Convenience object for sending model messages and context updates. */
|
|
155
|
+
declare const model: {
|
|
156
|
+
message(message: ModelMessage): Promise<HostFeatureResult>;
|
|
157
|
+
context: {
|
|
158
|
+
update(context: Record<string, unknown>): Promise<HostFeatureResult>;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
/** Convenience object for server-bound MCP requests proxied by the Apps host. */
|
|
162
|
+
declare const server: {
|
|
163
|
+
tool<TParams extends Record<string, unknown> = Record<string, unknown>, Structured = unknown, Meta = Record<string, unknown>>(params: {
|
|
164
|
+
name: string;
|
|
165
|
+
arguments?: TParams;
|
|
166
|
+
}): Promise<WidgetToolResult<Structured, Meta>>;
|
|
167
|
+
resource: {
|
|
168
|
+
read(params: {
|
|
169
|
+
uri: string;
|
|
170
|
+
}): Promise<HostFeatureResult<ServerResourceReadResult>>;
|
|
171
|
+
list(params?: {
|
|
172
|
+
cursor?: string;
|
|
173
|
+
}): Promise<HostFeatureResult<ServerResourceListResult>>;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
/** Convenience object for standard host sampling requests. */
|
|
177
|
+
declare const sampling: {
|
|
178
|
+
createMessage(params: SamplingMessageRequest): Promise<HostFeatureResult<SamplingMessageResult>>;
|
|
179
|
+
};
|
|
180
|
+
/** Convenience object for standard host logging notifications. */
|
|
181
|
+
declare const log: {
|
|
182
|
+
send(message: HostLogMessage): Promise<HostFeatureResult>;
|
|
183
|
+
};
|
|
184
|
+
/** Convenience object for view lifecycle and layout notifications. */
|
|
185
|
+
declare const view: {
|
|
186
|
+
requestTeardown(params?: Record<string, never>): Promise<HostFeatureResult>;
|
|
187
|
+
sizeChanged(size: SizeChangedMessage): Promise<HostFeatureResult>;
|
|
188
|
+
};
|
|
189
|
+
/** Reads the current tool result from the default browser bridge. */
|
|
190
|
+
declare function getToolResult<Structured, Meta = Record<string, unknown>>(): WidgetToolResult<Structured, Meta>;
|
|
191
|
+
/**
|
|
192
|
+
* Creates a typed proxy where method calls become host tool calls.
|
|
193
|
+
*
|
|
194
|
+
* Generated clients pass the machine-name map while user code calls readable
|
|
195
|
+
* camelCase methods.
|
|
196
|
+
*/
|
|
197
|
+
declare function createToolClient<TTools extends ToolClientShape>(names: Record<Extract<keyof TTools, string>, string>, bridge?: Pick<WidgetBridge, "callTool">): TTools;
|
|
198
|
+
type McpAppsToolResult = {
|
|
199
|
+
structuredContent?: unknown;
|
|
200
|
+
content?: unknown[];
|
|
201
|
+
_meta?: Record<string, unknown>;
|
|
202
|
+
isError?: boolean;
|
|
203
|
+
[key: string]: unknown;
|
|
204
|
+
};
|
|
205
|
+
type McpAppsHostCapabilities = {
|
|
206
|
+
serverTools?: unknown;
|
|
207
|
+
openLinks?: unknown;
|
|
208
|
+
downloadFile?: unknown;
|
|
209
|
+
updateModelContext?: unknown;
|
|
210
|
+
message?: unknown;
|
|
211
|
+
[key: string]: unknown;
|
|
212
|
+
};
|
|
213
|
+
type McpAppsHostContext = {
|
|
214
|
+
theme?: "light" | "dark";
|
|
215
|
+
userAgent?: string;
|
|
216
|
+
displayMode?: SidecarDisplayMode;
|
|
217
|
+
availableDisplayModes?: SidecarDisplayMode[];
|
|
218
|
+
[key: string]: unknown;
|
|
219
|
+
};
|
|
220
|
+
type McpAppsRuntime = {
|
|
221
|
+
connect(transport: unknown, options?: Record<string, unknown>): Promise<void>;
|
|
222
|
+
callServerTool(params: {
|
|
223
|
+
name: string;
|
|
224
|
+
arguments?: Record<string, unknown>;
|
|
225
|
+
}): Promise<McpAppsToolResult>;
|
|
226
|
+
readServerResource(params: {
|
|
227
|
+
uri: string;
|
|
228
|
+
}): Promise<ServerResourceReadResult>;
|
|
229
|
+
listServerResources(params?: {
|
|
230
|
+
cursor?: string;
|
|
231
|
+
}): Promise<ServerResourceListResult>;
|
|
232
|
+
createSamplingMessage(params: SamplingMessageRequest): Promise<SamplingMessageResult>;
|
|
233
|
+
sendMessage(params: {
|
|
234
|
+
role: "user";
|
|
235
|
+
content: ClientContentBlock[];
|
|
236
|
+
}): Promise<{
|
|
237
|
+
isError?: boolean;
|
|
238
|
+
}>;
|
|
239
|
+
sendLog(params: HostLogMessage): Promise<void>;
|
|
240
|
+
updateModelContext(params: {
|
|
241
|
+
content?: ClientContentBlock[];
|
|
242
|
+
structuredContent?: Record<string, unknown>;
|
|
243
|
+
}): Promise<unknown>;
|
|
244
|
+
openLink(params: {
|
|
245
|
+
url: string;
|
|
246
|
+
}): Promise<{
|
|
247
|
+
isError?: boolean;
|
|
248
|
+
}>;
|
|
249
|
+
downloadFile(params: {
|
|
250
|
+
contents: ClientContentBlock[];
|
|
251
|
+
}): Promise<{
|
|
252
|
+
isError?: boolean;
|
|
253
|
+
}>;
|
|
254
|
+
requestTeardown(params?: Record<string, never>): Promise<void>;
|
|
255
|
+
requestDisplayMode(params: {
|
|
256
|
+
mode: SidecarDisplayMode;
|
|
257
|
+
}): Promise<{
|
|
258
|
+
mode: SidecarDisplayMode;
|
|
259
|
+
}>;
|
|
260
|
+
sendSizeChanged(params: SizeChangedMessage): Promise<void>;
|
|
261
|
+
getHostCapabilities(): McpAppsHostCapabilities | undefined;
|
|
262
|
+
getHostContext(): McpAppsHostContext | undefined;
|
|
263
|
+
ontoolinput?: (params: ToolInput) => void;
|
|
264
|
+
ontoolinputpartial?: (params: ToolInput) => void;
|
|
265
|
+
ontoolresult?: (params: McpAppsToolResult) => void;
|
|
266
|
+
onhostcontextchanged?: (params: McpAppsHostContext) => void;
|
|
267
|
+
ontoolcancelled?: (params: {
|
|
268
|
+
reason?: string;
|
|
269
|
+
}) => void;
|
|
270
|
+
onteardown?: () => Record<string, never> | Promise<Record<string, never>>;
|
|
271
|
+
};
|
|
272
|
+
type McpAppsState = {
|
|
273
|
+
app?: McpAppsRuntime;
|
|
274
|
+
connectPromise?: Promise<McpAppsRuntime | undefined>;
|
|
275
|
+
connected: boolean;
|
|
276
|
+
failed: boolean;
|
|
277
|
+
hostContext?: McpAppsHostContext;
|
|
278
|
+
toolResult?: WidgetToolResult;
|
|
279
|
+
hostContextListeners: Set<HostContextListener>;
|
|
280
|
+
toolInputListeners: Set<ToolInputListener>;
|
|
281
|
+
toolInputPartialListeners: Set<ToolInputListener>;
|
|
282
|
+
toolResultListeners: Set<ToolResultListener>;
|
|
283
|
+
toolCancelledListeners: Set<ToolCancelledListener>;
|
|
284
|
+
};
|
|
285
|
+
/** Detects the active widget host without relying on build-time target flags. */
|
|
286
|
+
declare function detectHostContext(): SidecarHostContext;
|
|
287
|
+
/** Subscribes to host context/theme changes from the MCP Apps bridge and media queries. */
|
|
288
|
+
declare function subscribeHostContext(listener: HostContextListener, state?: McpAppsState): () => void;
|
|
289
|
+
|
|
290
|
+
export { type ClientContentBlock, type HostContextListener, type HostFeatureResult, type HostLogLevel, type HostLogMessage, type ModelMessage, type SamplingMessageRequest, type SamplingMessageResult, type ServerResource, type ServerResourceContent, type ServerResourceListResult, type ServerResourceReadResult, type SidecarDisplayMode, type SidecarHostContext, type SidecarHostName, type SidecarTheme, type SizeChangedMessage, type ToolCancelledListener, type ToolClientShape, type ToolInput, type ToolInputListener, type ToolResultListener, type WidgetBridge, type WidgetToolResult, browserBridge, createBrowserBridge, createToolClient, detectHostContext, getToolResult, log, model, sampling, server, subscribeHostContext, view };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
// packages/client/src/index.ts
|
|
2
|
+
import { App, PostMessageTransport } from "@modelcontextprotocol/ext-apps/app-with-deps";
|
|
3
|
+
function createBrowserBridge() {
|
|
4
|
+
const state = createMcpAppsState();
|
|
5
|
+
return {
|
|
6
|
+
async callServerTool(params) {
|
|
7
|
+
return callServerTool(state, params);
|
|
8
|
+
},
|
|
9
|
+
async callTool(name, params) {
|
|
10
|
+
const result = await callServerTool(state, { name, arguments: params });
|
|
11
|
+
return result.structuredContent;
|
|
12
|
+
},
|
|
13
|
+
async readServerResource(params) {
|
|
14
|
+
const app = await readyMcpApp(state);
|
|
15
|
+
if (app?.getHostCapabilities()?.serverResources) {
|
|
16
|
+
return { ok: true, value: await app.readServerResource(params) };
|
|
17
|
+
}
|
|
18
|
+
return { ok: false, reason: "unsupported" };
|
|
19
|
+
},
|
|
20
|
+
async listServerResources(params) {
|
|
21
|
+
const app = await readyMcpApp(state);
|
|
22
|
+
if (app?.getHostCapabilities()?.serverResources) {
|
|
23
|
+
return { ok: true, value: await app.listServerResources(params) };
|
|
24
|
+
}
|
|
25
|
+
return { ok: false, reason: "unsupported" };
|
|
26
|
+
},
|
|
27
|
+
async createSamplingMessage(params) {
|
|
28
|
+
const app = await readyMcpApp(state);
|
|
29
|
+
if (app?.getHostCapabilities()?.sampling) {
|
|
30
|
+
return { ok: true, value: await app.createSamplingMessage(params) };
|
|
31
|
+
}
|
|
32
|
+
return { ok: false, reason: "unsupported" };
|
|
33
|
+
},
|
|
34
|
+
async sendMessage(message) {
|
|
35
|
+
const app = await readyMcpApp(state);
|
|
36
|
+
if (app?.getHostCapabilities()?.message) {
|
|
37
|
+
const result = await app.sendMessage({
|
|
38
|
+
role: "user",
|
|
39
|
+
content: normalizeMessageContent(message)
|
|
40
|
+
});
|
|
41
|
+
return result.isError ? { ok: false, reason: "denied" } : { ok: true, value: void 0 };
|
|
42
|
+
}
|
|
43
|
+
return { ok: false, reason: "unsupported" };
|
|
44
|
+
},
|
|
45
|
+
async sendLog(message) {
|
|
46
|
+
const app = await readyMcpApp(state);
|
|
47
|
+
if (app?.getHostCapabilities()?.logging) {
|
|
48
|
+
await app.sendLog(message);
|
|
49
|
+
return { ok: true, value: void 0 };
|
|
50
|
+
}
|
|
51
|
+
return { ok: false, reason: "unsupported" };
|
|
52
|
+
},
|
|
53
|
+
async updateModelContext(context) {
|
|
54
|
+
const app = await readyMcpApp(state);
|
|
55
|
+
if (app?.getHostCapabilities()?.updateModelContext) {
|
|
56
|
+
await app.updateModelContext({ structuredContent: context });
|
|
57
|
+
return { ok: true, value: void 0 };
|
|
58
|
+
}
|
|
59
|
+
return { ok: false, reason: "unsupported" };
|
|
60
|
+
},
|
|
61
|
+
async openLink(url) {
|
|
62
|
+
if (!isAllowedExternalUrl(url)) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
reason: "denied",
|
|
66
|
+
message: "Only http, https, and mailto URLs can be opened externally."
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const app = await readyMcpApp(state);
|
|
70
|
+
if (app?.getHostCapabilities()?.openLinks) {
|
|
71
|
+
const result = await app.openLink({ url });
|
|
72
|
+
return result.isError ? { ok: false, reason: "denied" } : { ok: true, value: void 0 };
|
|
73
|
+
}
|
|
74
|
+
return { ok: false, reason: "unsupported" };
|
|
75
|
+
},
|
|
76
|
+
async downloadFile(contents) {
|
|
77
|
+
const app = await readyMcpApp(state);
|
|
78
|
+
if (app?.getHostCapabilities()?.downloadFile) {
|
|
79
|
+
const result = await app.downloadFile({ contents });
|
|
80
|
+
return result.isError ? { ok: false, reason: "denied" } : { ok: true, value: void 0 };
|
|
81
|
+
}
|
|
82
|
+
return { ok: false, reason: "unsupported" };
|
|
83
|
+
},
|
|
84
|
+
async requestTeardown(params) {
|
|
85
|
+
const app = await readyMcpApp(state);
|
|
86
|
+
if (app) {
|
|
87
|
+
await app.requestTeardown(params ?? {});
|
|
88
|
+
return { ok: true, value: void 0 };
|
|
89
|
+
}
|
|
90
|
+
return { ok: false, reason: "unsupported" };
|
|
91
|
+
},
|
|
92
|
+
async requestDisplayMode(mode) {
|
|
93
|
+
const app = await readyMcpApp(state);
|
|
94
|
+
const available = app?.getHostContext()?.availableDisplayModes;
|
|
95
|
+
if (app && Array.isArray(available) && available.includes(mode)) {
|
|
96
|
+
const result = await app.requestDisplayMode({ mode });
|
|
97
|
+
updateMcpHostContext(state, { ...app.getHostContext(), displayMode: result.mode });
|
|
98
|
+
return { ok: true, value: result.mode };
|
|
99
|
+
}
|
|
100
|
+
return { ok: false, reason: "unsupported" };
|
|
101
|
+
},
|
|
102
|
+
async sendSizeChanged(size) {
|
|
103
|
+
const app = await readyMcpApp(state);
|
|
104
|
+
if (app) {
|
|
105
|
+
await app.sendSizeChanged(size);
|
|
106
|
+
return { ok: true, value: void 0 };
|
|
107
|
+
}
|
|
108
|
+
return { ok: false, reason: "unsupported" };
|
|
109
|
+
},
|
|
110
|
+
getToolResult() {
|
|
111
|
+
if (state.toolResult) {
|
|
112
|
+
return state.toolResult;
|
|
113
|
+
}
|
|
114
|
+
return normalizeToolResult({
|
|
115
|
+
structuredContent: void 0,
|
|
116
|
+
content: [],
|
|
117
|
+
_meta: {}
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
subscribeToolInput(listener) {
|
|
121
|
+
state.toolInputListeners.add(listener);
|
|
122
|
+
return () => state.toolInputListeners.delete(listener);
|
|
123
|
+
},
|
|
124
|
+
subscribeToolInputPartial(listener) {
|
|
125
|
+
state.toolInputPartialListeners.add(listener);
|
|
126
|
+
return () => state.toolInputPartialListeners.delete(listener);
|
|
127
|
+
},
|
|
128
|
+
subscribeToolResult(listener) {
|
|
129
|
+
state.toolResultListeners.add(listener);
|
|
130
|
+
if (state.toolResult) {
|
|
131
|
+
listener(state.toolResult);
|
|
132
|
+
}
|
|
133
|
+
return () => state.toolResultListeners.delete(listener);
|
|
134
|
+
},
|
|
135
|
+
subscribeToolCancelled(listener) {
|
|
136
|
+
state.toolCancelledListeners.add(listener);
|
|
137
|
+
return () => state.toolCancelledListeners.delete(listener);
|
|
138
|
+
},
|
|
139
|
+
getHostContext() {
|
|
140
|
+
return detectHostContext();
|
|
141
|
+
},
|
|
142
|
+
getHostCapabilities() {
|
|
143
|
+
return state.app?.getHostCapabilities();
|
|
144
|
+
},
|
|
145
|
+
subscribeHostContext(listener) {
|
|
146
|
+
return subscribeHostContext(listener, state);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
var defaultState;
|
|
151
|
+
var browserBridge = createBrowserBridge();
|
|
152
|
+
var model = {
|
|
153
|
+
message(message) {
|
|
154
|
+
return browserBridge.sendMessage(message);
|
|
155
|
+
},
|
|
156
|
+
context: {
|
|
157
|
+
update(context) {
|
|
158
|
+
return browserBridge.updateModelContext(context);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var server = {
|
|
163
|
+
tool(params) {
|
|
164
|
+
return browserBridge.callServerTool(params);
|
|
165
|
+
},
|
|
166
|
+
resource: {
|
|
167
|
+
read(params) {
|
|
168
|
+
return browserBridge.readServerResource(params);
|
|
169
|
+
},
|
|
170
|
+
list(params) {
|
|
171
|
+
return browserBridge.listServerResources(params);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var sampling = {
|
|
176
|
+
createMessage(params) {
|
|
177
|
+
return browserBridge.createSamplingMessage(params);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
var log = {
|
|
181
|
+
send(message) {
|
|
182
|
+
return browserBridge.sendLog(message);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var view = {
|
|
186
|
+
requestTeardown(params) {
|
|
187
|
+
return browserBridge.requestTeardown(params);
|
|
188
|
+
},
|
|
189
|
+
sizeChanged(size) {
|
|
190
|
+
return browserBridge.sendSizeChanged(size);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
function getToolResult() {
|
|
194
|
+
return browserBridge.getToolResult();
|
|
195
|
+
}
|
|
196
|
+
function createToolClient(names, bridge = browserBridge) {
|
|
197
|
+
return new Proxy(
|
|
198
|
+
{},
|
|
199
|
+
{
|
|
200
|
+
get(_target, property) {
|
|
201
|
+
if (typeof property !== "string" || property === "then" || property === "catch" || property === "finally") {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
if (!(property in names)) {
|
|
205
|
+
return void 0;
|
|
206
|
+
}
|
|
207
|
+
const method = property;
|
|
208
|
+
return (params) => bridge.callTool(String(names[method]), params);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
var MCP_APPS_READY_TIMEOUT_MS = 900;
|
|
214
|
+
var hostContextEventNames = ["hostcontextchanged"];
|
|
215
|
+
function createMcpAppsState() {
|
|
216
|
+
if (defaultState) {
|
|
217
|
+
return defaultState;
|
|
218
|
+
}
|
|
219
|
+
const state = {
|
|
220
|
+
connected: false,
|
|
221
|
+
failed: false,
|
|
222
|
+
hostContextListeners: /* @__PURE__ */ new Set(),
|
|
223
|
+
toolInputListeners: /* @__PURE__ */ new Set(),
|
|
224
|
+
toolInputPartialListeners: /* @__PURE__ */ new Set(),
|
|
225
|
+
toolResultListeners: /* @__PURE__ */ new Set(),
|
|
226
|
+
toolCancelledListeners: /* @__PURE__ */ new Set()
|
|
227
|
+
};
|
|
228
|
+
defaultState = state;
|
|
229
|
+
if (!canUseMcpAppsBridge()) {
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
const app = new App(
|
|
233
|
+
{ name: "Sidecar Widget", version: "0.0.0-dev" },
|
|
234
|
+
{},
|
|
235
|
+
{ autoResize: typeof ResizeObserver !== "undefined" }
|
|
236
|
+
);
|
|
237
|
+
state.app = app;
|
|
238
|
+
app.ontoolinput = (params) => {
|
|
239
|
+
notifySet(state.toolInputListeners, params);
|
|
240
|
+
};
|
|
241
|
+
app.ontoolinputpartial = (params) => {
|
|
242
|
+
notifySet(state.toolInputPartialListeners, params);
|
|
243
|
+
};
|
|
244
|
+
app.ontoolresult = (params) => {
|
|
245
|
+
state.toolResult = normalizeToolResult(params);
|
|
246
|
+
notifyToolResultListeners(state);
|
|
247
|
+
};
|
|
248
|
+
app.ontoolcancelled = (params) => {
|
|
249
|
+
state.toolResult = normalizeToolResult({
|
|
250
|
+
content: [{ type: "text", text: params.reason ?? "Tool execution was cancelled." }],
|
|
251
|
+
isError: true
|
|
252
|
+
});
|
|
253
|
+
notifySet(state.toolCancelledListeners, params);
|
|
254
|
+
notifyToolResultListeners(state);
|
|
255
|
+
};
|
|
256
|
+
app.onhostcontextchanged = (params) => updateMcpHostContext(state, params);
|
|
257
|
+
app.onteardown = async () => ({});
|
|
258
|
+
state.connectPromise = app.connect(new PostMessageTransport(window.parent, window.parent)).then(() => {
|
|
259
|
+
state.connected = true;
|
|
260
|
+
state.failed = false;
|
|
261
|
+
updateMcpHostContext(state, app.getHostContext() ?? {});
|
|
262
|
+
return app;
|
|
263
|
+
}).catch(() => {
|
|
264
|
+
state.failed = true;
|
|
265
|
+
return void 0;
|
|
266
|
+
});
|
|
267
|
+
void state.connectPromise;
|
|
268
|
+
return state;
|
|
269
|
+
}
|
|
270
|
+
async function callServerTool(state, params) {
|
|
271
|
+
const app = await readyMcpApp(state);
|
|
272
|
+
if (app?.getHostCapabilities()?.serverTools) {
|
|
273
|
+
const result = await app.callServerTool({
|
|
274
|
+
name: params.name,
|
|
275
|
+
arguments: params.arguments
|
|
276
|
+
});
|
|
277
|
+
state.toolResult = normalizeToolResult(result);
|
|
278
|
+
notifyToolResultListeners(state);
|
|
279
|
+
return state.toolResult;
|
|
280
|
+
}
|
|
281
|
+
throw new Error("This host does not expose widget tool calls.");
|
|
282
|
+
}
|
|
283
|
+
async function readyMcpApp(state) {
|
|
284
|
+
if (state.connected && state.app) {
|
|
285
|
+
return state.app;
|
|
286
|
+
}
|
|
287
|
+
if (state.failed || !state.connectPromise) {
|
|
288
|
+
return void 0;
|
|
289
|
+
}
|
|
290
|
+
return timeout(state.connectPromise, MCP_APPS_READY_TIMEOUT_MS, void 0);
|
|
291
|
+
}
|
|
292
|
+
function canUseMcpAppsBridge() {
|
|
293
|
+
return typeof window !== "undefined" && window.parent !== window;
|
|
294
|
+
}
|
|
295
|
+
function updateMcpHostContext(state, context) {
|
|
296
|
+
state.hostContext = {
|
|
297
|
+
...state.hostContext ?? {},
|
|
298
|
+
...context
|
|
299
|
+
};
|
|
300
|
+
notifyHostContextListeners(state);
|
|
301
|
+
}
|
|
302
|
+
function notifyHostContextListeners(state) {
|
|
303
|
+
const context = detectHostContext();
|
|
304
|
+
for (const listener of state.hostContextListeners) {
|
|
305
|
+
listener(context);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function notifyToolResultListeners(state) {
|
|
309
|
+
if (!state.toolResult) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
notifySet(state.toolResultListeners, state.toolResult);
|
|
313
|
+
}
|
|
314
|
+
function notifySet(listeners, value) {
|
|
315
|
+
for (const listener of [...listeners]) {
|
|
316
|
+
listener(value);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function detectHostContext() {
|
|
320
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
321
|
+
return { name: "generic", theme: "light", source: "fallback" };
|
|
322
|
+
}
|
|
323
|
+
const state = defaultState;
|
|
324
|
+
if (state?.hostContext) {
|
|
325
|
+
return normalizeHostContext(state.hostContext, "mcp-apps");
|
|
326
|
+
}
|
|
327
|
+
if (looksLikeClaudeTheme()) {
|
|
328
|
+
return {
|
|
329
|
+
name: "claude",
|
|
330
|
+
theme: inferTheme(),
|
|
331
|
+
source: "claude-css"
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
name: "generic",
|
|
336
|
+
theme: inferTheme(),
|
|
337
|
+
source: "media-query"
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function subscribeHostContext(listener, state = createMcpAppsState()) {
|
|
341
|
+
if (typeof window === "undefined") {
|
|
342
|
+
return () => {
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
state.hostContextListeners.add(listener);
|
|
346
|
+
const notify = () => listener(detectHostContext());
|
|
347
|
+
for (const eventName of hostContextEventNames) {
|
|
348
|
+
window.addEventListener(eventName, notify);
|
|
349
|
+
}
|
|
350
|
+
const media = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
351
|
+
media?.addEventListener?.("change", notify);
|
|
352
|
+
return () => {
|
|
353
|
+
state.hostContextListeners.delete(listener);
|
|
354
|
+
for (const eventName of hostContextEventNames) {
|
|
355
|
+
window.removeEventListener(eventName, notify);
|
|
356
|
+
}
|
|
357
|
+
media?.removeEventListener?.("change", notify);
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function normalizeHostContext(context, source) {
|
|
361
|
+
const name = inferHostName(context);
|
|
362
|
+
const theme = context.theme === "dark" || context.theme === "light" ? context.theme : inferTheme();
|
|
363
|
+
return {
|
|
364
|
+
name,
|
|
365
|
+
theme,
|
|
366
|
+
source,
|
|
367
|
+
raw: context
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function inferHostName(context) {
|
|
371
|
+
const userAgent = String(context.userAgent ?? "").toLowerCase();
|
|
372
|
+
if (userAgent.includes("claude") || looksLikeClaudeTheme()) {
|
|
373
|
+
return "claude";
|
|
374
|
+
}
|
|
375
|
+
if (userAgent.includes("chatgpt") || userAgent.includes("openai")) {
|
|
376
|
+
return "chatgpt";
|
|
377
|
+
}
|
|
378
|
+
return "generic";
|
|
379
|
+
}
|
|
380
|
+
function normalizeToolResult(result) {
|
|
381
|
+
const structuredContent = result.structuredContent;
|
|
382
|
+
const meta = result._meta ?? {};
|
|
383
|
+
return {
|
|
384
|
+
structuredContent,
|
|
385
|
+
structured: structuredContent,
|
|
386
|
+
content: result.content ?? [],
|
|
387
|
+
meta,
|
|
388
|
+
_meta: meta,
|
|
389
|
+
isError: result.isError
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function normalizeMessageContent(message) {
|
|
393
|
+
if (message.content?.length) {
|
|
394
|
+
return message.content;
|
|
395
|
+
}
|
|
396
|
+
return [{ type: "text", text: message.text ?? "" }];
|
|
397
|
+
}
|
|
398
|
+
function inferTheme() {
|
|
399
|
+
if (typeof window === "undefined" || !window.matchMedia) {
|
|
400
|
+
return "light";
|
|
401
|
+
}
|
|
402
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
403
|
+
}
|
|
404
|
+
function looksLikeClaudeTheme() {
|
|
405
|
+
if (typeof document === "undefined") {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
const style = getComputedStyle(document.documentElement);
|
|
409
|
+
return Boolean(
|
|
410
|
+
style.getPropertyValue("--claude-text-color").trim() || style.getPropertyValue("--claude-background-color").trim() || style.getPropertyValue("--claude-border-color").trim()
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
function isAllowedExternalUrl(value) {
|
|
414
|
+
try {
|
|
415
|
+
const url = new URL(value);
|
|
416
|
+
return url.protocol === "https:" || url.protocol === "http:" || url.protocol === "mailto:";
|
|
417
|
+
} catch {
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function timeout(promise, ms, fallback) {
|
|
422
|
+
return new Promise((resolve) => {
|
|
423
|
+
const timer = setTimeout(() => resolve(fallback), ms);
|
|
424
|
+
promise.then(
|
|
425
|
+
(value) => {
|
|
426
|
+
clearTimeout(timer);
|
|
427
|
+
resolve(value);
|
|
428
|
+
},
|
|
429
|
+
() => {
|
|
430
|
+
clearTimeout(timer);
|
|
431
|
+
resolve(fallback);
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
export {
|
|
437
|
+
browserBridge,
|
|
438
|
+
createBrowserBridge,
|
|
439
|
+
createToolClient,
|
|
440
|
+
detectHostContext,
|
|
441
|
+
getToolResult,
|
|
442
|
+
log,
|
|
443
|
+
model,
|
|
444
|
+
sampling,
|
|
445
|
+
server,
|
|
446
|
+
subscribeHostContext,
|
|
447
|
+
view
|
|
448
|
+
};
|
|
449
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../packages/client/src/index.ts"],"sourcesContent":["/**\n * Framework-agnostic widget bridge.\n *\n * Sidecar's public API stays small and typed, and the browser transport is the\n * official MCP Apps iframe bridge. Platform-specific globals live in their\n * platform packages, not in this generic client.\n */\nimport { App, PostMessageTransport } from \"@modelcontextprotocol/ext-apps/app-with-deps\";\n\n/** Standard result shape for host-only capabilities that may not exist everywhere. */\nexport type HostFeatureResult<T = void> =\n | { ok: true; value: T }\n | {\n ok: false;\n reason: \"unsupported\" | \"denied\" | \"cancelled\" | \"failed\";\n message?: string;\n };\n\n/** Host families Sidecar can theme and feature-detect at runtime. */\nexport type SidecarHostName = \"chatgpt\" | \"claude\" | \"generic\";\n\n/** Display theme reported by the host or inferred from browser settings. */\nexport type SidecarTheme = \"light\" | \"dark\";\n\n/** Display modes defined by the MCP Apps extension. */\nexport type SidecarDisplayMode = \"inline\" | \"fullscreen\" | \"pip\";\n\n/** Runtime host information used by React/native packages. */\nexport type SidecarHostContext = {\n /** Host family currently embedding the widget. */\n name: SidecarHostName;\n /** Light/dark theme for host-aligned native components. */\n theme: SidecarTheme;\n /** Whether the context came from the MCP Apps bridge, a host fallback, or browser inference. */\n source: \"mcp-apps\" | \"claude-css\" | \"media-query\" | \"fallback\";\n /** Raw MCP Apps host context when supplied by the host. */\n raw?: unknown;\n};\n\n/** Listener called when the embedding host changes theme or capability context. */\nexport type HostContextListener = (context: SidecarHostContext) => void;\n\n/** Minimal MCP content block shape used by client-side bridge calls. */\nexport type ClientContentBlock = {\n type: string;\n [key: string]: unknown;\n};\n\n/** Tool result data made available to a rendered widget. */\nexport type WidgetToolResult<\n Structured = unknown,\n Meta = Record<string, unknown>,\n> = {\n /** Structured data sent through the standard MCP `structuredContent` field. */\n structuredContent: Structured | undefined;\n /** Backward-compatible alias for early Sidecar examples. Prefer `structuredContent`. */\n structured: Structured | undefined;\n /** Model-visible MCP content blocks. */\n content: unknown[];\n /** Host/widget-only metadata from MCP `_meta`. */\n meta: Meta;\n /** Standard MCP metadata field. */\n _meta?: Meta;\n /** Whether the tool result represents a tool execution error. */\n isError?: boolean;\n};\n\n/** Message a widget wants to send back into the model conversation. */\nexport type ModelMessage = {\n /** Convenience text. Sidecar normalizes this to one MCP text content block. */\n text?: string;\n /** Exact MCP content blocks for richer messages. Takes precedence over `text`. */\n content?: ClientContentBlock[];\n};\n\n/** Resource descriptor returned by standard MCP `resources/list`. */\nexport type ServerResource = {\n uri: string;\n name?: string;\n description?: string;\n mimeType?: string;\n _meta?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n/** Resource content returned by standard MCP `resources/read`. */\nexport type ServerResourceContent = {\n uri: string;\n mimeType?: string;\n text?: string;\n blob?: string;\n _meta?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n/** Result of standard MCP `resources/list` proxied through the Apps host. */\nexport type ServerResourceListResult = {\n resources: ServerResource[];\n nextCursor?: string;\n _meta?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n/** Result of standard MCP `resources/read` proxied through the Apps host. */\nexport type ServerResourceReadResult = {\n contents: ServerResourceContent[];\n _meta?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n/** Standard MCP sampling request params passed through the Apps host. */\nexport type SamplingMessageRequest = Record<string, unknown>;\n\n/** Standard MCP sampling result returned by the Apps host. */\nexport type SamplingMessageResult = Record<string, unknown>;\n\n/** Standard MCP log message levels. */\nexport type HostLogLevel =\n | \"debug\"\n | \"info\"\n | \"notice\"\n | \"warning\"\n | \"error\"\n | \"critical\"\n | \"alert\"\n | \"emergency\";\n\n/** Standard MCP log notification payload sent through the Apps host. */\nexport type HostLogMessage = {\n level: HostLogLevel;\n data: unknown;\n logger?: string;\n};\n\n/** Standard MCP Apps size-change notification payload. */\nexport type SizeChangedMessage = {\n width: number;\n height: number;\n};\n\n/** Complete or partial tool input sent by the host before a tool result arrives. */\nexport type ToolInput = {\n arguments?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n/** Host bridge capabilities available to widget code. */\nexport type WidgetBridge = {\n callServerTool<\n TParams extends Record<string, unknown> = Record<string, unknown>,\n Structured = unknown,\n Meta = Record<string, unknown>,\n >(params: {\n name: string;\n arguments?: TParams;\n }): Promise<WidgetToolResult<Structured, Meta>>;\n callTool<TParams extends Record<string, unknown>, TResult>(\n name: string,\n params: TParams,\n ): Promise<TResult>;\n readServerResource(params: { uri: string }): Promise<HostFeatureResult<ServerResourceReadResult>>;\n listServerResources(params?: { cursor?: string }): Promise<HostFeatureResult<ServerResourceListResult>>;\n createSamplingMessage(params: SamplingMessageRequest): Promise<HostFeatureResult<SamplingMessageResult>>;\n sendMessage(message: ModelMessage): Promise<HostFeatureResult>;\n updateModelContext(\n context: Record<string, unknown>,\n ): Promise<HostFeatureResult>;\n sendLog(message: HostLogMessage): Promise<HostFeatureResult>;\n openLink(url: string): Promise<HostFeatureResult>;\n downloadFile(contents: ClientContentBlock[]): Promise<HostFeatureResult>;\n requestTeardown(params?: Record<string, never>): Promise<HostFeatureResult>;\n requestDisplayMode(mode: SidecarDisplayMode): Promise<HostFeatureResult<SidecarDisplayMode>>;\n sendSizeChanged(size: SizeChangedMessage): Promise<HostFeatureResult>;\n getToolResult<Structured, Meta = Record<string, unknown>>(): WidgetToolResult<\n Structured,\n Meta\n >;\n subscribeToolInput(listener: ToolInputListener): () => void;\n subscribeToolInputPartial(listener: ToolInputListener): () => void;\n subscribeToolResult(listener: ToolResultListener): () => void;\n subscribeToolCancelled(listener: ToolCancelledListener): () => void;\n getHostContext(): SidecarHostContext;\n getHostCapabilities(): Record<string, unknown> | undefined;\n subscribeHostContext(listener: HostContextListener): () => void;\n};\n\n/** Listener called when the host sends standard MCP Apps tool input. */\nexport type ToolInputListener = (input: ToolInput) => void;\n\n/** Listener called when the host sends a standard MCP Apps tool-result notification. */\nexport type ToolResultListener = (result: WidgetToolResult) => void;\n\n/** Listener called when the host cancels the active tool execution. */\nexport type ToolCancelledListener = (params: { reason?: string }) => void;\n\n/** Structural constraint for generated typed tool clients. */\nexport type ToolClientShape = object;\n\n/** Creates a browser bridge that speaks MCP Apps first and ChatGPT globals second. */\nexport function createBrowserBridge(): WidgetBridge {\n const state = createMcpAppsState();\n\n return {\n async callServerTool(params) {\n return callServerTool(state, params) as never;\n },\n\n async callTool(name, params) {\n const result = await callServerTool(state, { name, arguments: params });\n return result.structuredContent as never;\n },\n\n async readServerResource(params) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.serverResources) {\n return { ok: true, value: await app.readServerResource(params) };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async listServerResources(params) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.serverResources) {\n return { ok: true, value: await app.listServerResources(params) };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async createSamplingMessage(params) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.sampling) {\n return { ok: true, value: await app.createSamplingMessage(params) };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async sendMessage(message) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.message) {\n const result = await app.sendMessage({\n role: \"user\",\n content: normalizeMessageContent(message),\n });\n return result.isError ? { ok: false, reason: \"denied\" } : { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async sendLog(message) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.logging) {\n await app.sendLog(message);\n return { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async updateModelContext(context) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.updateModelContext) {\n await app.updateModelContext({ structuredContent: context });\n return { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async openLink(url) {\n if (!isAllowedExternalUrl(url)) {\n return {\n ok: false,\n reason: \"denied\",\n message: \"Only http, https, and mailto URLs can be opened externally.\",\n };\n }\n\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.openLinks) {\n const result = await app.openLink({ url });\n return result.isError ? { ok: false, reason: \"denied\" } : { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async downloadFile(contents) {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.downloadFile) {\n const result = await app.downloadFile({ contents });\n return result.isError ? { ok: false, reason: \"denied\" } : { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async requestTeardown(params) {\n const app = await readyMcpApp(state);\n if (app) {\n await app.requestTeardown(params ?? {});\n return { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async requestDisplayMode(mode) {\n const app = await readyMcpApp(state);\n const available = app?.getHostContext()?.availableDisplayModes;\n if (app && Array.isArray(available) && available.includes(mode)) {\n const result = await app.requestDisplayMode({ mode });\n updateMcpHostContext(state, { ...app.getHostContext(), displayMode: result.mode });\n return { ok: true, value: result.mode };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n async sendSizeChanged(size) {\n const app = await readyMcpApp(state);\n if (app) {\n await app.sendSizeChanged(size);\n return { ok: true, value: undefined };\n }\n\n return { ok: false, reason: \"unsupported\" };\n },\n\n getToolResult() {\n if (state.toolResult) {\n return state.toolResult as never;\n }\n\n return normalizeToolResult({\n structuredContent: undefined,\n content: [],\n _meta: {},\n }) as never;\n },\n\n subscribeToolInput(listener) {\n state.toolInputListeners.add(listener);\n return () => state.toolInputListeners.delete(listener);\n },\n\n subscribeToolInputPartial(listener) {\n state.toolInputPartialListeners.add(listener);\n return () => state.toolInputPartialListeners.delete(listener);\n },\n\n subscribeToolResult(listener) {\n state.toolResultListeners.add(listener);\n if (state.toolResult) {\n listener(state.toolResult);\n }\n return () => state.toolResultListeners.delete(listener);\n },\n\n subscribeToolCancelled(listener) {\n state.toolCancelledListeners.add(listener);\n return () => state.toolCancelledListeners.delete(listener);\n },\n\n getHostContext() {\n return detectHostContext();\n },\n\n getHostCapabilities() {\n return state.app?.getHostCapabilities();\n },\n\n subscribeHostContext(listener) {\n return subscribeHostContext(listener, state);\n },\n };\n}\n\nlet defaultState: McpAppsState | undefined;\n\n/** Default browser bridge used by generated widget clients. */\nexport const browserBridge = createBrowserBridge();\n\n/** Convenience object for sending model messages and context updates. */\nexport const model = {\n message(message: ModelMessage): Promise<HostFeatureResult> {\n return browserBridge.sendMessage(message);\n },\n context: {\n update(context: Record<string, unknown>): Promise<HostFeatureResult> {\n return browserBridge.updateModelContext(context);\n },\n },\n};\n\n/** Convenience object for server-bound MCP requests proxied by the Apps host. */\nexport const server = {\n tool<\n TParams extends Record<string, unknown> = Record<string, unknown>,\n Structured = unknown,\n Meta = Record<string, unknown>,\n >(params: {\n name: string;\n arguments?: TParams;\n }): Promise<WidgetToolResult<Structured, Meta>> {\n return browserBridge.callServerTool<TParams, Structured, Meta>(params);\n },\n resource: {\n read(params: { uri: string }): Promise<HostFeatureResult<ServerResourceReadResult>> {\n return browserBridge.readServerResource(params);\n },\n list(params?: { cursor?: string }): Promise<HostFeatureResult<ServerResourceListResult>> {\n return browserBridge.listServerResources(params);\n },\n },\n};\n\n/** Convenience object for standard host sampling requests. */\nexport const sampling = {\n createMessage(params: SamplingMessageRequest): Promise<HostFeatureResult<SamplingMessageResult>> {\n return browserBridge.createSamplingMessage(params);\n },\n};\n\n/** Convenience object for standard host logging notifications. */\nexport const log = {\n send(message: HostLogMessage): Promise<HostFeatureResult> {\n return browserBridge.sendLog(message);\n },\n};\n\n/** Convenience object for view lifecycle and layout notifications. */\nexport const view = {\n requestTeardown(params?: Record<string, never>): Promise<HostFeatureResult> {\n return browserBridge.requestTeardown(params);\n },\n sizeChanged(size: SizeChangedMessage): Promise<HostFeatureResult> {\n return browserBridge.sendSizeChanged(size);\n },\n};\n\n/** Reads the current tool result from the default browser bridge. */\nexport function getToolResult<\n Structured,\n Meta = Record<string, unknown>,\n>(): WidgetToolResult<Structured, Meta> {\n return browserBridge.getToolResult<Structured, Meta>();\n}\n\n/**\n * Creates a typed proxy where method calls become host tool calls.\n *\n * Generated clients pass the machine-name map while user code calls readable\n * camelCase methods.\n */\nexport function createToolClient<TTools extends ToolClientShape>(\n names: Record<Extract<keyof TTools, string>, string>,\n bridge: Pick<WidgetBridge, \"callTool\"> = browserBridge,\n): TTools {\n return new Proxy(\n {},\n {\n get(_target, property) {\n if (typeof property !== \"string\" || property === \"then\" || property === \"catch\" || property === \"finally\") {\n return undefined;\n }\n if (!(property in names)) {\n return undefined;\n }\n const method = property as Extract<keyof TTools, string>;\n return (params: Record<string, unknown>) =>\n bridge.callTool(String(names[method]), params);\n },\n },\n ) as TTools;\n}\n\ntype McpAppsToolResult = {\n structuredContent?: unknown;\n content?: unknown[];\n _meta?: Record<string, unknown>;\n isError?: boolean;\n [key: string]: unknown;\n};\n\ntype McpAppsHostCapabilities = {\n serverTools?: unknown;\n openLinks?: unknown;\n downloadFile?: unknown;\n updateModelContext?: unknown;\n message?: unknown;\n [key: string]: unknown;\n};\n\ntype McpAppsHostContext = {\n theme?: \"light\" | \"dark\";\n userAgent?: string;\n displayMode?: SidecarDisplayMode;\n availableDisplayModes?: SidecarDisplayMode[];\n [key: string]: unknown;\n};\n\ntype McpAppsRuntime = {\n connect(transport: unknown, options?: Record<string, unknown>): Promise<void>;\n callServerTool(params: { name: string; arguments?: Record<string, unknown> }): Promise<McpAppsToolResult>;\n readServerResource(params: { uri: string }): Promise<ServerResourceReadResult>;\n listServerResources(params?: { cursor?: string }): Promise<ServerResourceListResult>;\n createSamplingMessage(params: SamplingMessageRequest): Promise<SamplingMessageResult>;\n sendMessage(params: { role: \"user\"; content: ClientContentBlock[] }): Promise<{ isError?: boolean }>;\n sendLog(params: HostLogMessage): Promise<void>;\n updateModelContext(params: { content?: ClientContentBlock[]; structuredContent?: Record<string, unknown> }): Promise<unknown>;\n openLink(params: { url: string }): Promise<{ isError?: boolean }>;\n downloadFile(params: { contents: ClientContentBlock[] }): Promise<{ isError?: boolean }>;\n requestTeardown(params?: Record<string, never>): Promise<void>;\n requestDisplayMode(params: { mode: SidecarDisplayMode }): Promise<{ mode: SidecarDisplayMode }>;\n sendSizeChanged(params: SizeChangedMessage): Promise<void>;\n getHostCapabilities(): McpAppsHostCapabilities | undefined;\n getHostContext(): McpAppsHostContext | undefined;\n ontoolinput?: (params: ToolInput) => void;\n ontoolinputpartial?: (params: ToolInput) => void;\n ontoolresult?: (params: McpAppsToolResult) => void;\n onhostcontextchanged?: (params: McpAppsHostContext) => void;\n ontoolcancelled?: (params: { reason?: string }) => void;\n onteardown?: () => Record<string, never> | Promise<Record<string, never>>;\n};\n\ntype McpAppsState = {\n app?: McpAppsRuntime;\n connectPromise?: Promise<McpAppsRuntime | undefined>;\n connected: boolean;\n failed: boolean;\n hostContext?: McpAppsHostContext;\n toolResult?: WidgetToolResult;\n hostContextListeners: Set<HostContextListener>;\n toolInputListeners: Set<ToolInputListener>;\n toolInputPartialListeners: Set<ToolInputListener>;\n toolResultListeners: Set<ToolResultListener>;\n toolCancelledListeners: Set<ToolCancelledListener>;\n};\n\nconst MCP_APPS_READY_TIMEOUT_MS = 900;\nconst hostContextEventNames = [\"hostcontextchanged\"] as const;\n\n/** Creates and starts the standard MCP Apps runtime when running in an iframe. */\nfunction createMcpAppsState(): McpAppsState {\n if (defaultState) {\n return defaultState;\n }\n\n const state: McpAppsState = {\n connected: false,\n failed: false,\n hostContextListeners: new Set(),\n toolInputListeners: new Set(),\n toolInputPartialListeners: new Set(),\n toolResultListeners: new Set(),\n toolCancelledListeners: new Set(),\n };\n defaultState = state;\n\n if (!canUseMcpAppsBridge()) {\n return state;\n }\n\n const app = new App(\n { name: \"Sidecar Widget\", version: \"0.0.0-dev\" },\n {},\n { autoResize: typeof ResizeObserver !== \"undefined\" },\n ) as unknown as McpAppsRuntime;\n state.app = app;\n\n app.ontoolinput = (params) => {\n notifySet(state.toolInputListeners, params);\n };\n app.ontoolinputpartial = (params) => {\n notifySet(state.toolInputPartialListeners, params);\n };\n app.ontoolresult = (params) => {\n state.toolResult = normalizeToolResult(params);\n notifyToolResultListeners(state);\n };\n app.ontoolcancelled = (params) => {\n state.toolResult = normalizeToolResult({\n content: [{ type: \"text\", text: params.reason ?? \"Tool execution was cancelled.\" }],\n isError: true,\n });\n notifySet(state.toolCancelledListeners, params);\n notifyToolResultListeners(state);\n };\n app.onhostcontextchanged = (params) => updateMcpHostContext(state, params);\n app.onteardown = async () => ({});\n\n state.connectPromise = app\n .connect(new PostMessageTransport(window.parent, window.parent))\n .then(() => {\n state.connected = true;\n state.failed = false;\n updateMcpHostContext(state, app.getHostContext() ?? {});\n return app;\n })\n .catch(() => {\n state.failed = true;\n return undefined;\n });\n void state.connectPromise;\n\n return state;\n}\n\n/** Calls the originating MCP server through the standard Apps host bridge. */\nasync function callServerTool<\n TParams extends Record<string, unknown>,\n Structured,\n Meta = Record<string, unknown>,\n>(\n state: McpAppsState,\n params: { name: string; arguments?: TParams },\n): Promise<WidgetToolResult<Structured, Meta>> {\n const app = await readyMcpApp(state);\n if (app?.getHostCapabilities()?.serverTools) {\n const result = await app.callServerTool({\n name: params.name,\n arguments: params.arguments,\n });\n state.toolResult = normalizeToolResult(result);\n notifyToolResultListeners(state);\n return state.toolResult as WidgetToolResult<Structured, Meta>;\n }\n\n throw new Error(\"This host does not expose widget tool calls.\");\n}\n\n/** Resolves the standard MCP Apps app if its initialization has completed. */\nasync function readyMcpApp(state: McpAppsState): Promise<McpAppsRuntime | undefined> {\n if (state.connected && state.app) {\n return state.app;\n }\n if (state.failed || !state.connectPromise) {\n return undefined;\n }\n\n return timeout(state.connectPromise, MCP_APPS_READY_TIMEOUT_MS, undefined);\n}\n\n/** Returns true when a browser iframe can attempt MCP Apps postMessage transport. */\nfunction canUseMcpAppsBridge(): boolean {\n return typeof window !== \"undefined\" && window.parent !== window;\n}\n\n/** Updates raw host context and notifies React/native subscribers. */\nfunction updateMcpHostContext(state: McpAppsState, context: McpAppsHostContext): void {\n state.hostContext = {\n ...(state.hostContext ?? {}),\n ...context,\n };\n notifyHostContextListeners(state);\n}\n\n/** Notifies subscribers of the normalized Sidecar host context. */\nfunction notifyHostContextListeners(state: McpAppsState): void {\n const context = detectHostContext();\n for (const listener of state.hostContextListeners) {\n listener(context);\n }\n}\n\n/** Notifies subscribers of the latest normalized MCP tool result. */\nfunction notifyToolResultListeners(state: McpAppsState): void {\n if (!state.toolResult) {\n return;\n }\n notifySet(state.toolResultListeners, state.toolResult);\n}\n\n/** Notifies all listeners in one set without exposing mutation during dispatch. */\nfunction notifySet<T>(listeners: Set<(value: T) => void>, value: T): void {\n for (const listener of [...listeners]) {\n listener(value);\n }\n}\n\n/** Detects the active widget host without relying on build-time target flags. */\nexport function detectHostContext(): SidecarHostContext {\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return { name: \"generic\", theme: \"light\", source: \"fallback\" };\n }\n\n const state = defaultState;\n if (state?.hostContext) {\n return normalizeHostContext(state.hostContext, \"mcp-apps\");\n }\n\n if (looksLikeClaudeTheme()) {\n return {\n name: \"claude\",\n theme: inferTheme(),\n source: \"claude-css\",\n };\n }\n\n return {\n name: \"generic\",\n theme: inferTheme(),\n source: \"media-query\",\n };\n}\n\n/** Subscribes to host context/theme changes from the MCP Apps bridge and media queries. */\nexport function subscribeHostContext(\n listener: HostContextListener,\n state = createMcpAppsState(),\n): () => void {\n if (typeof window === \"undefined\") {\n return () => {};\n }\n\n state.hostContextListeners.add(listener);\n const notify = () => listener(detectHostContext());\n for (const eventName of hostContextEventNames) {\n window.addEventListener(eventName, notify);\n }\n\n const media = window.matchMedia?.(\"(prefers-color-scheme: dark)\");\n media?.addEventListener?.(\"change\", notify);\n\n return () => {\n state.hostContextListeners.delete(listener);\n for (const eventName of hostContextEventNames) {\n window.removeEventListener(eventName, notify);\n }\n media?.removeEventListener?.(\"change\", notify);\n };\n}\n\n/** Converts unknown host context shapes into Sidecar's stable context contract. */\nfunction normalizeHostContext(\n context: McpAppsHostContext,\n source: SidecarHostContext[\"source\"],\n): SidecarHostContext {\n const name = inferHostName(context);\n const theme = context.theme === \"dark\" || context.theme === \"light\"\n ? context.theme\n : inferTheme();\n\n return {\n name,\n theme,\n source,\n raw: context,\n };\n}\n\n/** Infers ChatGPT/Claude from standard host context and runtime hints. */\nfunction inferHostName(context: McpAppsHostContext): SidecarHostName {\n const userAgent = String(context.userAgent ?? \"\").toLowerCase();\n if (userAgent.includes(\"claude\") || looksLikeClaudeTheme()) {\n return \"claude\";\n }\n if (userAgent.includes(\"chatgpt\") || userAgent.includes(\"openai\")) {\n return \"chatgpt\";\n }\n return \"generic\";\n}\n\n/** Converts a standard MCP tool result into Sidecar's hook-friendly result. */\nfunction normalizeToolResult<\n Structured = unknown,\n Meta = Record<string, unknown>,\n>(result: McpAppsToolResult): WidgetToolResult<Structured, Meta> {\n const structuredContent = result.structuredContent as Structured | undefined;\n const meta = (result._meta ?? {}) as Meta;\n return {\n structuredContent,\n structured: structuredContent,\n content: result.content ?? [],\n meta,\n _meta: meta,\n isError: result.isError,\n };\n}\n\n/** Normalizes Sidecar's convenient message object to the standard MCP Apps shape. */\nfunction normalizeMessageContent(message: ModelMessage): ClientContentBlock[] {\n if (message.content?.length) {\n return message.content;\n }\n return [{ type: \"text\", text: message.text ?? \"\" }];\n}\n\n/** Infers light/dark when the host did not provide an explicit theme. */\nfunction inferTheme(): SidecarTheme {\n if (typeof window === \"undefined\" || !window.matchMedia) {\n return \"light\";\n }\n\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches ? \"dark\" : \"light\";\n}\n\n/** Detects Claude-like host theming through documented CSS custom properties. */\nfunction looksLikeClaudeTheme(): boolean {\n if (typeof document === \"undefined\") {\n return false;\n }\n\n const style = getComputedStyle(document.documentElement);\n return Boolean(\n style.getPropertyValue(\"--claude-text-color\").trim() ||\n style.getPropertyValue(\"--claude-background-color\").trim() ||\n style.getPropertyValue(\"--claude-border-color\").trim(),\n );\n}\n\n/** Allows only URL schemes that are safe for external navigation helpers. */\nfunction isAllowedExternalUrl(value: string): boolean {\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\" || url.protocol === \"mailto:\";\n } catch {\n return false;\n }\n}\n\n/** Resolves a promise with a fallback if it does not settle within the timeout. */\nfunction timeout<T>(promise: Promise<T>, ms: number, fallback: T): Promise<T> {\n return new Promise((resolve) => {\n const timer = setTimeout(() => resolve(fallback), ms);\n promise.then(\n (value) => {\n clearTimeout(timer);\n resolve(value);\n },\n () => {\n clearTimeout(timer);\n resolve(fallback);\n },\n );\n });\n}\n"],"mappings":";AAOA,SAAS,KAAK,4BAA4B;AAgMnC,SAAS,sBAAoC;AAClD,QAAM,QAAQ,mBAAmB;AAEjC,SAAO;AAAA,IACL,MAAM,eAAe,QAAQ;AAC3B,aAAO,eAAe,OAAO,MAAM;AAAA,IACrC;AAAA,IAEA,MAAM,SAAS,MAAM,QAAQ;AAC3B,YAAM,SAAS,MAAM,eAAe,OAAO,EAAE,MAAM,WAAW,OAAO,CAAC;AACtE,aAAO,OAAO;AAAA,IAChB;AAAA,IAEA,MAAM,mBAAmB,QAAQ;AAC/B,YAAM,MAAM,MAAM,YAAY,KAAK;AACnC,UAAI,KAAK,oBAAoB,GAAG,iBAAiB;AAC/C,eAAO,EAAE,IAAI,MAAM,OAAO,MAAM,IAAI,mBAAmB,MAAM,EAAE;AAAA,MACjE;AAEA,aAAO,EAAE,IAAI,OAAO,QAAQ,cAAc;AAAA,IAC5C;AAAA,IAEA,MAAM,oBAAoB,QAAQ;AAChC,YAAM,MAAM,MAAM,YAAY,KAAK;AACnC,UAAI,KAAK,oBAAoB,GAAG,iBAAiB;AAC/C,eAAO,EAAE,IAAI,MAAM,OAAO,MAAM,IAAI,oBAAoB,MAAM,EAAE;AAAA,MAClE;AAEA,aAAO,EAAE,IAAI,OAAO,QAAQ,cAAc;AAAA,IAC5C;AAAA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ACF,UAAM,MAAM,IAAI,IAAI,KAAK;AACzB,WAAO,IAAI,aAAa,YAAY,IAAI,aAAa,WAAW,IAAI,aAAa;AAAA,EACnF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,SAAS,QAAW,SAAqB,IAAY,UAAyB;AAC5E,SAAO,IAAI,QAAQ,CAAC,YAAY;AAC9B,UAAM,QAAQ,WAAW,MAAM,QAAQ,QAAQ,GAAG,EAAE;AACpD,YAAQ;AAAA,MACN,CAAC,UAAU;AACT,qBAAa,KAAK;AAClB,gBAAQ,KAAK;AAAA,MACf;AAAA,MACA,MAAM;AACJ,qBAAa,KAAK;AAClB,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sidecar-ai/client",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@modelcontextprotocol/ext-apps": "^1.7.2"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
}
|
|
21
|
+
}
|