mcp-use 1.11.0-canary.9 → 1.11.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.
Files changed (51) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-N3DO4P2L.js → chunk-A4QJRN7Z.js} +2 -2
  3. package/dist/{chunk-UCPSHMNO.js → chunk-B7AGEK7F.js} +1 -1
  4. package/dist/{chunk-HU2DGJ5J.js → chunk-GN5HOAV3.js} +491 -5
  5. package/dist/{chunk-D3CNYAYE.js → chunk-QPIDKGV4.js} +199 -8
  6. package/dist/{chunk-ZFZPZ4GE.js → chunk-V77WS6CS.js} +9 -0
  7. package/dist/{chunk-5QFJZ7H3.js → chunk-VRHAF2WT.js} +10 -4
  8. package/dist/{chunk-F3BZFJCD.js → chunk-Y2HHHJQB.js} +10 -5
  9. package/dist/{chunk-Q5LZL6BH.js → chunk-ZLZOOXMJ.js} +96 -43
  10. package/dist/index.cjs +122 -47
  11. package/dist/index.js +15 -19
  12. package/dist/src/agents/index.cjs +108 -44
  13. package/dist/src/agents/index.d.ts +1 -1
  14. package/dist/src/agents/index.d.ts.map +1 -1
  15. package/dist/src/agents/index.js +7 -11
  16. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  17. package/dist/src/{client/prompts.d.ts → agents/prompts/index.d.ts} +3 -3
  18. package/dist/src/agents/prompts/index.d.ts.map +1 -0
  19. package/dist/src/browser.cjs +115 -45
  20. package/dist/src/browser.js +10 -13
  21. package/dist/src/client/browser.d.ts.map +1 -1
  22. package/dist/src/client.cjs +108 -43
  23. package/dist/src/client.d.ts +2 -0
  24. package/dist/src/client.d.ts.map +1 -1
  25. package/dist/src/client.js +6 -5
  26. package/dist/src/config.d.ts.map +1 -1
  27. package/dist/src/connectors/http.d.ts +2 -0
  28. package/dist/src/connectors/http.d.ts.map +1 -1
  29. package/dist/src/react/index.cjs +119 -46
  30. package/dist/src/react/index.js +7 -8
  31. package/dist/src/react/useMcp.d.ts.map +1 -1
  32. package/dist/src/server/index.cjs +178 -113
  33. package/dist/src/server/index.js +92 -80
  34. package/dist/src/server/types/widget.d.ts +2 -2
  35. package/dist/src/server/types/widget.d.ts.map +1 -1
  36. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  37. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
  38. package/dist/src/telemetry/telemetry.d.ts +1 -0
  39. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  40. package/dist/src/version.d.ts +1 -1
  41. package/dist/src/version.d.ts.map +1 -1
  42. package/dist/{tool-execution-helpers-MXVN6YNU.js → tool-execution-helpers-ZUA5D5IO.js} +2 -2
  43. package/package.json +49 -52
  44. package/dist/chunk-ESMOFYJ6.js +0 -2638
  45. package/dist/chunk-M7WATKYM.js +0 -204
  46. package/dist/chunk-OWPXM4QQ.js +0 -12
  47. package/dist/chunk-WW3A2EKQ.js +0 -1055
  48. package/dist/chunk-XEFWIBQF.js +0 -491
  49. package/dist/src/client/prompts.cjs +0 -407
  50. package/dist/src/client/prompts.d.ts.map +0 -1
  51. package/dist/src/client/prompts.js +0 -11
@@ -761,7 +761,7 @@ var VERSION;
761
761
  var init_version = __esm({
762
762
  "src/version.ts"() {
763
763
  "use strict";
764
- VERSION = "1.11.0-canary.9";
764
+ VERSION = "1.11.0";
765
765
  __name(getPackageVersion, "getPackageVersion");
766
766
  }
767
767
  });
@@ -775,6 +775,19 @@ var init_utils = __esm({
775
775
  });
776
776
 
777
777
  // src/telemetry/telemetry.ts
778
+ function secureRandomString() {
779
+ if (typeof window !== "undefined" && window.crypto && typeof window.crypto.getRandomValues === "function") {
780
+ const array2 = new Uint8Array(8);
781
+ window.crypto.getRandomValues(array2);
782
+ return Array.from(array2, (v) => v.toString(16).padStart(2, "0")).join("");
783
+ }
784
+ try {
785
+ const crypto = require("crypto");
786
+ return crypto.randomBytes(8).toString("hex");
787
+ } catch (e) {
788
+ return Math.random().toString(36).substring(2, 15);
789
+ }
790
+ }
778
791
  function detectRuntimeEnvironment() {
779
792
  try {
780
793
  if (typeof globalThis.Bun !== "undefined") {
@@ -835,6 +848,7 @@ var init_telemetry = __esm({
835
848
  init_logging();
836
849
  init_events();
837
850
  init_utils();
851
+ __name(secureRandomString, "secureRandomString");
838
852
  USER_ID_STORAGE_KEY = "mcp_use_user_id";
839
853
  __name(detectRuntimeEnvironment, "detectRuntimeEnvironment");
840
854
  __name(getStorageCapability, "getStorageCapability");
@@ -914,12 +928,26 @@ var init_telemetry = __esm({
914
928
  "Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
915
929
  );
916
930
  this._posthogLoading = this._initPostHog();
917
- try {
918
- this._scarfClient = new ScarfEventLogger(this.SCARF_GATEWAY_URL, 3e3);
919
- } catch (e) {
920
- logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
931
+ if (this._runtimeEnvironment !== "browser") {
932
+ try {
933
+ this._scarfClient = new ScarfEventLogger(
934
+ this.SCARF_GATEWAY_URL,
935
+ 3e3
936
+ );
937
+ } catch (e) {
938
+ logger.warn(`Failed to initialize Scarf telemetry: ${e}`);
939
+ this._scarfClient = null;
940
+ }
941
+ } else {
921
942
  this._scarfClient = null;
922
943
  }
944
+ if (this._storageCapability === "filesystem" && this._scarfClient) {
945
+ setTimeout(() => {
946
+ this.trackPackageDownload({ triggered_by: "initialization" }).catch(
947
+ (e) => logger.debug(`Failed to track package download: ${e}`)
948
+ );
949
+ }, 0);
950
+ }
923
951
  }
924
952
  }
925
953
  _checkTelemetryDisabled() {
@@ -1044,47 +1072,65 @@ var init_telemetry = __esm({
1044
1072
  break;
1045
1073
  case "session-only":
1046
1074
  default:
1047
- this._currUserId = `session-${generateUUID()}`;
1048
- logger.debug(
1049
- `Using session-based user ID (${this._runtimeEnvironment} environment)`
1050
- );
1075
+ try {
1076
+ this._currUserId = `session-${generateUUID()}`;
1077
+ } catch (uuidError) {
1078
+ this._currUserId = `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1079
+ }
1051
1080
  break;
1052
1081
  }
1053
- if (this._storageCapability === "filesystem" && this._currUserId) {
1054
- this._trackPackageDownloadInternal(this._currUserId, {
1055
- triggered_by: "user_id_property"
1056
- }).catch((e) => logger.debug(`Failed to track package download: ${e}`));
1057
- }
1058
1082
  } catch (e) {
1059
- logger.debug(`Failed to get/create user ID: ${e}`);
1060
1083
  this._currUserId = this.UNKNOWN_USER_ID;
1061
1084
  }
1062
1085
  return this._currUserId;
1063
1086
  }
1064
1087
  /**
1065
1088
  * Get or create user ID from filesystem (Node.js/Bun)
1089
+ * Falls back to session ID if filesystem operations fail
1066
1090
  */
1067
1091
  _getUserIdFromFilesystem() {
1068
- const fs = require("fs");
1069
- const os = require("os");
1070
- const path = require("path");
1071
- if (!this._userIdPath) {
1072
- this._userIdPath = path.join(
1073
- this._getCacheHome(os, path),
1074
- "mcp_use_3",
1075
- "telemetry_user_id"
1076
- );
1077
- }
1078
- const isFirstTime = !fs.existsSync(this._userIdPath);
1079
- if (isFirstTime) {
1080
- logger.debug(`Creating user ID path: ${this._userIdPath}`);
1081
- fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
1082
- const newUserId = generateUUID();
1083
- fs.writeFileSync(this._userIdPath, newUserId);
1084
- logger.debug(`User ID path created: ${this._userIdPath}`);
1085
- return newUserId;
1092
+ try {
1093
+ let fs, os, path;
1094
+ try {
1095
+ fs = require("fs");
1096
+ os = require("os");
1097
+ path = require("path");
1098
+ } catch (requireError) {
1099
+ try {
1100
+ const sessionId = `session-${generateUUID()}`;
1101
+ return sessionId;
1102
+ } catch (uuidError) {
1103
+ return `session-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1104
+ }
1105
+ }
1106
+ if (!this._userIdPath) {
1107
+ this._userIdPath = path.join(
1108
+ this._getCacheHome(os, path),
1109
+ "mcp_use_3",
1110
+ "telemetry_user_id"
1111
+ );
1112
+ }
1113
+ const isFirstTime = !fs.existsSync(this._userIdPath);
1114
+ if (isFirstTime) {
1115
+ fs.mkdirSync(path.dirname(this._userIdPath), { recursive: true });
1116
+ let newUserId;
1117
+ try {
1118
+ newUserId = generateUUID();
1119
+ } catch (uuidError) {
1120
+ newUserId = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1121
+ }
1122
+ fs.writeFileSync(this._userIdPath, newUserId);
1123
+ return newUserId;
1124
+ }
1125
+ const userId = fs.readFileSync(this._userIdPath, "utf-8").trim();
1126
+ return userId;
1127
+ } catch (e) {
1128
+ try {
1129
+ return `session-${generateUUID()}`;
1130
+ } catch (uuidError) {
1131
+ return `session-${Date.now()}-${secureRandomString()}`;
1132
+ }
1086
1133
  }
1087
- return fs.readFileSync(this._userIdPath, "utf-8").trim();
1088
1134
  }
1089
1135
  /**
1090
1136
  * Get or create user ID from localStorage (Browser)
@@ -1093,14 +1139,22 @@ var init_telemetry = __esm({
1093
1139
  try {
1094
1140
  let userId = localStorage.getItem(USER_ID_STORAGE_KEY);
1095
1141
  if (!userId) {
1096
- userId = generateUUID();
1142
+ try {
1143
+ userId = generateUUID();
1144
+ } catch (uuidError) {
1145
+ userId = `${Date.now()}-${secureRandomString()}`;
1146
+ }
1097
1147
  localStorage.setItem(USER_ID_STORAGE_KEY, userId);
1098
- logger.debug(`Created new browser user ID`);
1099
1148
  }
1100
1149
  return userId;
1101
1150
  } catch (e) {
1102
- logger.debug(`localStorage access failed: ${e}`);
1103
- return `session-${generateUUID()}`;
1151
+ let sessionId;
1152
+ try {
1153
+ sessionId = `session-${generateUUID()}`;
1154
+ } catch (uuidError) {
1155
+ sessionId = `session-${Date.now()}-${secureRandomString()}`;
1156
+ }
1157
+ return sessionId;
1104
1158
  }
1105
1159
  }
1106
1160
  _getCacheHome(os, path) {
@@ -1129,6 +1183,7 @@ var init_telemetry = __esm({
1129
1183
  if (!this._posthogNodeClient && !this._posthogBrowserClient && !this._scarfClient) {
1130
1184
  return;
1131
1185
  }
1186
+ const currentUserId = this.userId;
1132
1187
  const properties = { ...event.properties };
1133
1188
  properties.mcp_use_version = getPackageVersion();
1134
1189
  properties.language = "typescript";
@@ -1136,9 +1191,8 @@ var init_telemetry = __esm({
1136
1191
  properties.runtime = this._runtimeEnvironment;
1137
1192
  if (this._posthogNodeClient) {
1138
1193
  try {
1139
- logger.debug(`CAPTURE: PostHog Node Event ${event.name}`);
1140
1194
  this._posthogNodeClient.capture({
1141
- distinctId: this.userId,
1195
+ distinctId: currentUserId,
1142
1196
  event: event.name,
1143
1197
  properties
1144
1198
  });
@@ -1148,10 +1202,9 @@ var init_telemetry = __esm({
1148
1202
  }
1149
1203
  if (this._posthogBrowserClient) {
1150
1204
  try {
1151
- logger.debug(`CAPTURE: PostHog Browser Event ${event.name}`);
1152
1205
  this._posthogBrowserClient.capture(event.name, {
1153
1206
  ...properties,
1154
- distinct_id: this.userId
1207
+ distinct_id: currentUserId
1155
1208
  });
1156
1209
  } catch (e) {
1157
1210
  logger.debug(
@@ -1163,7 +1216,7 @@ var init_telemetry = __esm({
1163
1216
  try {
1164
1217
  const scarfProperties = {
1165
1218
  ...properties,
1166
- user_id: this.userId,
1219
+ user_id: currentUserId,
1167
1220
  event: event.name
1168
1221
  };
1169
1222
  await this._scarfClient.logEvent(scarfProperties);
@@ -2221,7 +2274,7 @@ module.exports = __toCommonJS(server_exports);
2221
2274
  // src/server/mcp-server.ts
2222
2275
  var import_mcp2 = require("@mcp-use/modelcontextprotocol-sdk/server/mcp.js");
2223
2276
  var import_types2 = require("@mcp-use/modelcontextprotocol-sdk/types.js");
2224
- var import_zod2 = require("zod");
2277
+ var import_zod3 = require("zod");
2225
2278
  init_telemetry2();
2226
2279
  init_version();
2227
2280
 
@@ -3705,12 +3758,16 @@ export default PostHog;
3705
3758
  const mod = await viteServer.ssrLoadModule(widget2.entry);
3706
3759
  if (mod.widgetMetadata) {
3707
3760
  metadata = mod.widgetMetadata;
3708
- if (metadata.inputs) {
3761
+ const schemaField = metadata.props || metadata.inputs;
3762
+ if (schemaField) {
3709
3763
  try {
3710
- metadata.inputs = metadata.inputs.shape || metadata.inputs;
3764
+ metadata.props = schemaField;
3765
+ if (!metadata.inputs) {
3766
+ metadata.inputs = schemaField;
3767
+ }
3711
3768
  } catch (error2) {
3712
3769
  console.warn(
3713
- `[WIDGET] Failed to extract props schema for ${widget2.name}:`,
3770
+ `[WIDGET] Failed to extract schema for ${widget2.name}:`,
3714
3771
  error2
3715
3772
  );
3716
3773
  }
@@ -3900,6 +3957,7 @@ function setupWidgetRoutes(app, serverConfig) {
3900
3957
  __name(setupWidgetRoutes, "setupWidgetRoutes");
3901
3958
 
3902
3959
  // src/server/widgets/ui-resource-registration.ts
3960
+ var import_zod = __toESM(require("zod"), 1);
3903
3961
  function uiResourceRegistration(server, definition) {
3904
3962
  const displayName = definition.title || definition.name;
3905
3963
  if (definition.type === "appsSdk" && definition._meta) {
@@ -4005,69 +4063,76 @@ function uiResourceRegistration(server, definition) {
4005
4063
  }
4006
4064
  }
4007
4065
  }
4008
- server.tool(
4009
- {
4010
- name: definition.name,
4011
- title: definition.title,
4012
- description: definition.description,
4013
- inputs: convertPropsToInputs(definition.props),
4014
- annotations: definition.toolAnnotations,
4015
- _meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0
4016
- },
4017
- async (params) => {
4018
- const uiResource = await createWidgetUIResource(
4019
- definition,
4020
- params,
4021
- serverConfig
4066
+ const widgetMetadata2 = definition._meta?.["mcp-use/widget"];
4067
+ const propsOrSchema = definition.props || widgetMetadata2?.props || widgetMetadata2?.inputs || widgetMetadata2?.schema;
4068
+ const isZodSchema = propsOrSchema && typeof propsOrSchema === "object" && propsOrSchema instanceof import_zod.default.ZodObject;
4069
+ const toolDefinition = {
4070
+ name: definition.name,
4071
+ title: definition.title,
4072
+ description: definition.description,
4073
+ annotations: definition.toolAnnotations,
4074
+ _meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0
4075
+ };
4076
+ if (isZodSchema) {
4077
+ toolDefinition.schema = propsOrSchema;
4078
+ } else if (propsOrSchema) {
4079
+ toolDefinition.inputs = convertPropsToInputs(
4080
+ propsOrSchema
4081
+ );
4082
+ }
4083
+ server.tool(toolDefinition, async (params) => {
4084
+ const uiResource = await createWidgetUIResource(
4085
+ definition,
4086
+ params,
4087
+ serverConfig
4088
+ );
4089
+ if (definition.type === "appsSdk") {
4090
+ const randomId = Math.random().toString(36).substring(2, 15);
4091
+ const uniqueUri = generateWidgetUri(
4092
+ definition.name,
4093
+ server.buildId,
4094
+ ".html",
4095
+ randomId
4022
4096
  );
4023
- if (definition.type === "appsSdk") {
4024
- const randomId = Math.random().toString(36).substring(2, 15);
4025
- const uniqueUri = generateWidgetUri(
4026
- definition.name,
4027
- server.buildId,
4028
- ".html",
4029
- randomId
4030
- );
4031
- const uniqueToolMetadata = {
4032
- ...toolMetadata,
4033
- "openai/outputTemplate": uniqueUri,
4034
- "mcp-use/props": params
4035
- // Pass params as widget props
4036
- };
4037
- let toolOutputResult;
4038
- if (definition.toolOutput) {
4039
- toolOutputResult = typeof definition.toolOutput === "function" ? definition.toolOutput(params) : definition.toolOutput;
4040
- } else {
4041
- toolOutputResult = {
4042
- content: [
4043
- {
4044
- type: "text",
4045
- text: `Displaying ${displayName}`
4046
- }
4047
- ]
4048
- };
4049
- }
4050
- const content = toolOutputResult.content || [
4051
- { type: "text", text: `Displaying ${displayName}` }
4052
- ];
4053
- return {
4054
- _meta: uniqueToolMetadata,
4055
- content,
4056
- structuredContent: toolOutputResult.structuredContent
4097
+ const uniqueToolMetadata = {
4098
+ ...toolMetadata,
4099
+ "openai/outputTemplate": uniqueUri,
4100
+ "mcp-use/props": params
4101
+ // Pass params as widget props
4102
+ };
4103
+ let toolOutputResult;
4104
+ if (definition.toolOutput) {
4105
+ toolOutputResult = typeof definition.toolOutput === "function" ? definition.toolOutput(params) : definition.toolOutput;
4106
+ } else {
4107
+ toolOutputResult = {
4108
+ content: [
4109
+ {
4110
+ type: "text",
4111
+ text: `Displaying ${displayName}`
4112
+ }
4113
+ ]
4057
4114
  };
4058
4115
  }
4116
+ const content = toolOutputResult.content || [
4117
+ { type: "text", text: `Displaying ${displayName}` }
4118
+ ];
4059
4119
  return {
4060
- content: [
4061
- {
4062
- type: "text",
4063
- text: `Displaying ${displayName}`,
4064
- description: `Show MCP-UI widget for ${displayName}`
4065
- },
4066
- uiResource
4067
- ]
4120
+ _meta: uniqueToolMetadata,
4121
+ content,
4122
+ structuredContent: toolOutputResult.structuredContent
4068
4123
  };
4069
4124
  }
4070
- );
4125
+ return {
4126
+ content: [
4127
+ {
4128
+ type: "text",
4129
+ text: `Displaying ${displayName}`,
4130
+ description: `Show MCP-UI widget for ${displayName}`
4131
+ },
4132
+ uiResource
4133
+ ]
4134
+ };
4135
+ });
4071
4136
  }
4072
4137
  return server;
4073
4138
  }
@@ -4129,9 +4194,9 @@ async function mountInspectorUI(app, serverHost, serverPort, isProduction) {
4129
4194
  __name(mountInspectorUI, "mountInspectorUI");
4130
4195
 
4131
4196
  // src/server/tools/schema-helpers.ts
4132
- var import_zod = require("zod");
4197
+ var import_zod2 = require("zod");
4133
4198
  function convertZodSchemaToParams(zodSchema) {
4134
- if (!(zodSchema instanceof import_zod.z.ZodObject)) {
4199
+ if (!(zodSchema instanceof import_zod2.z.ZodObject)) {
4135
4200
  throw new Error("schema must be a Zod object schema (z.object({...}))");
4136
4201
  }
4137
4202
  const shape = zodSchema.shape;
@@ -4148,22 +4213,22 @@ function createParamsSchema(inputs) {
4148
4213
  let zodType;
4149
4214
  switch (input.type) {
4150
4215
  case "string":
4151
- zodType = import_zod.z.string();
4216
+ zodType = import_zod2.z.string();
4152
4217
  break;
4153
4218
  case "number":
4154
- zodType = import_zod.z.number();
4219
+ zodType = import_zod2.z.number();
4155
4220
  break;
4156
4221
  case "boolean":
4157
- zodType = import_zod.z.boolean();
4222
+ zodType = import_zod2.z.boolean();
4158
4223
  break;
4159
4224
  case "object":
4160
- zodType = import_zod.z.object({});
4225
+ zodType = import_zod2.z.object({});
4161
4226
  break;
4162
4227
  case "array":
4163
- zodType = import_zod.z.array(import_zod.z.any());
4228
+ zodType = import_zod2.z.array(import_zod2.z.any());
4164
4229
  break;
4165
4230
  default:
4166
- zodType = import_zod.z.any();
4231
+ zodType = import_zod2.z.any();
4167
4232
  }
4168
4233
  if (input.description) {
4169
4234
  zodType = zodType.describe(input.description);
@@ -6663,7 +6728,7 @@ var MCPServerClass = class {
6663
6728
  );
6664
6729
  }
6665
6730
  newServer.server.setRequestHandler(
6666
- import_zod2.z.object({ method: import_zod2.z.literal("logging/setLevel") }).passthrough(),
6731
+ import_zod3.z.object({ method: import_zod3.z.literal("logging/setLevel") }).passthrough(),
6667
6732
  (async (request, extra) => {
6668
6733
  const level = request.params?.level;
6669
6734
  if (!level) {