@mcp-ts/sdk 1.3.10 → 1.4.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/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/client/index.d.mts +3 -189
- package/dist/client/index.d.ts +3 -189
- package/dist/client/index.js +218 -54
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +215 -55
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/react.d.mts +21 -14
- package/dist/client/react.d.ts +21 -14
- package/dist/client/react.js +402 -83
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +400 -85
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +3 -2
- package/dist/client/vue.d.ts +3 -2
- package/dist/client/vue.js +239 -63
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs +236 -64
- package/dist/client/vue.mjs.map +1 -1
- package/dist/index-CQr9q0bF.d.mts +295 -0
- package/dist/index-nE_7Io0I.d.ts +295 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +237 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -59
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.js +15 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +15 -4
- package/dist/server/index.mjs.map +1 -1
- package/package.json +13 -11
- package/src/adapters/langchain-adapter.ts +1 -1
- package/src/client/core/app-host.ts +252 -65
- package/src/client/core/constants.ts +30 -0
- package/src/client/index.ts +6 -1
- package/src/client/react/index.ts +1 -0
- package/src/client/react/use-app-host.ts +8 -15
- package/src/client/react/use-mcp-apps.tsx +221 -26
- package/src/client/react/use-mcp.ts +23 -12
- package/src/client/utils/app-host-utils.ts +62 -0
- package/src/client/vue/use-mcp.ts +23 -12
- package/src/server/mcp/oauth-client.ts +31 -8
package/dist/index.mjs
CHANGED
|
@@ -1725,13 +1725,24 @@ var MCPClient = class _MCPClient {
|
|
|
1725
1725
|
}
|
|
1726
1726
|
} catch (error) {
|
|
1727
1727
|
if (error instanceof UnauthorizedError$1 || error instanceof Error && error.message.toLowerCase().includes("unauthorized")) {
|
|
1728
|
-
this.emitStateChange("AUTHENTICATING");
|
|
1729
|
-
console.log(`[MCPClient] Saving session ${this.sessionId} with 10min TTL (OAuth pending)`);
|
|
1730
|
-
await this.saveSession(Math.floor(STATE_EXPIRATION_MS / 1e3), false);
|
|
1731
1728
|
let authUrl = "";
|
|
1732
1729
|
if (this.oauthProvider) {
|
|
1733
|
-
authUrl = this.oauthProvider.authUrl || "";
|
|
1730
|
+
authUrl = (this.oauthProvider.authUrl || "").trim();
|
|
1734
1731
|
}
|
|
1732
|
+
if (!authUrl) {
|
|
1733
|
+
const detail = error instanceof Error && error.message.trim().length > 0 ? error.message.trim() : "Unauthorized";
|
|
1734
|
+
const message = detail.toLowerCase() === "unauthorized" ? "OAuth authorization URL not available" : `OAuth authorization URL not available: ${detail}`;
|
|
1735
|
+
this.emitError(message, "auth");
|
|
1736
|
+
this.emitStateChange("FAILED");
|
|
1737
|
+
try {
|
|
1738
|
+
await storage.removeSession(this.identity, this.sessionId);
|
|
1739
|
+
} catch {
|
|
1740
|
+
}
|
|
1741
|
+
throw new Error(message);
|
|
1742
|
+
}
|
|
1743
|
+
this.emitStateChange("AUTHENTICATING");
|
|
1744
|
+
console.log(`[MCPClient] Saving session ${this.sessionId} with 10min TTL (OAuth pending)`);
|
|
1745
|
+
await this.saveSession(Math.floor(STATE_EXPIRATION_MS / 1e3), false);
|
|
1735
1746
|
if (this.serverId) {
|
|
1736
1747
|
this._onConnectionEvent.fire({
|
|
1737
1748
|
type: "auth_required",
|
|
@@ -3269,22 +3280,88 @@ var SSEClient = class {
|
|
|
3269
3280
|
}
|
|
3270
3281
|
}
|
|
3271
3282
|
};
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
"
|
|
3281
|
-
|
|
3282
|
-
"
|
|
3283
|
-
|
|
3284
|
-
"
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3283
|
+
|
|
3284
|
+
// src/client/core/constants.ts
|
|
3285
|
+
var SANDBOX_PROXY_READY_METHOD = "ui/notifications/sandbox-proxy-ready";
|
|
3286
|
+
var SANDBOX_RESOURCE_READY_METHOD = "ui/notifications/sandbox-resource-ready";
|
|
3287
|
+
var APP_HOST_DEFAULTS = {
|
|
3288
|
+
/** Default timeout for waiting for the sandbox proxy to be ready (ms). */
|
|
3289
|
+
SANDBOX_TIMEOUT_MS: 1e4,
|
|
3290
|
+
/** Default host info reported to guest apps. */
|
|
3291
|
+
HOST_INFO: { name: "mcp-ts-host", version: "1.0.0" },
|
|
3292
|
+
/** Supported MCP App URI schemes. */
|
|
3293
|
+
URI_SCHEMES: ["ui://", "mcp-app://"],
|
|
3294
|
+
/** Default theme for the host context. */
|
|
3295
|
+
THEME: "dark",
|
|
3296
|
+
/** Default platform for the host context. */
|
|
3297
|
+
PLATFORM: "web",
|
|
3298
|
+
/** Default max height for the iframe container (px). */
|
|
3299
|
+
MAX_HEIGHT: 6e3
|
|
3300
|
+
};
|
|
3301
|
+
|
|
3302
|
+
// src/client/utils/app-host-utils.ts
|
|
3303
|
+
var DEFAULT_SANDBOX_TIMEOUT_MS = APP_HOST_DEFAULTS.SANDBOX_TIMEOUT_MS;
|
|
3304
|
+
async function setupSandboxProxyIframe(iframe, sandboxProxyUrl) {
|
|
3305
|
+
iframe.style.width = "100%";
|
|
3306
|
+
iframe.style.height = "100%";
|
|
3307
|
+
iframe.style.border = "none";
|
|
3308
|
+
iframe.style.backgroundColor = "transparent";
|
|
3309
|
+
iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-modals allow-popups allow-downloads");
|
|
3310
|
+
const onReady = new Promise((resolve, reject) => {
|
|
3311
|
+
let settled = false;
|
|
3312
|
+
const cleanup = () => {
|
|
3313
|
+
window.removeEventListener("message", messageListener);
|
|
3314
|
+
iframe.removeEventListener("error", errorListener);
|
|
3315
|
+
};
|
|
3316
|
+
const timeoutId = setTimeout(() => {
|
|
3317
|
+
if (!settled) {
|
|
3318
|
+
settled = true;
|
|
3319
|
+
cleanup();
|
|
3320
|
+
reject(new Error("Timed out waiting for sandbox proxy iframe to be ready"));
|
|
3321
|
+
}
|
|
3322
|
+
}, DEFAULT_SANDBOX_TIMEOUT_MS);
|
|
3323
|
+
const messageListener = (event) => {
|
|
3324
|
+
if (event.source === iframe.contentWindow) {
|
|
3325
|
+
if (event.data?.method === SANDBOX_PROXY_READY_METHOD) {
|
|
3326
|
+
if (!settled) {
|
|
3327
|
+
settled = true;
|
|
3328
|
+
clearTimeout(timeoutId);
|
|
3329
|
+
cleanup();
|
|
3330
|
+
resolve();
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
};
|
|
3335
|
+
const errorListener = () => {
|
|
3336
|
+
if (!settled) {
|
|
3337
|
+
settled = true;
|
|
3338
|
+
clearTimeout(timeoutId);
|
|
3339
|
+
cleanup();
|
|
3340
|
+
reject(new Error("Failed to load sandbox proxy iframe"));
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
window.addEventListener("message", messageListener);
|
|
3344
|
+
iframe.addEventListener("error", errorListener);
|
|
3345
|
+
});
|
|
3346
|
+
iframe.src = sandboxProxyUrl.href;
|
|
3347
|
+
return { onReady };
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3350
|
+
// src/client/core/app-host.ts
|
|
3351
|
+
var DEFAULT_MCP_APP_CSP = {
|
|
3352
|
+
"default-src": "'self'",
|
|
3353
|
+
"script-src": "'self' 'unsafe-inline' 'unsafe-eval' https: blob:",
|
|
3354
|
+
"style-src": "'self' 'unsafe-inline' https:",
|
|
3355
|
+
"connect-src": "'self' https: wss:",
|
|
3356
|
+
"img-src": "'self' data: https: blob:",
|
|
3357
|
+
"font-src": "'self' data: https:",
|
|
3358
|
+
"media-src": "'self' https: blob:",
|
|
3359
|
+
"frame-src": "'none'",
|
|
3360
|
+
"object-src": "'none'",
|
|
3361
|
+
"base-uri": "'self'"
|
|
3362
|
+
};
|
|
3363
|
+
var HOST_INFO = APP_HOST_DEFAULTS.HOST_INFO;
|
|
3364
|
+
var MCP_URI_SCHEMES = APP_HOST_DEFAULTS.URI_SCHEMES;
|
|
3288
3365
|
var AppHost = class {
|
|
3289
3366
|
constructor(client, iframe, options) {
|
|
3290
3367
|
this.client = client;
|
|
@@ -3293,10 +3370,12 @@ var AppHost = class {
|
|
|
3293
3370
|
__publicField(this, "sessionId");
|
|
3294
3371
|
__publicField(this, "resourceCache", /* @__PURE__ */ new Map());
|
|
3295
3372
|
__publicField(this, "debug");
|
|
3296
|
-
|
|
3373
|
+
__publicField(this, "sandboxConfig");
|
|
3374
|
+
__publicField(this, "options");
|
|
3297
3375
|
__publicField(this, "onAppMessage");
|
|
3298
|
-
this.
|
|
3299
|
-
this.
|
|
3376
|
+
this.options = options || {};
|
|
3377
|
+
this.debug = this.options.debug ?? false;
|
|
3378
|
+
this.sandboxConfig = this.options.sandbox;
|
|
3300
3379
|
this.bridge = this.initializeBridge();
|
|
3301
3380
|
}
|
|
3302
3381
|
// ============================================
|
|
@@ -3323,19 +3402,35 @@ var AppHost = class {
|
|
|
3323
3402
|
}
|
|
3324
3403
|
}
|
|
3325
3404
|
/**
|
|
3326
|
-
* Launch an MCP App from a URL
|
|
3405
|
+
* Launch an MCP App from a URL, MCP resource URI, or RAW HTML.
|
|
3327
3406
|
* Loads the HTML first, then establishes bridge connection.
|
|
3328
3407
|
*/
|
|
3329
|
-
async launch(
|
|
3408
|
+
async launch(source, sessionId) {
|
|
3330
3409
|
if (sessionId) this.sessionId = sessionId;
|
|
3331
3410
|
const initializedPromise = this.onAppReady();
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3411
|
+
let htmlToRender = source.html;
|
|
3412
|
+
if (!htmlToRender && source.uri) {
|
|
3413
|
+
if (this.isMcpUri(source.uri)) {
|
|
3414
|
+
htmlToRender = await this.readMcpAppHtml(source.uri);
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
if (!htmlToRender && source.uri && !this.isMcpUri(source.uri)) {
|
|
3418
|
+
this.iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-modals allow-popups allow-downloads");
|
|
3419
|
+
this.iframe.src = source.uri;
|
|
3420
|
+
await this.onIframeReady();
|
|
3421
|
+
await this.connectBridge();
|
|
3422
|
+
} else if (htmlToRender) {
|
|
3423
|
+
if (!this.sandboxConfig) {
|
|
3424
|
+
throw new Error("Sandbox configuration requires a proxy URL to render HTML safely.");
|
|
3425
|
+
}
|
|
3426
|
+
await this.launchSandboxedHtml(htmlToRender, this.sandboxConfig);
|
|
3427
|
+
await this.connectBridge();
|
|
3428
|
+
this.log("Sending HTML resource to sandbox proxy (MCP Apps notification)");
|
|
3429
|
+
await this.bridge.sendSandboxResourceReady({
|
|
3430
|
+
html: htmlToRender,
|
|
3431
|
+
csp: this.sandboxConfig.csp
|
|
3432
|
+
});
|
|
3336
3433
|
}
|
|
3337
|
-
await this.onIframeReady();
|
|
3338
|
-
await this.connectBridge();
|
|
3339
3434
|
this.log("Waiting for app initialization");
|
|
3340
3435
|
await Promise.race([
|
|
3341
3436
|
initializedPromise,
|
|
@@ -3346,6 +3441,19 @@ var AppHost = class {
|
|
|
3346
3441
|
]);
|
|
3347
3442
|
this.log("App launched and ready");
|
|
3348
3443
|
}
|
|
3444
|
+
// Set host context manually
|
|
3445
|
+
setHostContext(context) {
|
|
3446
|
+
this.options.hostContext = context;
|
|
3447
|
+
if (this.bridge) {
|
|
3448
|
+
this.bridge.setHostContext(context);
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
// Send streaming inputs manually
|
|
3452
|
+
sendToolInputPartial(params) {
|
|
3453
|
+
if (this.bridge) {
|
|
3454
|
+
this.bridge.sendToolInputPartial(params);
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3349
3457
|
/**
|
|
3350
3458
|
* Wait for app to signal initialization complete
|
|
3351
3459
|
*/
|
|
@@ -3396,14 +3504,17 @@ var AppHost = class {
|
|
|
3396
3504
|
this.log("Sending tool cancellation to app");
|
|
3397
3505
|
this.bridge.sendToolCancelled({ reason });
|
|
3398
3506
|
}
|
|
3507
|
+
/**
|
|
3508
|
+
* Tell the guest UI the resource is being torn down (unload / cleanup).
|
|
3509
|
+
* Forwards to {@link AppBridge.teardownResource} on `@modelcontextprotocol/ext-apps/app-bridge`.
|
|
3510
|
+
*/
|
|
3511
|
+
teardownResource(params = {}) {
|
|
3512
|
+
this.log("Sending resource teardown to app");
|
|
3513
|
+
this.bridge.teardownResource(params);
|
|
3514
|
+
}
|
|
3399
3515
|
// ============================================
|
|
3400
3516
|
// Private: Initialization
|
|
3401
3517
|
// ============================================
|
|
3402
|
-
configureSandbox() {
|
|
3403
|
-
if (this.iframe.sandbox.value !== SANDBOX_PERMISSIONS) {
|
|
3404
|
-
this.iframe.sandbox.value = SANDBOX_PERMISSIONS;
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
3518
|
initializeBridge() {
|
|
3408
3519
|
const bridge = new AppBridge(
|
|
3409
3520
|
null,
|
|
@@ -3412,12 +3523,10 @@ var AppHost = class {
|
|
|
3412
3523
|
openLinks: {},
|
|
3413
3524
|
serverTools: {},
|
|
3414
3525
|
logging: {},
|
|
3415
|
-
// Declare support for model context updates
|
|
3416
3526
|
updateModelContext: { text: {} }
|
|
3417
3527
|
},
|
|
3418
3528
|
{
|
|
3419
|
-
|
|
3420
|
-
hostContext: {
|
|
3529
|
+
hostContext: this.options.hostContext || {
|
|
3421
3530
|
theme: "dark",
|
|
3422
3531
|
platform: "web",
|
|
3423
3532
|
containerDimensions: { maxHeight: 6e3 },
|
|
@@ -3426,19 +3535,56 @@ var AppHost = class {
|
|
|
3426
3535
|
}
|
|
3427
3536
|
}
|
|
3428
3537
|
);
|
|
3538
|
+
bridge.fallbackRequestHandler = this.options.onFallbackRequest;
|
|
3429
3539
|
bridge.oncalltool = (params) => this.handleToolCall(params);
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3540
|
+
if (this.options.onReadResource) {
|
|
3541
|
+
bridge.onreadresource = async (params) => {
|
|
3542
|
+
const resp = await this.options.onReadResource(params.uri);
|
|
3543
|
+
return {
|
|
3544
|
+
contents: resp.contents.map((c) => ({
|
|
3545
|
+
uri: params.uri,
|
|
3546
|
+
text: c.text,
|
|
3547
|
+
blob: c.blob
|
|
3548
|
+
}))
|
|
3549
|
+
};
|
|
3550
|
+
};
|
|
3551
|
+
}
|
|
3552
|
+
bridge.onopenlink = async (params, extra) => {
|
|
3553
|
+
if (this.options.onOpenLink) {
|
|
3554
|
+
return await this.options.onOpenLink(params, extra);
|
|
3555
|
+
}
|
|
3556
|
+
return this.handleOpenLink(params);
|
|
3557
|
+
};
|
|
3558
|
+
bridge.onmessage = async (params, extra) => {
|
|
3559
|
+
if (this.options.onMessage) {
|
|
3560
|
+
return await this.options.onMessage(params, extra);
|
|
3561
|
+
}
|
|
3562
|
+
return this.handleMessage(params);
|
|
3563
|
+
};
|
|
3564
|
+
bridge.onloggingmessage = (params) => {
|
|
3565
|
+
this.log(`App log [${params.level}]: ${params.data}`);
|
|
3566
|
+
if (this.options.onLoggingMessage) {
|
|
3567
|
+
this.options.onLoggingMessage(params);
|
|
3568
|
+
}
|
|
3569
|
+
};
|
|
3433
3570
|
bridge.onupdatemodelcontext = async () => ({});
|
|
3434
|
-
bridge.onsizechange = async (
|
|
3435
|
-
|
|
3436
|
-
if (
|
|
3571
|
+
bridge.onsizechange = async (params) => {
|
|
3572
|
+
const { width, height } = params;
|
|
3573
|
+
if (height !== void 0 && height > 0) {
|
|
3574
|
+
this.iframe.style.height = `${height}px`;
|
|
3575
|
+
}
|
|
3576
|
+
if (width !== void 0 && width > 0) this.iframe.style.minWidth = `min(${width}px, 100%)`;
|
|
3577
|
+
if (this.options.onSizeChanged) {
|
|
3578
|
+
this.options.onSizeChanged(params);
|
|
3579
|
+
}
|
|
3437
3580
|
return {};
|
|
3438
3581
|
};
|
|
3439
|
-
bridge.onrequestdisplaymode = async (params) =>
|
|
3440
|
-
|
|
3441
|
-
|
|
3582
|
+
bridge.onrequestdisplaymode = async (params, extra) => {
|
|
3583
|
+
if (this.options.onRequestDisplayMode) {
|
|
3584
|
+
return await this.options.onRequestDisplayMode(params, extra);
|
|
3585
|
+
}
|
|
3586
|
+
return { mode: params.mode === "fullscreen" ? "fullscreen" : "inline" };
|
|
3587
|
+
};
|
|
3442
3588
|
return bridge;
|
|
3443
3589
|
}
|
|
3444
3590
|
async connectBridge() {
|
|
@@ -3452,6 +3598,9 @@ var AppHost = class {
|
|
|
3452
3598
|
this.log("Bridge connected successfully");
|
|
3453
3599
|
} catch (error) {
|
|
3454
3600
|
this.log("Bridge connection failed", "error");
|
|
3601
|
+
if (this.options.onError) {
|
|
3602
|
+
this.options.onError(error instanceof Error ? error : new Error(String(error)));
|
|
3603
|
+
}
|
|
3455
3604
|
throw error;
|
|
3456
3605
|
}
|
|
3457
3606
|
}
|
|
@@ -3459,8 +3608,11 @@ var AppHost = class {
|
|
|
3459
3608
|
// Private: Bridge Event Handlers
|
|
3460
3609
|
// ============================================
|
|
3461
3610
|
async handleToolCall(params) {
|
|
3462
|
-
if (
|
|
3463
|
-
|
|
3611
|
+
if (this.options.onCallTool) {
|
|
3612
|
+
return await this.options.onCallTool(params);
|
|
3613
|
+
}
|
|
3614
|
+
if (!this.client || !this.client.isConnected()) {
|
|
3615
|
+
throw new Error("Client disconnected or not provided");
|
|
3464
3616
|
}
|
|
3465
3617
|
const sessionId = await this.getSessionId();
|
|
3466
3618
|
if (!sessionId) {
|
|
@@ -3484,13 +3636,19 @@ var AppHost = class {
|
|
|
3484
3636
|
// ============================================
|
|
3485
3637
|
// Private: Resource Loading
|
|
3486
3638
|
// ============================================
|
|
3487
|
-
async
|
|
3488
|
-
|
|
3489
|
-
|
|
3639
|
+
async launchSandboxedHtml(html, config) {
|
|
3640
|
+
const sandboxUrlString = config.url instanceof URL ? config.url.href : config.url;
|
|
3641
|
+
const url = new URL(sandboxUrlString, globalThis.location?.href);
|
|
3642
|
+
if (config.csp && Object.keys(config.csp).length > 0) {
|
|
3643
|
+
url.searchParams.set("csp", JSON.stringify(config.csp));
|
|
3490
3644
|
}
|
|
3645
|
+
const { onReady } = await setupSandboxProxyIframe(this.iframe, url);
|
|
3646
|
+
await onReady;
|
|
3647
|
+
}
|
|
3648
|
+
async readMcpAppHtml(uri) {
|
|
3491
3649
|
const sessionId = await this.getSessionId();
|
|
3492
|
-
if (!sessionId) {
|
|
3493
|
-
throw new Error("No active session");
|
|
3650
|
+
if (!sessionId && !this.options.onReadResource) {
|
|
3651
|
+
throw new Error("No active session.");
|
|
3494
3652
|
}
|
|
3495
3653
|
const response = await this.fetchResourceWithCache(sessionId, uri);
|
|
3496
3654
|
if (!response?.contents?.length) {
|
|
@@ -3501,10 +3659,18 @@ var AppHost = class {
|
|
|
3501
3659
|
if (!html) {
|
|
3502
3660
|
throw new Error(`Invalid content in resource: ${uri}`);
|
|
3503
3661
|
}
|
|
3504
|
-
|
|
3505
|
-
this.iframe.src = URL.createObjectURL(blob);
|
|
3662
|
+
return html;
|
|
3506
3663
|
}
|
|
3507
3664
|
async fetchResourceWithCache(sessionId, uri) {
|
|
3665
|
+
if (this.options.onReadResource) {
|
|
3666
|
+
return await this.options.onReadResource(uri);
|
|
3667
|
+
}
|
|
3668
|
+
if (!sessionId) {
|
|
3669
|
+
throw new Error("No active session");
|
|
3670
|
+
}
|
|
3671
|
+
if (!this.client) {
|
|
3672
|
+
throw new Error("No client to read resource from");
|
|
3673
|
+
}
|
|
3508
3674
|
if (this.hasClientCache()) {
|
|
3509
3675
|
return this.client.getOrFetchResource(sessionId, uri);
|
|
3510
3676
|
}
|
|
@@ -3517,8 +3683,11 @@ var AppHost = class {
|
|
|
3517
3683
|
}
|
|
3518
3684
|
async preloadResource(uri) {
|
|
3519
3685
|
try {
|
|
3686
|
+
if (this.options.onReadResource) {
|
|
3687
|
+
return await this.options.onReadResource(uri);
|
|
3688
|
+
}
|
|
3520
3689
|
const sessionId = await this.getSessionId();
|
|
3521
|
-
if (!sessionId) return null;
|
|
3690
|
+
if (!sessionId || !this.client) return null;
|
|
3522
3691
|
return await this.client.readResource(sessionId, uri);
|
|
3523
3692
|
} catch (error) {
|
|
3524
3693
|
this.log(`Preload failed for ${uri}`, "warn");
|
|
@@ -3530,6 +3699,7 @@ var AppHost = class {
|
|
|
3530
3699
|
// ============================================
|
|
3531
3700
|
async getSessionId() {
|
|
3532
3701
|
if (this.sessionId) return this.sessionId;
|
|
3702
|
+
if (!this.client) return void 0;
|
|
3533
3703
|
const result = await this.client.getSessions();
|
|
3534
3704
|
return result.sessions?.[0]?.sessionId;
|
|
3535
3705
|
}
|
|
@@ -3537,6 +3707,7 @@ var AppHost = class {
|
|
|
3537
3707
|
return MCP_URI_SCHEMES.some((scheme) => url.startsWith(scheme));
|
|
3538
3708
|
}
|
|
3539
3709
|
hasClientCache() {
|
|
3710
|
+
if (!this.client) return false;
|
|
3540
3711
|
return "getOrFetchResource" in this.client && typeof this.client.getOrFetchResource === "function";
|
|
3541
3712
|
}
|
|
3542
3713
|
extractUiResourceUri(tool) {
|
|
@@ -3600,6 +3771,6 @@ function findToolByName(connections, toolName) {
|
|
|
3600
3771
|
return void 0;
|
|
3601
3772
|
}
|
|
3602
3773
|
|
|
3603
|
-
export { AppHost, AuthenticationError, ConfigurationError, ConnectionError, DEFAULT_CLIENT_NAME, DEFAULT_CLIENT_URI, DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_LOGO_URI, DEFAULT_POLICY_URI, DisposableStore, Emitter, InvalidStateError, MCPClient, MCP_CLIENT_NAME, MCP_CLIENT_VERSION, McpError, MultiSessionClient, NotConnectedError, REDIS_KEY_PREFIX, RpcErrorCodes, SESSION_TTL_SECONDS, SOFTWARE_ID, SOFTWARE_VERSION, SSEClient, SSEConnectionManager, STATE_EXPIRATION_MS, SessionNotFoundError, SessionValidationError, StorageOAuthClientProvider, TOKEN_EXPIRY_BUFFER_MS, ToolExecutionError, UnauthorizedError, createNextMcpHandler, createSSEHandler, findToolByName, getToolUiResourceUri, isCallToolSuccess, isConnectAuthRequired, isConnectError, isConnectSuccess, isListToolsSuccess, sanitizeServerLabel, storage };
|
|
3774
|
+
export { APP_HOST_DEFAULTS, AppHost, AuthenticationError, ConfigurationError, ConnectionError, DEFAULT_CLIENT_NAME, DEFAULT_CLIENT_URI, DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_LOGO_URI, DEFAULT_MCP_APP_CSP, DEFAULT_POLICY_URI, DisposableStore, Emitter, InvalidStateError, MCPClient, MCP_CLIENT_NAME, MCP_CLIENT_VERSION, McpError, MultiSessionClient, NotConnectedError, REDIS_KEY_PREFIX, RpcErrorCodes, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SESSION_TTL_SECONDS, SOFTWARE_ID, SOFTWARE_VERSION, SSEClient, SSEConnectionManager, STATE_EXPIRATION_MS, SessionNotFoundError, SessionValidationError, StorageOAuthClientProvider, TOKEN_EXPIRY_BUFFER_MS, ToolExecutionError, UnauthorizedError, createNextMcpHandler, createSSEHandler, findToolByName, getToolUiResourceUri, isCallToolSuccess, isConnectAuthRequired, isConnectError, isConnectSuccess, isListToolsSuccess, sanitizeServerLabel, storage };
|
|
3604
3775
|
//# sourceMappingURL=index.mjs.map
|
|
3605
3776
|
//# sourceMappingURL=index.mjs.map
|