@mcp-use/client 2.0.1 → 2.0.2-canary.1
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/.tsbuildinfo +1 -1
- package/dist/core/session.d.ts +2 -2
- package/dist/core/session.d.ts.map +1 -1
- package/dist/index-browser.js +3 -3
- package/dist/index-browser.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/react/index.js +187 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/view/inject-openai-file-apis.d.ts +5 -2
- package/dist/react/view/inject-openai-file-apis.d.ts.map +1 -1
- package/dist/transport/base.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -1606,7 +1606,7 @@ var HttpConnector = class extends BaseConnector {
|
|
|
1606
1606
|
};
|
|
1607
1607
|
|
|
1608
1608
|
// src/utils/version.ts
|
|
1609
|
-
var VERSION = "2.0.1";
|
|
1609
|
+
var VERSION = "2.0.2-canary.1";
|
|
1610
1610
|
function getPackageVersion() {
|
|
1611
1611
|
return VERSION;
|
|
1612
1612
|
}
|
|
@@ -3491,7 +3491,7 @@ var MCPConnection = class {
|
|
|
3491
3491
|
const protocolEra = this.protocolEra;
|
|
3492
3492
|
const protocolVersion = this.negotiatedProtocolVersion;
|
|
3493
3493
|
const server = this.serverInfo;
|
|
3494
|
-
if (!protocolEra || !protocolVersion
|
|
3494
|
+
if (!protocolEra || !protocolVersion) {
|
|
3495
3495
|
throw new Error("MCP connection is not initialized");
|
|
3496
3496
|
}
|
|
3497
3497
|
const capabilities = this.serverCapabilities;
|
|
@@ -3499,7 +3499,7 @@ var MCPConnection = class {
|
|
|
3499
3499
|
return {
|
|
3500
3500
|
protocolEra,
|
|
3501
3501
|
protocolVersion,
|
|
3502
|
-
server,
|
|
3502
|
+
...server ? { server } : {},
|
|
3503
3503
|
capabilities,
|
|
3504
3504
|
instructions: this.connector.instructions,
|
|
3505
3505
|
extensions
|
|
@@ -7331,35 +7331,211 @@ function parseCustomProps(customProps) {
|
|
|
7331
7331
|
}
|
|
7332
7332
|
|
|
7333
7333
|
// src/react/view/inject-openai-file-apis.ts
|
|
7334
|
-
|
|
7334
|
+
import { LATEST_PROTOCOL_VERSION } from "@modelcontextprotocol/ext-apps/app-bridge";
|
|
7335
|
+
var OPENAI_COMPATIBILITY_BRIDGE_SCRIPT = `<script>
|
|
7335
7336
|
(function () {
|
|
7336
7337
|
var files = new Map();
|
|
7337
|
-
|
|
7338
|
-
|
|
7338
|
+
var pendingRequests = new Map();
|
|
7339
|
+
var requestId = 0;
|
|
7340
|
+
var hostConnected = false;
|
|
7341
|
+
var fallbackTimer;
|
|
7342
|
+
var api = window.openai || {};
|
|
7343
|
+
|
|
7344
|
+
function dispatchGlobals(globals) {
|
|
7345
|
+
Object.assign(api, globals);
|
|
7346
|
+
window.dispatchEvent(new CustomEvent("openai:set_globals", {
|
|
7347
|
+
detail: { globals: globals }
|
|
7348
|
+
}));
|
|
7349
|
+
}
|
|
7350
|
+
|
|
7351
|
+
function applyHostContext(context) {
|
|
7352
|
+
if (!context || typeof context !== "object") return;
|
|
7353
|
+
var globals = {};
|
|
7354
|
+
if (context.theme !== undefined) globals.theme = context.theme;
|
|
7355
|
+
if (context.displayMode !== undefined) globals.displayMode = context.displayMode;
|
|
7356
|
+
if (context.locale !== undefined) globals.locale = context.locale;
|
|
7357
|
+
if (context.view !== undefined) globals.view = context.view;
|
|
7358
|
+
if (context.safeAreaInsets !== undefined) {
|
|
7359
|
+
globals.safeArea = { insets: context.safeAreaInsets };
|
|
7360
|
+
}
|
|
7361
|
+
if (context.containerDimensions && context.containerDimensions.maxHeight !== undefined) {
|
|
7362
|
+
globals.maxHeight = context.containerDimensions.maxHeight;
|
|
7363
|
+
}
|
|
7364
|
+
if (context.platform !== undefined || context.deviceCapabilities !== undefined) {
|
|
7365
|
+
globals.userAgent = {
|
|
7366
|
+
device: {
|
|
7367
|
+
type: context.platform === "mobile" ? "mobile" : "desktop"
|
|
7368
|
+
},
|
|
7369
|
+
capabilities: {
|
|
7370
|
+
hover: !!(context.deviceCapabilities && context.deviceCapabilities.hover),
|
|
7371
|
+
touch: !!(context.deviceCapabilities && context.deviceCapabilities.touch)
|
|
7372
|
+
}
|
|
7373
|
+
};
|
|
7374
|
+
}
|
|
7375
|
+
dispatchGlobals(globals);
|
|
7376
|
+
}
|
|
7377
|
+
|
|
7378
|
+
function markHostConnected(result) {
|
|
7379
|
+
hostConnected = true;
|
|
7380
|
+
clearTimeout(fallbackTimer);
|
|
7381
|
+
if (result && result.hostContext) applyHostContext(result.hostContext);
|
|
7382
|
+
}
|
|
7383
|
+
|
|
7384
|
+
function postMessage(message) {
|
|
7385
|
+
if (window.parent === window) {
|
|
7386
|
+
throw new Error("window.openai compatibility APIs require an iframe host");
|
|
7387
|
+
}
|
|
7388
|
+
window.parent.postMessage(message, "*");
|
|
7389
|
+
}
|
|
7390
|
+
|
|
7391
|
+
function sendRequest(method, params) {
|
|
7392
|
+
var id = "mcp-use-openai-compat-" + (++requestId);
|
|
7393
|
+
return new Promise(function (resolve, reject) {
|
|
7394
|
+
pendingRequests.set(id, { resolve: resolve, reject: reject });
|
|
7395
|
+
postMessage({ jsonrpc: "2.0", id: id, method: method, params: params });
|
|
7396
|
+
window.setTimeout(function () {
|
|
7397
|
+
var pending = pendingRequests.get(id);
|
|
7398
|
+
if (!pending) return;
|
|
7399
|
+
pendingRequests.delete(id);
|
|
7400
|
+
pending.reject(new Error("Request timeout: " + method));
|
|
7401
|
+
}, 30000);
|
|
7402
|
+
});
|
|
7403
|
+
}
|
|
7404
|
+
|
|
7405
|
+
function sendNotification(method, params) {
|
|
7406
|
+
postMessage({ jsonrpc: "2.0", method: method, params: params });
|
|
7407
|
+
}
|
|
7408
|
+
|
|
7409
|
+
window.addEventListener("message", function (event) {
|
|
7410
|
+
if (event.source !== window.parent) return;
|
|
7411
|
+
var message = event.data;
|
|
7412
|
+
if (!message || message.jsonrpc !== "2.0") return;
|
|
7413
|
+
|
|
7414
|
+
if (message.id !== undefined && (message.result !== undefined || message.error !== undefined)) {
|
|
7415
|
+
var pending = pendingRequests.get(message.id);
|
|
7416
|
+
if (pending) {
|
|
7417
|
+
pendingRequests.delete(message.id);
|
|
7418
|
+
if (message.error) pending.reject(new Error(message.error.message || "Host request failed"));
|
|
7419
|
+
else pending.resolve(message.result);
|
|
7420
|
+
return;
|
|
7421
|
+
}
|
|
7422
|
+
if (message.result && (message.result.hostInfo || message.result.hostContext)) {
|
|
7423
|
+
markHostConnected(message.result);
|
|
7424
|
+
}
|
|
7425
|
+
return;
|
|
7426
|
+
}
|
|
7427
|
+
|
|
7428
|
+
if (message.id !== undefined || typeof message.method !== "string") return;
|
|
7429
|
+
var params = message.params || {};
|
|
7430
|
+
switch (message.method) {
|
|
7431
|
+
case "ui/notifications/tool-input":
|
|
7432
|
+
markHostConnected();
|
|
7433
|
+
dispatchGlobals({ toolInput: params.arguments || {} });
|
|
7434
|
+
break;
|
|
7435
|
+
case "ui/notifications/tool-input-partial":
|
|
7436
|
+
// window.openai has no partial-input global. Do not expose incomplete
|
|
7437
|
+
// or approval-gated arguments as if the final tool input had arrived.
|
|
7438
|
+
markHostConnected();
|
|
7439
|
+
break;
|
|
7440
|
+
case "ui/notifications/tool-result":
|
|
7441
|
+
markHostConnected();
|
|
7442
|
+
dispatchGlobals({
|
|
7443
|
+
// OpenAI defines toolOutput as structuredContent, not the complete
|
|
7444
|
+
// CallToolResult envelope. Keep that envelope (including hidden
|
|
7445
|
+
// _meta) in toolResponseMetadata instead.
|
|
7446
|
+
toolOutput: params.structuredContent === undefined ? null : params.structuredContent,
|
|
7447
|
+
toolResponseMetadata: params
|
|
7448
|
+
});
|
|
7449
|
+
break;
|
|
7450
|
+
case "ui/notifications/host-context-changed":
|
|
7451
|
+
markHostConnected();
|
|
7452
|
+
applyHostContext(params);
|
|
7453
|
+
break;
|
|
7454
|
+
}
|
|
7455
|
+
});
|
|
7456
|
+
|
|
7457
|
+
api.toolInput = api.toolInput === undefined ? null : api.toolInput;
|
|
7458
|
+
api.toolOutput = api.toolOutput === undefined ? null : api.toolOutput;
|
|
7459
|
+
api.toolResponseMetadata =
|
|
7460
|
+
api.toolResponseMetadata === undefined ? null : api.toolResponseMetadata;
|
|
7461
|
+
api.widgetState = api.widgetState === undefined ? null : api.widgetState;
|
|
7462
|
+
api.theme = api.theme || "light";
|
|
7463
|
+
api.displayMode = api.displayMode || "inline";
|
|
7464
|
+
api.safeArea = api.safeArea || {
|
|
7465
|
+
insets: { top: 0, right: 0, bottom: 0, left: 0 }
|
|
7466
|
+
};
|
|
7467
|
+
api.maxHeight = api.maxHeight || 600;
|
|
7468
|
+
api.userAgent = api.userAgent || {
|
|
7469
|
+
device: { type: "desktop" },
|
|
7470
|
+
capabilities: { hover: true, touch: false }
|
|
7471
|
+
};
|
|
7472
|
+
api.locale = api.locale || "en";
|
|
7473
|
+
|
|
7474
|
+
api.callTool = api.callTool || function (name, args) {
|
|
7475
|
+
return sendRequest("tools/call", { name: name, arguments: args || {} });
|
|
7476
|
+
};
|
|
7477
|
+
api.sendFollowUpMessage = api.sendFollowUpMessage || function (request) {
|
|
7478
|
+
return sendRequest("ui/message", {
|
|
7479
|
+
role: "user",
|
|
7480
|
+
content: [{ type: "text", text: request.prompt }]
|
|
7481
|
+
});
|
|
7482
|
+
};
|
|
7483
|
+
api.openExternal = api.openExternal || function (request) {
|
|
7484
|
+
return sendRequest("ui/open-link", { url: request.href });
|
|
7485
|
+
};
|
|
7486
|
+
api.requestDisplayMode = api.requestDisplayMode || function (request) {
|
|
7487
|
+
return sendRequest("ui/request-display-mode", { mode: request.mode });
|
|
7488
|
+
};
|
|
7489
|
+
api.setWidgetState = api.setWidgetState || function (state) {
|
|
7490
|
+
dispatchGlobals({ widgetState: state });
|
|
7491
|
+
};
|
|
7492
|
+
api.notifyIntrinsicHeight = api.notifyIntrinsicHeight || function (height) {
|
|
7493
|
+
sendNotification("ui/notifications/size-changed", { height: height });
|
|
7494
|
+
return Promise.resolve();
|
|
7495
|
+
};
|
|
7496
|
+
api.uploadFile = api.uploadFile || async function (file) {
|
|
7339
7497
|
var fileId = crypto.randomUUID();
|
|
7340
7498
|
files.set(fileId, file);
|
|
7341
7499
|
return { fileId: fileId };
|
|
7342
7500
|
};
|
|
7343
|
-
|
|
7501
|
+
api.getFileDownloadUrl = api.getFileDownloadUrl || async function (ref) {
|
|
7344
7502
|
var file = files.get(ref.fileId);
|
|
7345
7503
|
if (!file) {
|
|
7346
7504
|
throw new Error("File not found: " + ref.fileId);
|
|
7347
7505
|
}
|
|
7348
7506
|
return { downloadUrl: URL.createObjectURL(file) };
|
|
7349
7507
|
};
|
|
7508
|
+
window.openai = api;
|
|
7509
|
+
|
|
7510
|
+
// Native V2 views initialize their own MCP Apps bridge. Only initialize this
|
|
7511
|
+
// compatibility bridge when no other guest handshake appears, so the file
|
|
7512
|
+
// helpers remain safe for both V2 views and legacy useWidget() bundles.
|
|
7513
|
+
fallbackTimer = window.setTimeout(function () {
|
|
7514
|
+
if (hostConnected) return;
|
|
7515
|
+
sendRequest("ui/initialize", {
|
|
7516
|
+
appCapabilities: {},
|
|
7517
|
+
appInfo: { name: "mcp-use-openai-compat", version: "1.0.0" },
|
|
7518
|
+
protocolVersion: ${JSON.stringify(LATEST_PROTOCOL_VERSION)}
|
|
7519
|
+
}).then(function (result) {
|
|
7520
|
+
markHostConnected(result);
|
|
7521
|
+
sendNotification("ui/notifications/initialized", {});
|
|
7522
|
+
}).catch(function (error) {
|
|
7523
|
+
console.warn("[window.openai compatibility] Failed to initialize:", error);
|
|
7524
|
+
});
|
|
7525
|
+
}, 1000);
|
|
7350
7526
|
})();
|
|
7351
7527
|
</script>`;
|
|
7352
7528
|
function injectOpenAiFileApis(html) {
|
|
7353
7529
|
const headEnd = findOpeningConstructEnd(html, "<head");
|
|
7354
7530
|
if (headEnd !== void 0) {
|
|
7355
|
-
return insertAt(html, headEnd,
|
|
7531
|
+
return insertAt(html, headEnd, OPENAI_COMPATIBILITY_BRIDGE_SCRIPT);
|
|
7356
7532
|
}
|
|
7357
7533
|
const htmlEnd = findOpeningConstructEnd(html, "<html");
|
|
7358
7534
|
if (htmlEnd !== void 0) {
|
|
7359
7535
|
return insertAt(
|
|
7360
7536
|
html,
|
|
7361
7537
|
htmlEnd,
|
|
7362
|
-
"<head>" +
|
|
7538
|
+
"<head>" + OPENAI_COMPATIBILITY_BRIDGE_SCRIPT + "</head>"
|
|
7363
7539
|
);
|
|
7364
7540
|
}
|
|
7365
7541
|
const doctypeEnd = findOpeningConstructEnd(html, "<!doctype");
|
|
@@ -7367,10 +7543,10 @@ function injectOpenAiFileApis(html) {
|
|
|
7367
7543
|
return insertAt(
|
|
7368
7544
|
html,
|
|
7369
7545
|
doctypeEnd,
|
|
7370
|
-
"<head>" +
|
|
7546
|
+
"<head>" + OPENAI_COMPATIBILITY_BRIDGE_SCRIPT + "</head>"
|
|
7371
7547
|
);
|
|
7372
7548
|
}
|
|
7373
|
-
return
|
|
7549
|
+
return OPENAI_COMPATIBILITY_BRIDGE_SCRIPT + html;
|
|
7374
7550
|
}
|
|
7375
7551
|
function findOpeningConstructEnd(html, lowercasePrefix) {
|
|
7376
7552
|
const lowercaseHtml = html.toLowerCase();
|