@miragon/mcp-toolkit-ui 0.10.1 → 1.1.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/README.md +7 -7
- package/dist/app/adapt-data-widget.d.ts +26 -5
- package/dist/app/adapt-data-widget.d.ts.map +1 -1
- package/dist/app/adapt-data-widget.js +39 -5
- package/dist/app/adapt-data-widget.js.map +1 -1
- package/dist/app/host-bridge.d.ts +52 -46
- package/dist/app/host-bridge.d.ts.map +1 -1
- package/dist/app/host-bridge.js +30 -52
- package/dist/app/host-bridge.js.map +1 -1
- package/dist/app/index.d.ts +5 -4
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +9 -8
- package/dist/app/index.js.map +1 -1
- package/dist/app/mcp-app-view.d.ts.map +1 -1
- package/dist/app/mcp-app-view.js +37 -24
- package/dist/app/mcp-app-view.js.map +1 -1
- package/dist/app/mcp-toolkit-app.d.ts +21 -10
- package/dist/app/mcp-toolkit-app.d.ts.map +1 -1
- package/dist/app/mcp-toolkit-app.js +26 -12
- package/dist/app/mcp-toolkit-app.js.map +1 -1
- package/dist/app/mcp-use-host-bridge.d.ts +29 -0
- package/dist/app/mcp-use-host-bridge.d.ts.map +1 -0
- package/dist/app/mcp-use-host-bridge.js +120 -0
- package/dist/app/mcp-use-host-bridge.js.map +1 -0
- package/dist/app/use-host-actions.d.ts +6 -6
- package/dist/app/use-host-actions.js +6 -6
- package/dist/app/widget-fixture.d.ts +24 -21
- package/dist/app/widget-fixture.d.ts.map +1 -1
- package/dist/app/widget-fixture.js +27 -123
- package/dist/app/widget-fixture.js.map +1 -1
- package/dist/hooks/use-tool-result-recovery.d.ts +40 -15
- package/dist/hooks/use-tool-result-recovery.d.ts.map +1 -1
- package/dist/hooks/use-tool-result-recovery.js +57 -4
- package/dist/hooks/use-tool-result-recovery.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +16 -8
- package/src/app/adapt-data-widget.tsx +50 -6
- package/src/app/host-bridge.test.ts +107 -0
- package/src/app/host-bridge.tsx +85 -82
- package/src/app/index.ts +15 -10
- package/src/app/mcp-app-view.tsx +41 -32
- package/src/app/mcp-toolkit-app.tsx +33 -16
- package/src/app/mcp-use-host-bridge.tsx +164 -0
- package/src/app/use-host-actions.tsx +6 -6
- package/src/app/widget-fixture.tsx +35 -156
- package/src/hooks/use-tool-result-recovery.ts +75 -19
- package/src/index.ts +1 -1
- package/ui-catalog.json +81 -27
package/dist/app/mcp-app-view.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useCallback } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { useDisplayMode, useHostContext, useToolContext } from "mcp-use/react";
|
|
4
4
|
import { Maximize2, Minimize2, Pencil, RefreshCw } from "lucide-react";
|
|
5
5
|
import { Skeleton } from "../primitives/skeleton.js";
|
|
6
6
|
import { AppQueryProvider, queryClient } from "../providers/query-provider.js";
|
|
7
7
|
import { useToolResultRecovery } from "../hooks/use-tool-result-recovery.js";
|
|
8
8
|
import { parseToolResult } from "../lib/parse-tool-result.js";
|
|
9
|
+
import { useHostBridge } from "./host-bridge.js";
|
|
9
10
|
import { LayoutBuilder } from "./layout-builder.js";
|
|
10
11
|
import { WidgetRenderer } from "./widget-renderer.js";
|
|
11
12
|
const DEFAULT_LABELS = {
|
|
@@ -27,15 +28,19 @@ function isCompleteViewData(value) {
|
|
|
27
28
|
}
|
|
28
29
|
export function McpAppView({ widgets, refreshToolName = "refresh-view", builderEnabled, labels, }) {
|
|
29
30
|
const effectiveLabels = { ...DEFAULT_LABELS, ...labels };
|
|
30
|
-
|
|
31
|
+
// Since mcp-use 2.x the shell reads the view channels through the dedicated
|
|
32
|
+
// hooks (all require the surrounding `bootstrapView` mount that
|
|
33
|
+
// `mountMcpToolkitApp` provides) and calls tools through the HostBridge that
|
|
34
|
+
// `McpUseHostBridgeProvider` installs.
|
|
35
|
+
const tool = useToolContext();
|
|
36
|
+
const { displayMode, requestDisplayMode } = useDisplayMode();
|
|
37
|
+
const { safeArea, hostContext } = useHostContext();
|
|
38
|
+
const bridge = useHostBridge();
|
|
39
|
+
const callTool = useCallback((name, args) => bridge.callTool(name, args), [bridge]);
|
|
40
|
+
const isPending = tool.status === "pending";
|
|
41
|
+
const initialViewData = tool.status === "ready" ? tool.toolOutput : undefined;
|
|
42
|
+
const toolInput = tool.toolInput;
|
|
31
43
|
const [viewData, setViewData] = useState(null);
|
|
32
|
-
const [displayMode, setDisplayMode] = useState(currentDisplayMode ?? "inline");
|
|
33
|
-
const [prevCurrentDisplayMode, setPrevCurrentDisplayMode] = useState(currentDisplayMode);
|
|
34
|
-
if (currentDisplayMode !== prevCurrentDisplayMode) {
|
|
35
|
-
setPrevCurrentDisplayMode(currentDisplayMode);
|
|
36
|
-
if (currentDisplayMode)
|
|
37
|
-
setDisplayMode(currentDisplayMode);
|
|
38
|
-
}
|
|
39
44
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
40
45
|
// In-iframe build mode is purely a UI state — the LLM never sees the
|
|
41
46
|
// catalogue, the user toggles into build by clicking the toolbar button.
|
|
@@ -59,10 +64,13 @@ export function McpAppView({ widgets, refreshToolName = "refresh-view", builderE
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
// Hosts that strip `structuredContent` from the tool-result notification
|
|
62
|
-
// (claude.ai / Claude Desktop)
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
67
|
+
// (claude.ai / Claude Desktop) never latch a result under mcp-use 2.x — the
|
|
68
|
+
// `useToolContext` latch ignores content-only results, so `isPending` stays
|
|
69
|
+
// true forever. The recovery therefore also arms itself on a grace timer
|
|
70
|
+
// once the originating tool is known, re-executes it via `callTool`
|
|
71
|
+
// (responses carry `structuredContent` intact), and fills the gap.
|
|
72
|
+
// Conforming hosts deliver a valid payload up front, so it never fires
|
|
73
|
+
// there.
|
|
66
74
|
const recovery = useToolResultRecovery({
|
|
67
75
|
resultReady: !isPending,
|
|
68
76
|
props: initialViewData,
|
|
@@ -81,8 +89,10 @@ export function McpAppView({ widgets, refreshToolName = "refresh-view", builderE
|
|
|
81
89
|
const toggleFullscreen = useCallback(async () => {
|
|
82
90
|
const newMode = displayMode === "fullscreen" ? "inline" : "fullscreen";
|
|
83
91
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
// Advisory since 2.x: the promise only confirms the host processed the
|
|
93
|
+
// request. `displayMode` from `useDisplayMode` updates reactively when
|
|
94
|
+
// (and only when) the host actually applies the change.
|
|
95
|
+
await requestDisplayMode({ mode: newMode });
|
|
86
96
|
}
|
|
87
97
|
catch (e) {
|
|
88
98
|
console.error("Failed to toggle display mode:", e);
|
|
@@ -135,7 +145,10 @@ export function McpAppView({ widgets, refreshToolName = "refresh-view", builderE
|
|
|
135
145
|
}
|
|
136
146
|
setBuildMode(false);
|
|
137
147
|
}, []);
|
|
138
|
-
|
|
148
|
+
// `isPending` must not gate the render: on hosts that strip
|
|
149
|
+
// `structuredContent` the 2.x latch stays "pending" forever, and recovered
|
|
150
|
+
// viewData still has to replace the skeleton.
|
|
151
|
+
if (!viewData) {
|
|
139
152
|
return (_jsxs("div", { className: "flex flex-col gap-4 p-4", children: [_jsx(Skeleton, { className: "h-8 w-48" }), _jsx(Skeleton, { className: "h-32 w-full" }), _jsx("p", { className: "text-muted-foreground text-sm", children: effectiveLabels.loading })] }));
|
|
140
153
|
}
|
|
141
154
|
const showHeader = !buildMode;
|
|
@@ -147,17 +160,17 @@ export function McpAppView({ widgets, refreshToolName = "refresh-view", builderE
|
|
|
147
160
|
return (_jsxs("main", { style: {
|
|
148
161
|
// Fullscreen: the widget owns the viewport, so we take the full window
|
|
149
162
|
// and handle our own scrolling. Inline: the host (Claude, ChatGPT) owns
|
|
150
|
-
// sizing + scrolling and
|
|
151
|
-
// `
|
|
152
|
-
// overflowY (which would clip our own content inside a
|
|
153
|
-
// already auto-sized to us).
|
|
163
|
+
// sizing + scrolling and observes our intrinsic height via
|
|
164
|
+
// `bootstrapView`'s auto-resize, so we let content dictate height and
|
|
165
|
+
// avoid setting overflowY (which would clip our own content inside a
|
|
166
|
+
// host that's already auto-sized to us).
|
|
154
167
|
...(displayMode === "fullscreen"
|
|
155
168
|
? { minHeight: "100vh", overflowY: "auto" }
|
|
156
169
|
: null),
|
|
157
|
-
paddingTop: safeArea
|
|
158
|
-
paddingRight: safeArea
|
|
159
|
-
paddingBottom: safeArea
|
|
160
|
-
paddingLeft: safeArea
|
|
170
|
+
paddingTop: safeArea.top,
|
|
171
|
+
paddingRight: safeArea.right,
|
|
172
|
+
paddingBottom: safeArea.bottom,
|
|
173
|
+
paddingLeft: safeArea.left,
|
|
161
174
|
}, children: [showHeader && (_jsxs("div", { className: "mb-4 flex items-center justify-between", children: [viewData.title && _jsx("h2", { className: "text-xl font-bold", children: viewData.title }), _jsxs("div", { className: "ml-auto flex items-center gap-2", children: [viewData._refreshParams && viewData.layout && (_jsxs("button", { onClick: () => {
|
|
162
175
|
void refreshView();
|
|
163
176
|
}, disabled: isRefreshing, className: "hover:bg-accent hover:text-accent-foreground inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-50", children: [_jsx(RefreshCw, { "aria-hidden": "true", className: `h-4 w-4 ${isRefreshing ? "animate-spin" : ""}` }), isRefreshing ? effectiveLabels.refreshing : effectiveLabels.refresh] })), builderAvailable && viewData._refreshParams && (_jsxs("button", { onClick: () => setBuildMode(true), className: "hover:bg-accent hover:text-accent-foreground inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm font-medium transition-colors", children: [_jsx(Pencil, { className: "h-4 w-4" }), effectiveLabels.build] })), _jsxs("button", { onClick: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-app-view.js","sourceRoot":"","sources":["../../src/app/mcp-app-view.tsx"],"names":[],"mappings":";A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-1,18 +1,29 @@
|
|
|
1
1
|
import { type McpAppViewProps } from "./mcp-app-view.js";
|
|
2
2
|
/**
|
|
3
|
-
* Consumer-facing root for a toolkit-rendered MCP App.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Consumer-facing root for a toolkit-rendered MCP App. Composes the mcp-use
|
|
4
|
+
* 2.x view plumbing around `McpAppView`: `ThemeProvider` applies the host's
|
|
5
|
+
* theme/style variables to the document, and `McpUseHostBridgeProvider`
|
|
6
|
+
* installs the `HostBridge` (and view-scope flag) every toolkit widget below
|
|
7
|
+
* resolves through `useHostBridge()`.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
+
* Must render inside a `bootstrapView`-mounted tree — the mcp-use view hooks
|
|
10
|
+
* throw outside one. Use {@link mountMcpToolkitApp} at the bundle entry point,
|
|
11
|
+
* which wires exactly that; render `McpToolkitApp` directly only when
|
|
12
|
+
* composing a custom view under your own `bootstrapView` call.
|
|
13
|
+
*/
|
|
14
|
+
export declare function McpToolkitApp(props: McpAppViewProps): import("react").JSX.Element;
|
|
15
|
+
/**
|
|
16
|
+
* Mount the toolkit app as the document's MCP App view — the bundle entry
|
|
17
|
+
* point since mcp-use 2.x.
|
|
18
|
+
*
|
|
19
|
+
* `bootstrapView` owns the mount: it connects the ext-apps postMessage bridge
|
|
20
|
+
* to the host, installs an error boundary, and auto-reports size changes
|
|
21
|
+
* (replacing 1.x's `createRoot` + `McpUseProvider` pair).
|
|
9
22
|
*
|
|
10
23
|
* ```tsx
|
|
11
|
-
*
|
|
24
|
+
* // main.tsx of the widget bundle
|
|
25
|
+
* mountMcpToolkitApp({ widgets })
|
|
12
26
|
* ```
|
|
13
|
-
*
|
|
14
|
-
* `McpUseProvider` also installs StrictMode, a default ErrorBoundary, and
|
|
15
|
-
* the theme plumbing used by the toolkit primitives.
|
|
16
27
|
*/
|
|
17
|
-
export declare function
|
|
28
|
+
export declare function mountMcpToolkitApp(props: McpAppViewProps): void;
|
|
18
29
|
//# sourceMappingURL=mcp-toolkit-app.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-toolkit-app.d.ts","sourceRoot":"","sources":["../../src/app/mcp-toolkit-app.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"mcp-toolkit-app.d.ts","sourceRoot":"","sources":["../../src/app/mcp-toolkit-app.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGpE;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,+BAQnD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAE/D"}
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { ThemeProvider, bootstrapView } from "mcp-use/react";
|
|
3
3
|
import { McpAppView } from "./mcp-app-view.js";
|
|
4
|
+
import { McpUseHostBridgeProvider } from "./mcp-use-host-bridge.js";
|
|
4
5
|
/**
|
|
5
|
-
* Consumer-facing root for a toolkit-rendered MCP App.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Consumer-facing root for a toolkit-rendered MCP App. Composes the mcp-use
|
|
7
|
+
* 2.x view plumbing around `McpAppView`: `ThemeProvider` applies the host's
|
|
8
|
+
* theme/style variables to the document, and `McpUseHostBridgeProvider`
|
|
9
|
+
* installs the `HostBridge` (and view-scope flag) every toolkit widget below
|
|
10
|
+
* resolves through `useHostBridge()`.
|
|
9
11
|
*
|
|
10
|
-
*
|
|
12
|
+
* Must render inside a `bootstrapView`-mounted tree — the mcp-use view hooks
|
|
13
|
+
* throw outside one. Use {@link mountMcpToolkitApp} at the bundle entry point,
|
|
14
|
+
* which wires exactly that; render `McpToolkitApp` directly only when
|
|
15
|
+
* composing a custom view under your own `bootstrapView` call.
|
|
16
|
+
*/
|
|
17
|
+
export function McpToolkitApp(props) {
|
|
18
|
+
return (_jsx(ThemeProvider, { children: _jsx(McpUseHostBridgeProvider, { children: _jsx(McpAppView, { ...props }) }) }));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Mount the toolkit app as the document's MCP App view — the bundle entry
|
|
22
|
+
* point since mcp-use 2.x.
|
|
23
|
+
*
|
|
24
|
+
* `bootstrapView` owns the mount: it connects the ext-apps postMessage bridge
|
|
25
|
+
* to the host, installs an error boundary, and auto-reports size changes
|
|
26
|
+
* (replacing 1.x's `createRoot` + `McpUseProvider` pair).
|
|
11
27
|
*
|
|
12
28
|
* ```tsx
|
|
13
|
-
*
|
|
29
|
+
* // main.tsx of the widget bundle
|
|
30
|
+
* mountMcpToolkitApp({ widgets })
|
|
14
31
|
* ```
|
|
15
|
-
*
|
|
16
|
-
* `McpUseProvider` also installs StrictMode, a default ErrorBoundary, and
|
|
17
|
-
* the theme plumbing used by the toolkit primitives.
|
|
18
32
|
*/
|
|
19
|
-
export function
|
|
20
|
-
|
|
33
|
+
export function mountMcpToolkitApp(props) {
|
|
34
|
+
bootstrapView({ default: () => _jsx(McpToolkitApp, { ...props }) });
|
|
21
35
|
}
|
|
22
36
|
//# sourceMappingURL=mcp-toolkit-app.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-toolkit-app.js","sourceRoot":"","sources":["../../src/app/mcp-toolkit-app.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mcp-toolkit-app.js","sourceRoot":"","sources":["../../src/app/mcp-toolkit-app.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAwB,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AAEnE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,OAAO,CACL,KAAC,aAAa,cACZ,KAAC,wBAAwB,cACvB,KAAC,UAAU,OAAK,KAAK,GAAI,GACA,GACb,CACjB,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAsB;IACvD,aAAa,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAC,aAAa,OAAK,KAAK,GAAI,EAAE,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/** Whether the subtree runs inside an mcp-use view (see {@link McpUseViewContext}). */
|
|
3
|
+
export declare function useIsInsideMcpUseView(): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Install the `mcp-use` {@link HostBridge} (plus the view-scope flag) for a
|
|
6
|
+
* subtree inside an mcp-use 2.x view.
|
|
7
|
+
*
|
|
8
|
+
* Composes the 2.x view hooks into the `McpUseWidgetSurface` shape and maps it
|
|
9
|
+
* through {@link toHostBridge}, so the fail-soft bridge contract widgets rely
|
|
10
|
+
* on is exactly the pinned one:
|
|
11
|
+
*
|
|
12
|
+
* - `callTool` — the dynamic-tool pool above; resolves with the raw
|
|
13
|
+
* `CallToolResult` envelope, rejects on tool errors.
|
|
14
|
+
* - `sendFollowup` / `openExternal` — `useSendFollowUp` / `useOpenExternal`;
|
|
15
|
+
* while the bridge is not connected (local `file://` preview), `openExternal`
|
|
16
|
+
* throws into `toHostBridge`'s documented `window.open` fallback.
|
|
17
|
+
* - `setModelContext` — writes `{ __model_context }` into the view state,
|
|
18
|
+
* which hosts receive via `ui/update-model-context` (ext-apps) or
|
|
19
|
+
* `widgetState` (ChatGPT). The key is a toolkit-owned convention since 2.x.
|
|
20
|
+
* - `getWidgetData` — the rendering tool's `structuredContent` once ready.
|
|
21
|
+
*
|
|
22
|
+
* Must render inside a `bootstrapView`-mounted tree (the mcp-use hooks throw
|
|
23
|
+
* otherwise) — `McpToolkitApp` does this for the standard bundle; use it
|
|
24
|
+
* directly only when composing a custom shell under `bootstrapView`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function McpUseHostBridgeProvider({ children }: {
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}): ReactNode;
|
|
29
|
+
//# sourceMappingURL=mcp-use-host-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-use-host-bridge.d.ts","sourceRoot":"","sources":["../../src/app/mcp-use-host-bridge.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAqBd,uFAAuF;AACvF,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAoED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,GAAG,SAAS,CAwCzF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { useDynamicTool, useHostContext, useOpenExternal, useSendFollowUp, useToolContext, useViewState, useViewTheme, } from "mcp-use/react";
|
|
4
|
+
import { HostBridgeProvider, toHostBridge } from "./host-bridge.js";
|
|
5
|
+
/**
|
|
6
|
+
* `true` inside an mcp-use 2.x view — i.e. under a
|
|
7
|
+
* {@link McpUseHostBridgeProvider}, which itself only renders under a
|
|
8
|
+
* `bootstrapView`-mounted tree. Components that want to use `mcp-use/react`
|
|
9
|
+
* primitives (which throw outside a view) branch on this instead of probing
|
|
10
|
+
* mcp-use internals; see `adaptDataWidget`'s ModelContext handling.
|
|
11
|
+
*/
|
|
12
|
+
const McpUseViewContext = createContext(false);
|
|
13
|
+
/** Whether the subtree runs inside an mcp-use view (see {@link McpUseViewContext}). */
|
|
14
|
+
export function useIsInsideMcpUseView() {
|
|
15
|
+
return useContext(McpUseViewContext);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Mounts one `useDynamicTool` handle and hands its stable `callTool` up to the
|
|
19
|
+
* pool. This rendered indirection exists because mcp-use 2.x has no public
|
|
20
|
+
* "call any tool by name" API — `useDynamicTool(name)` is fixed per hook
|
|
21
|
+
* instance, so a generic `(name, args)` caller needs one mounted hook per
|
|
22
|
+
* distinct name.
|
|
23
|
+
*/
|
|
24
|
+
function ToolBinder({ name, onBind, }) {
|
|
25
|
+
const { callTool } = useDynamicTool(name);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
onBind(name, callTool);
|
|
28
|
+
}, [name, callTool, onBind]);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A generic `(name, args)` tool caller over mcp-use 2.x's per-name hooks.
|
|
33
|
+
*
|
|
34
|
+
* The first call for a given name mounts a {@link ToolBinder} (one render
|
|
35
|
+
* tick) and resolves once its handle is bound; later calls hit the bound
|
|
36
|
+
* handle directly. Binders accumulate for the mount's lifetime — tool names in
|
|
37
|
+
* a view are a small closed set. Calls left waiting when the view unmounts
|
|
38
|
+
* never settle, which is moot because their callers unmounted with it.
|
|
39
|
+
*/
|
|
40
|
+
function useDynamicToolPool() {
|
|
41
|
+
const [names, setNames] = useState([]);
|
|
42
|
+
const boundRef = useRef(new Map());
|
|
43
|
+
const waitersRef = useRef(new Map());
|
|
44
|
+
const onBind = useCallback((name, call) => {
|
|
45
|
+
boundRef.current.set(name, call);
|
|
46
|
+
const waiters = waitersRef.current.get(name);
|
|
47
|
+
if (!waiters)
|
|
48
|
+
return;
|
|
49
|
+
waitersRef.current.delete(name);
|
|
50
|
+
for (const resolve of waiters)
|
|
51
|
+
resolve(call);
|
|
52
|
+
}, []);
|
|
53
|
+
const callTool = useCallback((name, args) => {
|
|
54
|
+
const bound = boundRef.current.get(name);
|
|
55
|
+
if (bound)
|
|
56
|
+
return bound(args);
|
|
57
|
+
const pending = new Promise((resolve) => {
|
|
58
|
+
const waiters = waitersRef.current.get(name) ?? [];
|
|
59
|
+
waiters.push(resolve);
|
|
60
|
+
waitersRef.current.set(name, waiters);
|
|
61
|
+
});
|
|
62
|
+
setNames((prev) => (prev.includes(name) ? prev : [...prev, name]));
|
|
63
|
+
return pending.then((call) => call(args));
|
|
64
|
+
}, []);
|
|
65
|
+
const binders = useMemo(() => names.map((name) => _jsx(ToolBinder, { name: name, onBind: onBind }, name)), [names, onBind]);
|
|
66
|
+
return { callTool, binders };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Install the `mcp-use` {@link HostBridge} (plus the view-scope flag) for a
|
|
70
|
+
* subtree inside an mcp-use 2.x view.
|
|
71
|
+
*
|
|
72
|
+
* Composes the 2.x view hooks into the `McpUseWidgetSurface` shape and maps it
|
|
73
|
+
* through {@link toHostBridge}, so the fail-soft bridge contract widgets rely
|
|
74
|
+
* on is exactly the pinned one:
|
|
75
|
+
*
|
|
76
|
+
* - `callTool` — the dynamic-tool pool above; resolves with the raw
|
|
77
|
+
* `CallToolResult` envelope, rejects on tool errors.
|
|
78
|
+
* - `sendFollowup` / `openExternal` — `useSendFollowUp` / `useOpenExternal`;
|
|
79
|
+
* while the bridge is not connected (local `file://` preview), `openExternal`
|
|
80
|
+
* throws into `toHostBridge`'s documented `window.open` fallback.
|
|
81
|
+
* - `setModelContext` — writes `{ __model_context }` into the view state,
|
|
82
|
+
* which hosts receive via `ui/update-model-context` (ext-apps) or
|
|
83
|
+
* `widgetState` (ChatGPT). The key is a toolkit-owned convention since 2.x.
|
|
84
|
+
* - `getWidgetData` — the rendering tool's `structuredContent` once ready.
|
|
85
|
+
*
|
|
86
|
+
* Must render inside a `bootstrapView`-mounted tree (the mcp-use hooks throw
|
|
87
|
+
* otherwise) — `McpToolkitApp` does this for the standard bundle; use it
|
|
88
|
+
* directly only when composing a custom shell under `bootstrapView`.
|
|
89
|
+
*/
|
|
90
|
+
export function McpUseHostBridgeProvider({ children }) {
|
|
91
|
+
const { callTool, binders } = useDynamicToolPool();
|
|
92
|
+
const sendFollowUp = useSendFollowUp();
|
|
93
|
+
const openExternal = useOpenExternal();
|
|
94
|
+
const tool = useToolContext();
|
|
95
|
+
const theme = useViewTheme();
|
|
96
|
+
const { isAvailable } = useHostContext();
|
|
97
|
+
const [, setViewState] = useViewState({});
|
|
98
|
+
const output = tool.status === "ready" ? tool.toolOutput : undefined;
|
|
99
|
+
const bridge = useMemo(() => toHostBridge({
|
|
100
|
+
callTool,
|
|
101
|
+
sendFollowUpMessage: (prompt) => sendFollowUp({ prompt }),
|
|
102
|
+
openExternal: (url) => {
|
|
103
|
+
// Not connected (e.g. the bundle opened straight in a browser):
|
|
104
|
+
// throw synchronously so toHostBridge's window.open fallback fires.
|
|
105
|
+
if (!isAvailable)
|
|
106
|
+
throw new Error("mcp-use view bridge is not connected");
|
|
107
|
+
void openExternal({ url }).catch((err) => {
|
|
108
|
+
console.warn("[host-bridge] openExternal failed:", err);
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
output,
|
|
112
|
+
theme,
|
|
113
|
+
setState: (state) => {
|
|
114
|
+
setViewState((prev) => ({ ...prev, ...state }));
|
|
115
|
+
return Promise.resolve();
|
|
116
|
+
},
|
|
117
|
+
}), [callTool, sendFollowUp, openExternal, output, theme, isAvailable, setViewState]);
|
|
118
|
+
return (_jsxs(McpUseViewContext.Provider, { value: true, children: [binders, _jsx(HostBridgeProvider, { bridge: bridge, children: children })] }));
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=mcp-use-host-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-use-host-bridge.js","sourceRoot":"","sources":["../../src/app/mcp-use-host-bridge.tsx"],"names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AC,CAAA;QACJ,CAAC;QACD,MAAM;QACN,KAAK;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,YAAY,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAA;YAC/C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAC1B,CAAC;KACF,CAAC,EACJ,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,CAAC,CACjF,CAAA;IAED,OAAO,CACL,MAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,aACpC,OAAO,EACR,KAAC,kBAAkB,IAAC,MAAM,EAAE,MAAM,YAAG,QAAQ,GAAsB,IACxC,CAC9B,CAAA;AACH,CAAC"}
|
|
@@ -46,12 +46,12 @@ export declare function buildShowWidgetIntent(toolName: string, description: str
|
|
|
46
46
|
* because they cross the UI→chat boundary for different reasons — see above).
|
|
47
47
|
*
|
|
48
48
|
* Relationship to {@link useHostBridge}: this hook resolves the active bridge
|
|
49
|
-
* through `useHostBridge()`, so it
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* `useHostBridge` directly in new portable
|
|
54
|
-
* its named affordances
|
|
49
|
+
* through `useHostBridge()`, so it uses whatever the nearest
|
|
50
|
+
* `HostBridgeProvider` supplies — the toolkit shell installs the `mcp-use`
|
|
51
|
+
* bridge via `McpUseHostBridgeProvider`, ChatGPT / standalone mounts wrap
|
|
52
|
+
* their root themselves — and, like `useHostBridge`, it throws when no
|
|
53
|
+
* provider is present. Prefer `useHostBridge` directly in new portable
|
|
54
|
+
* widgets; `useHostActions` stays for its named affordances.
|
|
55
55
|
*/
|
|
56
56
|
export declare function useHostActions(): HostActions;
|
|
57
57
|
//# sourceMappingURL=use-host-actions.d.ts.map
|
|
@@ -19,12 +19,12 @@ export function buildShowWidgetIntent(toolName, description) {
|
|
|
19
19
|
* because they cross the UI→chat boundary for different reasons — see above).
|
|
20
20
|
*
|
|
21
21
|
* Relationship to {@link useHostBridge}: this hook resolves the active bridge
|
|
22
|
-
* through `useHostBridge()`, so it
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* `useHostBridge` directly in new portable
|
|
27
|
-
* its named affordances
|
|
22
|
+
* through `useHostBridge()`, so it uses whatever the nearest
|
|
23
|
+
* `HostBridgeProvider` supplies — the toolkit shell installs the `mcp-use`
|
|
24
|
+
* bridge via `McpUseHostBridgeProvider`, ChatGPT / standalone mounts wrap
|
|
25
|
+
* their root themselves — and, like `useHostBridge`, it throws when no
|
|
26
|
+
* provider is present. Prefer `useHostBridge` directly in new portable
|
|
27
|
+
* widgets; `useHostActions` stays for its named affordances.
|
|
28
28
|
*/
|
|
29
29
|
export function useHostActions() {
|
|
30
30
|
const bridge = useHostBridge();
|
|
@@ -67,8 +67,11 @@ export declare class FixtureCallToolRegistry {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* A host action a widget asked the host to perform, surfaced to the harness so
|
|
70
|
-
* it can render an activity log.
|
|
71
|
-
*
|
|
70
|
+
* it can render an activity log. The `HostBridge` verbs (`callTool`,
|
|
71
|
+
* `sendFollowup`, `openExternal`) fire in the harness; `requestDisplayMode` /
|
|
72
|
+
* `setWidgetState` remain in the union for log-renderer compatibility but no
|
|
73
|
+
* longer fire — they belonged to the 1.x `window.openai` shim this harness
|
|
74
|
+
* used to install.
|
|
72
75
|
*/
|
|
73
76
|
export type HostActionLog = {
|
|
74
77
|
type: "callTool";
|
|
@@ -122,13 +125,14 @@ export interface WidgetFixtureHostProps {
|
|
|
122
125
|
dataType?: string;
|
|
123
126
|
/**
|
|
124
127
|
* Tool fixtures keyed by tool name. Each value is a static result or a
|
|
125
|
-
* handler — see {@link FixtureToolEntry}. Drives
|
|
126
|
-
* `
|
|
128
|
+
* handler — see {@link FixtureToolEntry}. Drives the simulated
|
|
129
|
+
* `HostBridge.callTool` and the toolkit's `useToolQuery`.
|
|
127
130
|
*/
|
|
128
131
|
tools?: Record<string, FixtureToolEntry>;
|
|
129
132
|
/**
|
|
130
|
-
* Host context
|
|
131
|
-
*
|
|
133
|
+
* Host context overrides, merged over {@link DEFAULT_GLOBALS}. Since the
|
|
134
|
+
* mcp-use 2.x move only `theme` influences the simulated host; the other
|
|
135
|
+
* keys are accepted for compatibility with existing playground setups.
|
|
132
136
|
*/
|
|
133
137
|
globals?: Record<string, unknown>;
|
|
134
138
|
/**
|
|
@@ -155,25 +159,24 @@ export declare function buildFixtureWidgetProps(data: Record<string, unknown>, d
|
|
|
155
159
|
* without booting a real MCP host or backend.
|
|
156
160
|
*
|
|
157
161
|
* ### What it mocks
|
|
158
|
-
* -
|
|
159
|
-
*
|
|
160
|
-
* {@link FixtureCallToolRegistry} built from `tools`;
|
|
161
|
-
* `openExternal
|
|
162
|
+
* - **A {@link HostBridge}** — a `createStandaloneHostBridge` over the fixture
|
|
163
|
+
* registry and callbacks, provided via `HostBridgeProvider`. `callTool`
|
|
164
|
+
* resolves against the {@link FixtureCallToolRegistry} built from `tools`;
|
|
165
|
+
* `sendFollowup` / `openExternal` are reported to `onHostAction`;
|
|
166
|
+
* `setModelContext` feeds `onModelContext`, so you can *see* what the model
|
|
167
|
+
* would (adapted widgets report through this bridge outside a real view).
|
|
162
168
|
* - **The toolkit `AppQueryProvider`** — so widgets that fetch via `useToolQuery`
|
|
163
169
|
* (e.g. generated `use*` hooks) resolve against the same registry.
|
|
164
|
-
* - **`ModelContext`** — a flush handler captures the serialized context string
|
|
165
|
-
* and forwards it to `onModelContext`, so you can *see* what the model would.
|
|
166
|
-
* - **A {@link HostBridge}** — a `createStandaloneHostBridge` over the same
|
|
167
|
-
* registry and callbacks, provided via `HostBridgeProvider`, so widgets
|
|
168
|
-
* written against `useHostBridge` (the host-portable pattern) are simulated
|
|
169
|
-
* from the same single source as the `window.openai` shim above.
|
|
170
170
|
*
|
|
171
171
|
* ### Boundaries
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
172
|
+
* The harness simulates the **host-portable pattern** (`useHostBridge`,
|
|
173
|
+
* `useToolQuery`) — the surface the toolkit's skills teach. It does not
|
|
174
|
+
* simulate the mcp-use 2.x view runtime: since 2.x the `mcp-use/react` hooks
|
|
175
|
+
* only run under a `bootstrapView`-mounted view speaking the ext-apps
|
|
176
|
+
* postMessage protocol (the 1.x `window.openai` shim this harness used to
|
|
177
|
+
* install has no equivalent seam). A widget that calls `mcp-use/react` hooks
|
|
178
|
+
* directly must be exercised against a real host — or rewritten against
|
|
179
|
+
* `useHostBridge`, which is the portable contract anyway.
|
|
177
180
|
*/
|
|
178
181
|
export declare function WidgetFixtureHost({ widget: Widget, data, dataType, tools, globals, onModelContext, onHostAction, }: WidgetFixtureHostProps): ReactNode;
|
|
179
182
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-fixture.d.ts","sourceRoot":"","sources":["../../src/app/widget-fixture.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"widget-fixture.d.ts","sourceRoot":"","sources":["../../src/app/widget-fixture.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC9F,OAAO,KAAK,EAA+B,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAIzF;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OA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