@maxhealth.tech/prefab 0.3.18 → 0.3.19
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/CHANGELOG.md +20 -0
- package/dist/a2ui/browser.js +1 -2
- package/dist/a2ui/browser.js.map +1 -1
- package/dist/a2ui/expr.d.ts +7 -54
- package/dist/a2ui/expr.d.ts.map +1 -1
- package/dist/a2ui/expr.js +13 -90
- package/dist/a2ui/expr.js.map +1 -1
- package/dist/a2ui/icons.d.ts +3 -25
- package/dist/a2ui/icons.d.ts.map +1 -1
- package/dist/a2ui/icons.js +4 -33
- package/dist/a2ui/icons.js.map +1 -1
- package/dist/a2ui/types.d.ts +7 -54
- package/dist/a2ui/types.d.ts.map +1 -1
- package/dist/a2ui/types.js +2 -21
- package/dist/a2ui/types.js.map +1 -1
- package/dist/a2ui.min.js +1 -1
- package/dist/actions/subscribe.d.ts +3 -18
- package/dist/actions/subscribe.d.ts.map +1 -1
- package/dist/actions/subscribe.js +2 -17
- package/dist/actions/subscribe.js.map +1 -1
- package/dist/components/pdf/index.d.ts +3 -9
- package/dist/components/pdf/index.d.ts.map +1 -1
- package/dist/components/pdf/index.js +2 -8
- package/dist/components/pdf/index.js.map +1 -1
- package/dist/core/escape.d.ts +1 -19
- package/dist/core/escape.d.ts.map +1 -1
- package/dist/core/escape.js +1 -19
- package/dist/core/escape.js.map +1 -1
- package/dist/core/humanize.d.ts +2 -17
- package/dist/core/humanize.d.ts.map +1 -1
- package/dist/core/humanize.js +8 -20
- package/dist/core/humanize.js.map +1 -1
- package/dist/core/logger.d.ts +1 -9
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +1 -9
- package/dist/core/logger.js.map +1 -1
- package/dist/core/stringify.d.ts +2 -19
- package/dist/core/stringify.d.ts.map +1 -1
- package/dist/core/stringify.js +3 -21
- package/dist/core/stringify.js.map +1 -1
- package/dist/core/validate.d.ts.map +1 -1
- package/dist/core/validate.js +23 -26
- package/dist/core/validate.js.map +1 -1
- package/dist/core/version.d.ts +3 -22
- package/dist/core/version.d.ts.map +1 -1
- package/dist/core/version.js +3 -22
- package/dist/core/version.js.map +1 -1
- package/dist/mcp/a2ui.d.ts +6 -36
- package/dist/mcp/a2ui.d.ts.map +1 -1
- package/dist/mcp/a2ui.js +6 -36
- package/dist/mcp/a2ui.js.map +1 -1
- package/dist/mcp/input-required.d.ts.map +1 -1
- package/dist/mcp/input-required.js +2 -8
- package/dist/mcp/input-required.js.map +1 -1
- package/dist/mcp/resource.d.ts +12 -88
- package/dist/mcp/resource.d.ts.map +1 -1
- package/dist/mcp/resource.js +18 -85
- package/dist/mcp/resource.js.map +1 -1
- package/dist/mcp/result.d.ts +2 -27
- package/dist/mcp/result.d.ts.map +1 -1
- package/dist/mcp/result.js +2 -27
- package/dist/mcp/result.js.map +1 -1
- package/dist/mcp/theme-bridge.d.ts +5 -36
- package/dist/mcp/theme-bridge.d.ts.map +1 -1
- package/dist/mcp/theme-bridge.js +6 -43
- package/dist/mcp/theme-bridge.js.map +1 -1
- package/dist/mcp/types.d.ts +11 -106
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/types.js +2 -22
- package/dist/mcp/types.js.map +1 -1
- package/dist/renderer/actions.d.ts +2 -2
- package/dist/renderer/actions.d.ts.map +1 -1
- package/dist/renderer/actions.js +6 -2
- package/dist/renderer/actions.js.map +1 -1
- package/dist/renderer/app.d.ts.map +1 -1
- package/dist/renderer/app.js +3 -2
- package/dist/renderer/app.js.map +1 -1
- package/dist/renderer/auto.js +9 -4
- package/dist/renderer/auto.js.map +1 -1
- package/dist/renderer/bridge.d.ts +3 -7
- package/dist/renderer/bridge.d.ts.map +1 -1
- package/dist/renderer/bridge.js +38 -64
- package/dist/renderer/bridge.js.map +1 -1
- package/dist/renderer/components/alert.d.ts.map +1 -1
- package/dist/renderer/components/alert.js +4 -2
- package/dist/renderer/components/alert.js.map +1 -1
- package/dist/renderer/components/choice.d.ts.map +1 -1
- package/dist/renderer/components/choice.js +5 -4
- package/dist/renderer/components/choice.js.map +1 -1
- package/dist/renderer/components/control.d.ts.map +1 -1
- package/dist/renderer/components/control.js +16 -9
- package/dist/renderer/components/control.js.map +1 -1
- package/dist/renderer/components/data.d.ts.map +1 -1
- package/dist/renderer/components/data.js +17 -15
- package/dist/renderer/components/data.js.map +1 -1
- package/dist/renderer/components/form.d.ts.map +1 -1
- package/dist/renderer/components/form.js +18 -17
- package/dist/renderer/components/form.js.map +1 -1
- package/dist/renderer/components/interactive.d.ts.map +1 -1
- package/dist/renderer/components/interactive.js +3 -2
- package/dist/renderer/components/interactive.js.map +1 -1
- package/dist/renderer/components/media.d.ts.map +1 -1
- package/dist/renderer/components/media.js +13 -10
- package/dist/renderer/components/media.js.map +1 -1
- package/dist/renderer/components/pdf.d.ts +1 -10
- package/dist/renderer/components/pdf.d.ts.map +1 -1
- package/dist/renderer/components/pdf.js +19 -14
- package/dist/renderer/components/pdf.js.map +1 -1
- package/dist/renderer/components/table.js +2 -2
- package/dist/renderer/components/table.js.map +1 -1
- package/dist/renderer/components/typography.d.ts.map +1 -1
- package/dist/renderer/components/typography.js +4 -2
- package/dist/renderer/components/typography.js.map +1 -1
- package/dist/renderer/engine.d.ts.map +1 -1
- package/dist/renderer/engine.js +5 -6
- package/dist/renderer/engine.js.map +1 -1
- package/dist/renderer/host-context.d.ts +8 -0
- package/dist/renderer/host-context.d.ts.map +1 -0
- package/dist/renderer/host-context.js +62 -0
- package/dist/renderer/host-context.js.map +1 -0
- package/dist/renderer/index.d.ts.map +1 -1
- package/dist/renderer/index.js +20 -20
- package/dist/renderer/index.js.map +1 -1
- package/dist/renderer/rx.d.ts.map +1 -1
- package/dist/renderer/rx.js +17 -24
- package/dist/renderer/rx.js.map +1 -1
- package/dist/renderer/state.d.ts.map +1 -1
- package/dist/renderer/state.js +10 -4
- package/dist/renderer/state.js.map +1 -1
- package/dist/renderer.auto.min.js +10 -10
- package/dist/renderer.min.js +10 -10
- package/dist/rx/pipes.d.ts +3 -19
- package/dist/rx/pipes.d.ts.map +1 -1
- package/dist/rx/pipes.js +3 -19
- package/dist/rx/pipes.js.map +1 -1
- package/dist/rx/signal.d.ts +3 -13
- package/dist/rx/signal.d.ts.map +1 -1
- package/dist/rx/signal.js +2 -9
- package/dist/rx/signal.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/mcp/resource.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/mcp/resource.ts"],"names":[],"mappings":"AAAA,oKAAoK;AAKpK,OAAO,KAAK,EAAE,YAAY,EAAiB,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAC7G,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAMpE,gDAAgD;AAChD,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,oCAAoC;IACpC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAC1B;AAED,yDAAyD;AACzD,MAAM,WAAW,iBAAiB;IAChC,0DAA0D;IAC1D,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,gEAAgE;IAChE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,0DAA0D;IAC1D,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,mBAAmB;IAClC,iCAAiC;IACjC,GAAG,CAAC,EAAE,SAAS,CAAA;IACf,sDAAsD;IACtD,WAAW,CAAC,EAAE,iBAAiB,CAAA;CAChC;AAED,yEA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AI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAA;IAC3G,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAA;IACnG,mFAAmF;IACnF,MAAM,CAAC,EAAE;QAAE,oBAAoB,CAAC,CAAC,YAAY,EAAE,qBAAqB,GAAG,IAAI,CAAA;KAAE,CAAA;IAC7E,6DAA6D;IAC7D,oBAAoB,CAAC,CAAC,YAAY,EAAE,qBAAqB,GAAG,IAAI,CAAA;CACjE;AAED,wHAAwH;AACxH,wBAAgB,YAAY,CAC1B,IAAI,CAAC,EAAE,YAAY,EACnB,QAAQ,GAAE,QAAQ,CAAC,YAAY,CAAwB,GACtD,QAAQ,CAAC,YAAY,CAAC,CAUxB;AAcD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAsDnG"}
|
package/dist/mcp/resource.js
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Apps resource helpers — register the prefab viewer as a `ui://` resource.
|
|
3
|
-
*
|
|
4
|
-
* Covers the three things every MCP Apps host checks and the two the
|
|
5
|
-
* 2026-07-28 protocol revision added:
|
|
6
|
-
* - the `text/html;profile=mcp-app` MIME type,
|
|
7
|
-
* - `_meta.ui` CSP / permissions on BOTH the listing and the content item,
|
|
8
|
-
* - the viewer HTML itself (CDN-pinned to this exact package version),
|
|
9
|
-
* - `ttlMs` / `cacheScope` on the read result (SEP-2549 `CacheableResult`),
|
|
10
|
-
* - the `io.modelcontextprotocol/ui` extension capability (SEP-2133).
|
|
11
|
-
*/
|
|
1
|
+
/** Register the prefab viewer as a `ui://` MCP Apps resource: MIME type, `_meta.ui` on listing and content, CDN-pinned HTML, cache fields, extension capability. */
|
|
12
2
|
import { VERSION } from '../app.js';
|
|
13
3
|
import { createLogger } from '../core/logger.js';
|
|
14
4
|
import { escapeHtml } from '../core/escape.js';
|
|
15
5
|
import { themeBridgeCss } from './theme-bridge.js';
|
|
16
6
|
const log = createLogger('mcp');
|
|
17
7
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Includes CSP and Permission Policy configuration per the MCP Apps spec.
|
|
21
|
-
* Use on both the resource listing AND the content item (VS Code reads
|
|
22
|
-
* only the content item; other hosts may read either).
|
|
8
|
+
* The `_meta` (CSP, permissions) for a `ui://` resource. Put it on the listing and the content item: VS Code reads only the latter.
|
|
23
9
|
*
|
|
24
10
|
* @example
|
|
25
11
|
* ```ts
|
|
@@ -79,54 +65,21 @@ export const PREFAB_CDN_META = resourceMeta({
|
|
|
79
65
|
export const PREFAB_RESOURCE_URI = 'ui://prefab/viewer';
|
|
80
66
|
/** MIME type required by MCP Apps hosts. */
|
|
81
67
|
export const MCP_APP_MIME = 'text/html;profile=mcp-app';
|
|
82
|
-
/**
|
|
83
|
-
* Capability key for the MCP Apps extension (versioned independently of core).
|
|
84
|
-
*
|
|
85
|
-
* The identifier is `…/ui`, and the trap here is that `…/apps` looks right and is
|
|
86
|
-
* wrong. The normative source is the MCP Apps spec, which states "This extension is
|
|
87
|
-
* identified as: `io.modelcontextprotocol/ui`" in both the current `2026-01-26`
|
|
88
|
-
* revision and the draft, and the reference implementation agrees:
|
|
89
|
-
* `ext-apps/src/server/index.ts` exports `EXTENSION_ID = "io.modelcontextprotocol/ui"`.
|
|
90
|
-
*
|
|
91
|
-
* `io.modelcontextprotocol/apps` appears only as illustrative "e.g." text in the Rust
|
|
92
|
-
* and C# SDKs' generic `ServerCapabilities.extensions` doc comments (and their test
|
|
93
|
-
* fixtures), showing the SHAPE of the extensions map rather than naming this extension.
|
|
94
|
-
* Copying it from there declares the capability under a key no host looks up, which
|
|
95
|
-
* fails silently: rendering still works, because hosts fall back to detecting apps via
|
|
96
|
-
* `_meta.ui` plus the MIME type, so only the SEP-2133 declaration is lost.
|
|
97
|
-
*
|
|
98
|
-
* Duplicated as a literal rather than imported, because prefab ships zero dependencies.
|
|
99
|
-
*/
|
|
68
|
+
/** The MCP Apps extension id, `…/ui` per the spec and ext-apps (`…/apps` in some SDK doc examples is only illustrative). */
|
|
100
69
|
export const APPS_EXTENSION = 'io.modelcontextprotocol/ui';
|
|
101
|
-
/**
|
|
102
|
-
* Default cache hint for the viewer resource.
|
|
103
|
-
*
|
|
104
|
-
* The HTML is a pure function of this package's `VERSION` (the CDN base pins
|
|
105
|
-
* the exact version), so it cannot change for a given server build — it is
|
|
106
|
-
* safely shared-cacheable. Without this the SDK falls back to the conservative
|
|
107
|
-
* `{ ttlMs: 0, cacheScope: 'private' }` and the viewer is re-fetched every time.
|
|
108
|
-
*/
|
|
70
|
+
/** Viewer cache hint: the HTML is a pure function of `VERSION`, so it is shared-cacheable for a day. */
|
|
109
71
|
export const DEFAULT_VIEWER_CACHE = {
|
|
110
72
|
ttlMs: 86_400_000, // 24h
|
|
111
73
|
cacheScope: 'public',
|
|
112
74
|
};
|
|
113
|
-
/**
|
|
114
|
-
* Runtime whitelist for {@link McpCacheScope}.
|
|
115
|
-
*
|
|
116
|
-
* Kept as a value (not just the union type) so the guard in `resolveCache` still
|
|
117
|
-
* rejects a bad scope handed over from untyped JS — a `!==` chain against the
|
|
118
|
-
* union narrows itself away and validates nothing.
|
|
119
|
-
*/
|
|
75
|
+
/** Runtime list of {@link McpCacheScope}, so untyped JS callers are validated too. */
|
|
120
76
|
const CACHE_SCOPES = ['public', 'private'];
|
|
121
77
|
/** CDN base for the @maxhealth.tech/prefab package (exact version, never stale). */
|
|
122
78
|
function cdnBase() {
|
|
123
79
|
return `https://cdn.jsdelivr.net/npm/@maxhealth.tech/prefab@${VERSION}/dist`;
|
|
124
80
|
}
|
|
125
81
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* Returns the minimal HTML that loads `prefab.css` and `renderer.auto.min.js`
|
|
129
|
-
* from the CDN, plus any additional scripts/stylesheets you specify.
|
|
82
|
+
* The viewer HTML: `prefab.css` and `renderer.auto.min.js` from the CDN, plus your scripts and stylesheets.
|
|
130
83
|
*
|
|
131
84
|
* @example
|
|
132
85
|
* ```ts
|
|
@@ -141,8 +94,7 @@ function cdnBase() {
|
|
|
141
94
|
export function rendererHtml(options) {
|
|
142
95
|
const title = options?.title ?? 'Prefab';
|
|
143
96
|
const base = options?.cdnBase ?? cdnBase();
|
|
144
|
-
// Order
|
|
145
|
-
// over it), then the caller's stylesheets as the outermost override.
|
|
97
|
+
// Order matters: prefab.css, then the bridge, then the caller's stylesheets.
|
|
146
98
|
const bridge = options?.themeBridge
|
|
147
99
|
? ` <style>\n${themeBridgeCss(options.themeBridge)}\n </style>\n`
|
|
148
100
|
: '';
|
|
@@ -166,15 +118,7 @@ ${bridge}${extraStyles}</head>
|
|
|
166
118
|
${extraScripts}</body>
|
|
167
119
|
</html>`;
|
|
168
120
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Fill in and validate the `CacheableResult` fields, rejecting values the SDK
|
|
171
|
-
* would silently discard in favour of `ttlMs: 0`.
|
|
172
|
-
*
|
|
173
|
-
* `defaults` differ per resource kind: the viewer HTML is a pure function of the
|
|
174
|
-
* package version and is safely shared-cacheable, while an `a2ui://` surface is
|
|
175
|
-
* rebuilt on every read and defaults to no caching. Exported so `./a2ui.ts`
|
|
176
|
-
* resolves its hints through the same guard rather than restating it.
|
|
177
|
-
*/
|
|
121
|
+
/** Fill in and validate `CacheableResult` fields, throwing on values the SDK would silently replace with `ttlMs: 0`. */
|
|
178
122
|
export function resolveCache(hint, defaults = DEFAULT_VIEWER_CACHE) {
|
|
179
123
|
const ttlMs = hint?.ttlMs ?? defaults.ttlMs;
|
|
180
124
|
if (!Number.isSafeInteger(ttlMs) || ttlMs < 0) {
|
|
@@ -188,8 +132,6 @@ export function resolveCache(hint, defaults = DEFAULT_VIEWER_CACHE) {
|
|
|
188
132
|
}
|
|
189
133
|
/** Declare the MCP Apps extension capability, tolerating servers that cannot. */
|
|
190
134
|
function declareAppsExtension(server) {
|
|
191
|
-
// Not named `declare` — that is a TS modifier keyword at statement position
|
|
192
|
-
// and some transpilers refuse to parse a call to a binding of that name.
|
|
193
135
|
const declareCaps = server.registerCapabilities?.bind(server)
|
|
194
136
|
?? server.server?.registerCapabilities?.bind(server.server);
|
|
195
137
|
if (declareCaps == null)
|
|
@@ -198,16 +140,11 @@ function declareAppsExtension(server) {
|
|
|
198
140
|
declareCaps({ extensions: { [APPS_EXTENSION]: {} } });
|
|
199
141
|
}
|
|
200
142
|
catch (e) {
|
|
201
|
-
// Both SDK generations throw when called after connect. The server still
|
|
202
|
-
// serves the resource — it just does not advertise the extension.
|
|
203
143
|
log.warn(`could not declare the ${APPS_EXTENSION} capability (register the viewer before connecting):`, e);
|
|
204
144
|
}
|
|
205
145
|
}
|
|
206
146
|
/**
|
|
207
|
-
* Register the prefab viewer as a `ui://` resource
|
|
208
|
-
*
|
|
209
|
-
* Handles the MIME type, CSP on both listing and content item, HTML generation,
|
|
210
|
-
* the `CacheableResult` fields and the Apps extension capability in one call.
|
|
147
|
+
* Register the prefab viewer as a `ui://` resource. The CSP admits jsDelivr and every origin the page loads from.
|
|
211
148
|
*
|
|
212
149
|
* @example
|
|
213
150
|
* ```ts
|
|
@@ -236,17 +173,17 @@ export function registerViewerResource(server, options) {
|
|
|
236
173
|
baseUriDomains: options.csp.baseUriDomains ?? [],
|
|
237
174
|
}
|
|
238
175
|
: { resourceDomains: ['https://cdn.jsdelivr.net'] };
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return new URL(url).origin;
|
|
176
|
+
const loadedFrom = [...(options?.scripts ?? []), ...(options?.stylesheets ?? []), ...(options?.cdnBase != null ? [options.cdnBase] : [])];
|
|
177
|
+
const loadedOrigins = loadedFrom.flatMap(url => {
|
|
178
|
+
try {
|
|
179
|
+
return [new URL(url).origin];
|
|
244
180
|
}
|
|
245
181
|
catch {
|
|
246
|
-
return
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
if (loadedOrigins.length > 0) {
|
|
186
|
+
csp.resourceDomains = [...new Set([...(csp.resourceDomains ?? []), ...loadedOrigins])];
|
|
250
187
|
}
|
|
251
188
|
const meta = resourceMeta({ csp, permissions: options?.permissions });
|
|
252
189
|
const html = rendererHtml({
|
|
@@ -268,13 +205,9 @@ export function registerViewerResource(server, options) {
|
|
|
268
205
|
text: html,
|
|
269
206
|
_meta: meta,
|
|
270
207
|
}],
|
|
271
|
-
// Handler-provided cache fields take precedence over any server hint, and
|
|
272
|
-
// make the result spec-compliant on servers that fill in nothing.
|
|
273
208
|
ttlMs: cache.ttlMs,
|
|
274
209
|
cacheScope: cache.cacheScope,
|
|
275
210
|
});
|
|
276
|
-
// registerResource is the current API in both SDK generations; resource() is
|
|
277
|
-
// the v1 overload that v2 dropped.
|
|
278
211
|
const register = server.registerResource?.bind(server) ?? server.resource?.bind(server);
|
|
279
212
|
if (register == null) {
|
|
280
213
|
throw new TypeError('registerViewerResource: server exposes neither registerResource() nor resource()');
|
package/dist/mcp/resource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/mcp/resource.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/mcp/resource.ts"],"names":[],"mappings":"AAAA,oKAAoK;AAEpK,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAoB,M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ClB,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACvF,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,SAAS,CAAC,kFAAkF,CAAC,CAAA;IACzG,CAAC;IACD,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AACtC,CAAC"}
|
package/dist/mcp/result.d.ts
CHANGED
|
@@ -1,36 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP tool-result envelope.
|
|
3
|
-
*
|
|
4
|
-
* Every prefab display helper returns the same shape: the wire JSON as a text
|
|
5
|
-
* content block plus `structuredContent` for MCP Apps hosts to hand to the
|
|
6
|
-
* iframe. Building that envelope in one place keeps the `display_*` builders
|
|
7
|
-
* identical by construction.
|
|
8
|
-
*
|
|
9
|
-
* `structuredContent` is typed through the generic rather than widened to
|
|
10
|
-
* `Record<string, unknown>`, so callers keep the wire type and no cast is
|
|
11
|
-
* needed anywhere (protocol revision 2026-07-28 loosened the field to any JSON
|
|
12
|
-
* value — SEP-2106).
|
|
13
|
-
*
|
|
14
|
-
* `resultType` (SEP-2322) is deliberately NOT set here. It is a wire-only
|
|
15
|
-
* discriminator owned by the SDK's protocol layer: `@modelcontextprotocol/server`
|
|
16
|
-
* stamps it at its 2026-era encode seam and strips it before results reach
|
|
17
|
-
* consumers, which is why its public result types do not declare it.
|
|
18
|
-
*
|
|
19
|
-
* The one handler-authored case is `resultType: 'input_required'`, which a
|
|
20
|
-
* completed result never carries. That case is built by `./input-required.ts`
|
|
21
|
-
* and returned instead of a tool result, so it never travels through here.
|
|
22
|
-
*/
|
|
1
|
+
/** The one tool-result envelope every `display_*` helper returns. `resultType` (SEP-2322) is left to the SDK, which stamps it on encode. */
|
|
23
2
|
import type { McpDisplayResult } from './types.js';
|
|
24
3
|
export interface ToolResultOptions {
|
|
25
4
|
/** Flag the result as failed (hosts render it as a tool error). */
|
|
26
5
|
isError?: boolean;
|
|
27
6
|
}
|
|
28
7
|
/**
|
|
29
|
-
* Wrap a JSON payload as an MCP tool result.
|
|
30
|
-
*
|
|
31
|
-
* The payload is serialized into `content[0].text` (for hosts and models that
|
|
32
|
-
* read text) and passed through as `structuredContent` (for MCP Apps iframes,
|
|
33
|
-
* which receive it via `ui/notifications/tool-result`).
|
|
8
|
+
* Wrap a JSON payload as an MCP tool result: serialized into `content[0].text` and passed through as `structuredContent`.
|
|
34
9
|
*
|
|
35
10
|
* @example
|
|
36
11
|
* ```ts
|
package/dist/mcp/result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/mcp/result.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/mcp/result.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAE5I,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAO1F"}
|
package/dist/mcp/result.js
CHANGED
|
@@ -1,31 +1,6 @@
|
|
|
1
|
+
/** The one tool-result envelope every `display_*` helper returns. `resultType` (SEP-2322) is left to the SDK, which stamps it on encode. */
|
|
1
2
|
/**
|
|
2
|
-
* MCP tool
|
|
3
|
-
*
|
|
4
|
-
* Every prefab display helper returns the same shape: the wire JSON as a text
|
|
5
|
-
* content block plus `structuredContent` for MCP Apps hosts to hand to the
|
|
6
|
-
* iframe. Building that envelope in one place keeps the `display_*` builders
|
|
7
|
-
* identical by construction.
|
|
8
|
-
*
|
|
9
|
-
* `structuredContent` is typed through the generic rather than widened to
|
|
10
|
-
* `Record<string, unknown>`, so callers keep the wire type and no cast is
|
|
11
|
-
* needed anywhere (protocol revision 2026-07-28 loosened the field to any JSON
|
|
12
|
-
* value — SEP-2106).
|
|
13
|
-
*
|
|
14
|
-
* `resultType` (SEP-2322) is deliberately NOT set here. It is a wire-only
|
|
15
|
-
* discriminator owned by the SDK's protocol layer: `@modelcontextprotocol/server`
|
|
16
|
-
* stamps it at its 2026-era encode seam and strips it before results reach
|
|
17
|
-
* consumers, which is why its public result types do not declare it.
|
|
18
|
-
*
|
|
19
|
-
* The one handler-authored case is `resultType: 'input_required'`, which a
|
|
20
|
-
* completed result never carries. That case is built by `./input-required.ts`
|
|
21
|
-
* and returned instead of a tool result, so it never travels through here.
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* Wrap a JSON payload as an MCP tool result.
|
|
25
|
-
*
|
|
26
|
-
* The payload is serialized into `content[0].text` (for hosts and models that
|
|
27
|
-
* read text) and passed through as `structuredContent` (for MCP Apps iframes,
|
|
28
|
-
* which receive it via `ui/notifications/tool-result`).
|
|
3
|
+
* Wrap a JSON payload as an MCP tool result: serialized into `content[0].text` and passed through as `structuredContent`.
|
|
29
4
|
*
|
|
30
5
|
* @example
|
|
31
6
|
* ```ts
|
package/dist/mcp/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/mcp/result.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/mcp/result.ts"],"names":[],"mappings":"AAAA,4IAA4I;AAS5I;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CAAI,OAAU,EAAE,OAA2B;IACnE,MAAM,MAAM,GAAwB;QAClC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,iBAAiB,EAAE,OAAO;KAC3B,CAAA;IACD,IAAI,OAAO,EAAE,OAAO;QAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAA;IAC3C,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* VS Code theme bridge
|
|
3
|
-
*
|
|
4
|
-
* `prefab.css` resolves every token through a fallback chain: MCP Apps host
|
|
5
|
-
* variable first, then the VS Code webview variable, then a static default.
|
|
6
|
-
* That ordering is right in general, but it means a host which defines the MCP
|
|
7
|
-
* Apps `--color-*` variables shadows the VS Code ones entirely, and the viewer
|
|
8
|
-
* stops following the user's editor theme.
|
|
9
|
-
*
|
|
10
|
-
* This module emits a stylesheet that re-declares the affected tokens with the
|
|
11
|
-
* VS Code variable *first* and the MCP Apps layer dropped, at a specificity and
|
|
12
|
-
* document position that beat each of `prefab.css`'s four token blocks. It is
|
|
13
|
-
* opt-in via `rendererHtml({ themeBridge: 'vscode' })`.
|
|
14
|
-
*
|
|
15
|
-
* The table below is the single source of truth for the mapping.
|
|
16
|
-
* `test/theme-bridge.test.ts` cross-checks every entry against `prefab.css`, so
|
|
17
|
-
* the bridge cannot drift from the base theme it overrides.
|
|
2
|
+
* VS Code theme bridge: re-declares tokens with the `--vscode-*` variable first, so a host's MCP Apps `--color-*`
|
|
3
|
+
* layer no longer shadows the editor theme. `test/theme-bridge.test.ts` checks the table against `prefab.css`.
|
|
18
4
|
*/
|
|
19
5
|
/** How one prefab token is sourced from the VS Code webview. */
|
|
20
6
|
export interface VsCodeTokenSource {
|
|
@@ -25,30 +11,13 @@ export interface VsCodeTokenSource {
|
|
|
25
11
|
/** Dark-scheme fallback. Omitted for scheme-independent tokens (fonts). */
|
|
26
12
|
dark?: string;
|
|
27
13
|
}
|
|
28
|
-
/**
|
|
29
|
-
* prefab tokens that VS Code can supply, with the same variables and static
|
|
30
|
-
* fallbacks `prefab.css` uses. Tokens VS Code has no equivalent for (`--success`,
|
|
31
|
-
* `--warning`, shadows, radii) are deliberately absent: the bridge only overrides
|
|
32
|
-
* what the editor can actually provide.
|
|
33
|
-
*/
|
|
14
|
+
/** prefab tokens VS Code can supply, with `prefab.css`'s own fallbacks; tokens it cannot supply are absent. */
|
|
34
15
|
export declare const VSCODE_BRIDGE: Readonly<Record<string, VsCodeTokenSource>>;
|
|
35
16
|
/** Supported theme bridges. */
|
|
36
17
|
export type ThemeBridge = 'vscode';
|
|
37
18
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* Mirrors the selectors `prefab.css` uses for *host-driven* tokens, so the
|
|
41
|
-
* override lands in both schemes rather than only in light mode: the `:root`
|
|
42
|
-
* default (alongside `[data-theme="light"]`, whose higher specificity would
|
|
43
|
-
* otherwise win) and the `prefers-color-scheme: dark` media block. Each selector
|
|
44
|
-
* matches its counterpart's specificity and is emitted after `prefab.css`, so it
|
|
45
|
-
* wins on document order.
|
|
46
|
-
*
|
|
47
|
-
* `:root[data-theme="dark"]` is deliberately NOT bridged. That block is
|
|
48
|
-
* prefab's standalone dark palette with static values and no host chain at all,
|
|
49
|
-
* the explicit separation of host theming (which cascades) from the manual theme
|
|
50
|
-
* toggle. Overriding it would make an app that pins `data-theme="dark"` follow
|
|
51
|
-
* the editor instead of its own choice.
|
|
19
|
+
* The theme-bridge CSS, matching `prefab.css`'s host-driven selectors in both schemes. `[data-theme="dark"]` is
|
|
20
|
+
* left alone, so an app that pins it keeps its own palette.
|
|
52
21
|
*
|
|
53
22
|
* @example
|
|
54
23
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-bridge.d.ts","sourceRoot":"","sources":["../../src/mcp/theme-bridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"theme-bridge.d.ts","sourceRoot":"","sources":["../../src/mcp/theme-bridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,+GAA+G;AAC/G,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CA2BrE,CAAA;AAED,+BAA+B;AAC/B,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAA;AAelC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAe1D"}
|
package/dist/mcp/theme-bridge.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* VS Code theme bridge
|
|
3
|
-
*
|
|
4
|
-
* `prefab.css` resolves every token through a fallback chain: MCP Apps host
|
|
5
|
-
* variable first, then the VS Code webview variable, then a static default.
|
|
6
|
-
* That ordering is right in general, but it means a host which defines the MCP
|
|
7
|
-
* Apps `--color-*` variables shadows the VS Code ones entirely, and the viewer
|
|
8
|
-
* stops following the user's editor theme.
|
|
9
|
-
*
|
|
10
|
-
* This module emits a stylesheet that re-declares the affected tokens with the
|
|
11
|
-
* VS Code variable *first* and the MCP Apps layer dropped, at a specificity and
|
|
12
|
-
* document position that beat each of `prefab.css`'s four token blocks. It is
|
|
13
|
-
* opt-in via `rendererHtml({ themeBridge: 'vscode' })`.
|
|
14
|
-
*
|
|
15
|
-
* The table below is the single source of truth for the mapping.
|
|
16
|
-
* `test/theme-bridge.test.ts` cross-checks every entry against `prefab.css`, so
|
|
17
|
-
* the bridge cannot drift from the base theme it overrides.
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* prefab tokens that VS Code can supply, with the same variables and static
|
|
21
|
-
* fallbacks `prefab.css` uses. Tokens VS Code has no equivalent for (`--success`,
|
|
22
|
-
* `--warning`, shadows, radii) are deliberately absent: the bridge only overrides
|
|
23
|
-
* what the editor can actually provide.
|
|
2
|
+
* VS Code theme bridge: re-declares tokens with the `--vscode-*` variable first, so a host's MCP Apps `--color-*`
|
|
3
|
+
* layer no longer shadows the editor theme. `test/theme-bridge.test.ts` checks the table against `prefab.css`.
|
|
24
4
|
*/
|
|
5
|
+
/** prefab tokens VS Code can supply, with `prefab.css`'s own fallbacks; tokens it cannot supply are absent. */
|
|
25
6
|
export const VSCODE_BRIDGE = {
|
|
26
7
|
'background': { vscode: 'vscode-editor-background', light: '#ffffff', dark: '#09090b' },
|
|
27
8
|
'foreground': { vscode: 'vscode-editor-foreground', light: '#09090b', dark: '#fafafa' },
|
|
@@ -50,13 +31,7 @@ export const VSCODE_BRIDGE = {
|
|
|
50
31
|
light: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
51
32
|
},
|
|
52
33
|
};
|
|
53
|
-
/**
|
|
54
|
-
* Runtime whitelist for {@link ThemeBridge}.
|
|
55
|
-
*
|
|
56
|
-
* Kept as a value, not just the union type, so the guard in `themeBridgeCss`
|
|
57
|
-
* still rejects a bad name handed over from untyped JS. A `!==` chain against a
|
|
58
|
-
* single-member union narrows itself away and validates nothing.
|
|
59
|
-
*/
|
|
34
|
+
/** Runtime list of {@link ThemeBridge}, so untyped JS callers are validated too. */
|
|
60
35
|
const THEME_BRIDGES = ['vscode'];
|
|
61
36
|
function declarations(scheme, indent) {
|
|
62
37
|
return Object.entries(VSCODE_BRIDGE)
|
|
@@ -68,20 +43,8 @@ function declarations(scheme, indent) {
|
|
|
68
43
|
.join('\n');
|
|
69
44
|
}
|
|
70
45
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* Mirrors the selectors `prefab.css` uses for *host-driven* tokens, so the
|
|
74
|
-
* override lands in both schemes rather than only in light mode: the `:root`
|
|
75
|
-
* default (alongside `[data-theme="light"]`, whose higher specificity would
|
|
76
|
-
* otherwise win) and the `prefers-color-scheme: dark` media block. Each selector
|
|
77
|
-
* matches its counterpart's specificity and is emitted after `prefab.css`, so it
|
|
78
|
-
* wins on document order.
|
|
79
|
-
*
|
|
80
|
-
* `:root[data-theme="dark"]` is deliberately NOT bridged. That block is
|
|
81
|
-
* prefab's standalone dark palette with static values and no host chain at all,
|
|
82
|
-
* the explicit separation of host theming (which cascades) from the manual theme
|
|
83
|
-
* toggle. Overriding it would make an app that pins `data-theme="dark"` follow
|
|
84
|
-
* the editor instead of its own choice.
|
|
46
|
+
* The theme-bridge CSS, matching `prefab.css`'s host-driven selectors in both schemes. `[data-theme="dark"]` is
|
|
47
|
+
* left alone, so an app that pins it keeps its own palette.
|
|
85
48
|
*
|
|
86
49
|
* @example
|
|
87
50
|
* ```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme-bridge.js","sourceRoot":"","sources":["../../src/mcp/theme-bridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"theme-bridge.js","sourceRoot":"","sources":["../../src/mcp/theme-bridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,+GAA+G;AAC/G,MAAM,CAAC,MAAM,aAAa,GAAgD;IACxE,YAAY,EAAE,EAAE,MAAM,EAAE,0BAA0B,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACvF,YAAY,EAAE,EAAE,MAAM,EAAE,0BAA0B,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACvF,MAAM,EAAE,EAAE,MAAM,EAAE,gCAAgC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACvF,iBAAiB,EAAE,EAAE,MAAM,EAAE,gCAAgC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE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C;;;;;EAK3B,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC;;EAE5B,CAAA;AACF,CAAC"}
|
package/dist/mcp/types.d.ts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP
|
|
3
|
-
*
|
|
4
|
-
* These are structurally compatible with the SDK's `CallToolResult` and
|
|
5
|
-
* `ReadResourceResult` — prefab helpers can be returned directly from SDK
|
|
6
|
-
* handlers without casting.
|
|
7
|
-
*
|
|
8
|
-
* **Every shape here is a `type` alias, not an `interface`, and that is a
|
|
9
|
-
* correctness requirement rather than a style choice.** The SDK's result types
|
|
10
|
-
* are passthrough (`{ [x: string]: unknown }`), and TypeScript grants an
|
|
11
|
-
* *implicit index signature* only to aliases of object types — never to
|
|
12
|
-
* interfaces, whose key set is not final because declaration merging can reopen
|
|
13
|
-
* them. An interface here therefore fails the one thing these types exist for:
|
|
14
|
-
*
|
|
15
|
-
* Type 'McpResourceReadResult<…>' is not assignable to type '{ [x: string]: unknown; … }'.
|
|
16
|
-
* Index signature for type 'string' is missing in type 'McpResourceReadResult<…>'.
|
|
17
|
-
*
|
|
18
|
-
* `eslint.config.ts` flips `consistent-type-definitions` to `'type'` for this
|
|
19
|
-
* file so the linter enforces that instead of fighting it, and
|
|
20
|
-
* `test/mcp-types.test.ts` guards the assignability itself.
|
|
21
|
-
*
|
|
22
|
-
* @see https://github.com/microsoft/TypeScript/issues/15300
|
|
23
|
-
* @see https://spec.modelcontextprotocol.io/specification/server/tools/
|
|
2
|
+
* MCP result types assignable to the SDK's without a cast. All are `type` aliases on purpose: only aliases get the implicit
|
|
3
|
+
* index signature the SDK's passthrough types require (TypeScript#15300); `test/mcp-types.test.ts` guards it.
|
|
24
4
|
*/
|
|
25
5
|
/** MCP text content block (compatible with SDK's TextContent) */
|
|
26
6
|
export type McpTextContent = {
|
|
@@ -37,24 +17,14 @@ export type McpImageContent = {
|
|
|
37
17
|
annotations?: Record<string, unknown>;
|
|
38
18
|
_meta?: Record<string, unknown>;
|
|
39
19
|
};
|
|
40
|
-
/**
|
|
41
|
-
* Text resource contents (has `text`, never `blob`).
|
|
42
|
-
*
|
|
43
|
-
* Declared as a type alias, not an interface, and the difference is load-bearing.
|
|
44
|
-
* The SDK's resource types are passthrough (`{ [x: string]: unknown }`), and
|
|
45
|
-
* TypeScript grants an *implicit index signature* only to type aliases of object
|
|
46
|
-
* types — never to interfaces, since an interface can be reopened by declaration
|
|
47
|
-
* merging and so its key set is not final. Declaring this as an interface makes
|
|
48
|
-
* it fail to satisfy the SDK's shape with "Index signature for type 'string' is
|
|
49
|
-
* missing", which a consumer can only work around by casting.
|
|
50
|
-
*/
|
|
20
|
+
/** Text resource contents (has `text`, never `blob`). */
|
|
51
21
|
export type McpTextResourceContents = {
|
|
52
22
|
uri: string;
|
|
53
23
|
mimeType?: string;
|
|
54
24
|
text: string;
|
|
55
25
|
_meta?: Record<string, unknown>;
|
|
56
26
|
};
|
|
57
|
-
/** Blob resource contents (has `blob`, never `text`).
|
|
27
|
+
/** Blob resource contents (has `blob`, never `text`). */
|
|
58
28
|
export type McpBlobResourceContents = {
|
|
59
29
|
uri: string;
|
|
60
30
|
mimeType?: string;
|
|
@@ -70,22 +40,7 @@ export type McpResourceContent = {
|
|
|
70
40
|
};
|
|
71
41
|
/** Any MCP content block */
|
|
72
42
|
export type McpContent = McpTextContent | McpImageContent | McpResourceContent;
|
|
73
|
-
/**
|
|
74
|
-
* MCP tool result — returned from tool handlers.
|
|
75
|
-
*
|
|
76
|
-
* Structurally assignable to the SDK's `CallToolResult`. The index signature
|
|
77
|
-
* allows the SDK's `Result` base interface to be satisfied without a cast.
|
|
78
|
-
*
|
|
79
|
-
* `structuredContent` is generic rather than `Record<string, unknown>`: protocol
|
|
80
|
-
* revision 2026-07-28 loosened it to any JSON value (SEP-2106), and keeping the
|
|
81
|
-
* payload type lets callers read it back without casting.
|
|
82
|
-
*
|
|
83
|
-
* The wire discriminator `resultType` (SEP-2322) is intentionally absent. The
|
|
84
|
-
* SDK's protocol layer stamps it on encode and strips it before results reach
|
|
85
|
-
* consumers, so handlers do not author it for ordinary complete results. The
|
|
86
|
-
* index signature still admits `resultType: 'input_required'` for the one case
|
|
87
|
-
* a handler does own — multi-round-trip interim results.
|
|
88
|
-
*/
|
|
43
|
+
/** A tool result assignable to the SDK's `CallToolResult`; `structuredContent` keeps its payload type (any JSON since SEP-2106). */
|
|
89
44
|
export type McpToolResult<S = unknown> = {
|
|
90
45
|
content: McpContent[];
|
|
91
46
|
/** Structured payload forwarded to MCP Apps iframes via ui/notifications/tool-result. */
|
|
@@ -94,54 +49,20 @@ export type McpToolResult<S = unknown> = {
|
|
|
94
49
|
_meta?: Record<string, unknown>;
|
|
95
50
|
[key: string]: unknown;
|
|
96
51
|
};
|
|
97
|
-
/**
|
|
98
|
-
* A tool result whose `structuredContent` is guaranteed present.
|
|
99
|
-
*
|
|
100
|
-
* `McpToolResult.structuredContent` is optional because a hand-written result
|
|
101
|
-
* may legitimately omit it. Every prefab display helper populates it, and
|
|
102
|
-
* saying so in the return type spares callers a null check on a field that is
|
|
103
|
-
* never absent — reading `result.structuredContent.view` should not need one.
|
|
104
|
-
*
|
|
105
|
-
* Assignable to `McpToolResult<S>` in every position, so widening a helper's
|
|
106
|
-
* return type to this breaks nothing.
|
|
107
|
-
*/
|
|
52
|
+
/** A tool result whose `structuredContent` is always present, as every prefab display helper returns. */
|
|
108
53
|
export type McpDisplayResult<S> = McpToolResult<S> & {
|
|
109
54
|
structuredContent: S;
|
|
110
55
|
};
|
|
111
|
-
/**
|
|
112
|
-
* Cache scopes defined for cacheable results.
|
|
113
|
-
*
|
|
114
|
-
* `public` — the result may be stored by shared caches.
|
|
115
|
-
* `private` — only the requesting client may cache it.
|
|
116
|
-
*/
|
|
56
|
+
/** `public`: shared caches may store the result; `private`: only the requesting client may. */
|
|
117
57
|
export type McpCacheScope = 'public' | 'private';
|
|
118
|
-
/**
|
|
119
|
-
* Cache fields required on results from the cacheable operations
|
|
120
|
-
* (`tools/list`, `prompts/list`, `resources/list`, `resources/templates/list`,
|
|
121
|
-
* `resources/read`, `server/discover`).
|
|
122
|
-
*
|
|
123
|
-
* Values a handler returns on the result take precedence over any hint
|
|
124
|
-
* configured on the server; when neither is present the SDK falls back to the
|
|
125
|
-
* conservative `{ ttlMs: 0, cacheScope: 'private' }` — i.e. no caching.
|
|
126
|
-
*/
|
|
58
|
+
/** Cache fields of cacheable results (SEP-2549). The result's own values beat a server hint; with neither, nothing is cached. */
|
|
127
59
|
export type McpCacheHint = {
|
|
128
60
|
/** Cache lifetime in milliseconds. Must be a non-negative safe integer. */
|
|
129
61
|
ttlMs?: number;
|
|
130
62
|
/** Whether shared caches may store the result. */
|
|
131
63
|
cacheScope?: McpCacheScope;
|
|
132
64
|
};
|
|
133
|
-
/**
|
|
134
|
-
* A `resources/read` result carrying the required cache fields.
|
|
135
|
-
*
|
|
136
|
-
* Generic over the contents kind so a handler that only ever returns text (the
|
|
137
|
-
* prefab viewer, for one) does not force callers to narrow the union.
|
|
138
|
-
*
|
|
139
|
-
* A type alias rather than an interface, so it satisfies the SDK's passthrough
|
|
140
|
-
* `ReadResourceResult` (`{ [x: string]: unknown }`) without a cast. See
|
|
141
|
-
* {@link McpTextResourceContents} for why the distinction matters — returning
|
|
142
|
-
* this straight from an SDK read handler is the whole point of the type, and as
|
|
143
|
-
* an interface it did not typecheck there.
|
|
144
|
-
*/
|
|
65
|
+
/** A `resources/read` result with its required cache fields, generic over the contents kind. */
|
|
145
66
|
export type McpResourceReadResult<C extends McpTextResourceContents | McpBlobResourceContents = McpTextResourceContents | McpBlobResourceContents> = {
|
|
146
67
|
contents: C[];
|
|
147
68
|
/** Cache lifetime in milliseconds. */
|
|
@@ -149,16 +70,7 @@ export type McpResourceReadResult<C extends McpTextResourceContents | McpBlobRes
|
|
|
149
70
|
/** Whether shared caches may store the result. */
|
|
150
71
|
cacheScope: McpCacheScope;
|
|
151
72
|
};
|
|
152
|
-
/**
|
|
153
|
-
* The restricted JSON Schema an elicitation may request.
|
|
154
|
-
*
|
|
155
|
-
* Protocol revision 2026-07-28 replaced server-initiated `elicitation/create`
|
|
156
|
-
* pushes with Multi Round-Trip Requests: a handler *returns* an
|
|
157
|
-
* {@link McpInputRequiredResult}, the client answers the embedded requests and
|
|
158
|
-
* retries the original call. The schema is deliberately flat — top-level
|
|
159
|
-
* primitive properties only, no nesting — because it has to render as a form in
|
|
160
|
-
* hosts that have no UI surface of their own.
|
|
161
|
-
*/
|
|
73
|
+
/** A flat elicitation property schema, for {@link McpInputRequiredResult} (Multi Round-Trip, revision 2026-07-28). */
|
|
162
74
|
export type McpStringSchema = {
|
|
163
75
|
type: 'string';
|
|
164
76
|
title?: string;
|
|
@@ -237,14 +149,7 @@ export type McpElicitResult = {
|
|
|
237
149
|
content?: Record<string, string | number | boolean | string[]>;
|
|
238
150
|
};
|
|
239
151
|
export type McpInputResponses = Record<string, McpElicitResult>;
|
|
240
|
-
/**
|
|
241
|
-
* A result asking the client for input before the call can complete.
|
|
242
|
-
*
|
|
243
|
-
* At least one of `inputRequests` or `requestState` must be present, and
|
|
244
|
-
* `resultType` must be `'input_required'`: a server on this revision always
|
|
245
|
-
* stamps the discriminator, and a client that does not see it treats the result
|
|
246
|
-
* as `'complete'` and never retries.
|
|
247
|
-
*/
|
|
152
|
+
/** A result asking for input before the call completes; carries `inputRequests`, `requestState` or both. */
|
|
248
153
|
export type McpInputRequiredResult = {
|
|
249
154
|
resultType: 'input_required';
|
|
250
155
|
inputRequests?: McpInputRequests;
|