mcp-use 1.9.1-canary.0 → 1.10.0-canary.10

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 (148) hide show
  1. package/README.md +9 -6
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/chunk-6EYDSXO6.js +942 -0
  4. package/dist/{chunk-D22NUQTL.js → chunk-BFSVTG6G.js} +213 -12
  5. package/dist/{chunk-KHTTBIRP.js → chunk-BPP5XYP6.js} +156 -5
  6. package/dist/{chunk-3R5PDYIN.js → chunk-J75I2C26.js} +39 -11
  7. package/dist/{chunk-5URNFWCQ.js → chunk-LWVK6RXA.js} +8 -3
  8. package/dist/{chunk-MUZ5WYE3.js → chunk-NBSNYHID.js} +22 -13
  9. package/dist/{chunk-U5BX3ISQ.js → chunk-NRALSDBH.js} +22 -408
  10. package/dist/{chunk-ZQUCGISK.js → chunk-PL645KUX.js} +21 -5
  11. package/dist/{chunk-QREDNTLS.js → chunk-ZMA4JG4C.js} +1 -1
  12. package/dist/{context-storage-TXQ4DVSS.js → context-storage-NA4MHWOZ.js} +3 -1
  13. package/dist/index.cjs +854 -122
  14. package/dist/index.d.ts +6 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +57 -23
  17. package/dist/src/adapters/langchain_adapter.d.ts +1 -1
  18. package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
  19. package/dist/src/agents/index.cjs +2071 -1620
  20. package/dist/src/agents/index.js +4 -4
  21. package/dist/src/agents/mcp_agent.d.ts +5 -0
  22. package/dist/src/agents/mcp_agent.d.ts.map +1 -1
  23. package/dist/src/auth/browser-provider.d.ts +2 -2
  24. package/dist/src/auth/browser-provider.d.ts.map +1 -1
  25. package/dist/src/auth/callback.d.ts.map +1 -1
  26. package/dist/src/auth/index.cjs +39 -11
  27. package/dist/src/auth/index.js +1 -1
  28. package/dist/src/auth/types.d.ts +1 -1
  29. package/dist/src/auth/types.d.ts.map +1 -1
  30. package/dist/src/browser.cjs +3299 -2601
  31. package/dist/src/browser.d.ts +2 -1
  32. package/dist/src/browser.d.ts.map +1 -1
  33. package/dist/src/browser.js +10 -5
  34. package/dist/src/client/browser.d.ts +5 -0
  35. package/dist/src/client/browser.d.ts.map +1 -1
  36. package/dist/src/client/connectors/codeMode.d.ts +1 -1
  37. package/dist/src/client/connectors/codeMode.d.ts.map +1 -1
  38. package/dist/src/client/executors/base.d.ts +1 -1
  39. package/dist/src/client/executors/base.d.ts.map +1 -1
  40. package/dist/src/client/prompts.cjs +13 -4
  41. package/dist/src/client/prompts.js +3 -2
  42. package/dist/src/client.d.ts +7 -1
  43. package/dist/src/client.d.ts.map +1 -1
  44. package/dist/src/connectors/base.d.ts +56 -6
  45. package/dist/src/connectors/base.d.ts.map +1 -1
  46. package/dist/src/connectors/http.d.ts.map +1 -1
  47. package/dist/src/connectors/stdio.d.ts.map +1 -1
  48. package/dist/src/connectors/websocket.d.ts +1 -1
  49. package/dist/src/connectors/websocket.d.ts.map +1 -1
  50. package/dist/src/oauth-helper.d.ts.map +1 -1
  51. package/dist/src/react/WidgetControls.d.ts.map +1 -1
  52. package/dist/src/react/index.cjs +1098 -47
  53. package/dist/src/react/index.d.ts +1 -1
  54. package/dist/src/react/index.d.ts.map +1 -1
  55. package/dist/src/react/index.js +5 -5
  56. package/dist/src/react/types.d.ts +1 -1
  57. package/dist/src/react/types.d.ts.map +1 -1
  58. package/dist/src/react/useMcp.d.ts.map +1 -1
  59. package/dist/src/server/context-storage.d.ts +8 -1
  60. package/dist/src/server/context-storage.d.ts.map +1 -1
  61. package/dist/src/server/endpoints/mount-mcp.d.ts +4 -1
  62. package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
  63. package/dist/src/server/index.cjs +2162 -287
  64. package/dist/src/server/index.d.ts +4 -3
  65. package/dist/src/server/index.d.ts.map +1 -1
  66. package/dist/src/server/index.js +870 -261
  67. package/dist/src/server/mcp-server.d.ts +107 -27
  68. package/dist/src/server/mcp-server.d.ts.map +1 -1
  69. package/dist/src/server/oauth/middleware.d.ts.map +1 -1
  70. package/dist/src/server/oauth/providers/auth0.d.ts +1 -1
  71. package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -1
  72. package/dist/src/server/oauth/providers/custom.d.ts +4 -2
  73. package/dist/src/server/oauth/providers/custom.d.ts.map +1 -1
  74. package/dist/src/server/oauth/providers/keycloak.d.ts +1 -1
  75. package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -1
  76. package/dist/src/server/oauth/providers/supabase.d.ts +1 -1
  77. package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -1
  78. package/dist/src/server/oauth/providers/types.d.ts +9 -5
  79. package/dist/src/server/oauth/providers/types.d.ts.map +1 -1
  80. package/dist/src/server/oauth/providers.d.ts +27 -9
  81. package/dist/src/server/oauth/providers.d.ts.map +1 -1
  82. package/dist/src/server/oauth/setup.d.ts +5 -4
  83. package/dist/src/server/oauth/setup.d.ts.map +1 -1
  84. package/dist/src/server/oauth/utils.d.ts +3 -2
  85. package/dist/src/server/oauth/utils.d.ts.map +1 -1
  86. package/dist/src/server/prompts/conversion.d.ts +1 -1
  87. package/dist/src/server/prompts/conversion.d.ts.map +1 -1
  88. package/dist/src/server/prompts/index.d.ts +6 -5
  89. package/dist/src/server/prompts/index.d.ts.map +1 -1
  90. package/dist/src/server/resources/conversion.d.ts +1 -1
  91. package/dist/src/server/resources/conversion.d.ts.map +1 -1
  92. package/dist/src/server/resources/index.d.ts +45 -25
  93. package/dist/src/server/resources/index.d.ts.map +1 -1
  94. package/dist/src/server/resources/subscriptions.d.ts +54 -0
  95. package/dist/src/server/resources/subscriptions.d.ts.map +1 -0
  96. package/dist/src/server/sessions/session-manager.d.ts +17 -5
  97. package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
  98. package/dist/src/server/tools/tool-execution-helpers.d.ts +59 -23
  99. package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
  100. package/dist/src/server/tools/tool-registration.d.ts +21 -7
  101. package/dist/src/server/tools/tool-registration.d.ts.map +1 -1
  102. package/dist/src/server/types/common.d.ts +25 -9
  103. package/dist/src/server/types/common.d.ts.map +1 -1
  104. package/dist/src/server/types/index.d.ts +3 -3
  105. package/dist/src/server/types/index.d.ts.map +1 -1
  106. package/dist/src/server/types/prompt.d.ts +3 -2
  107. package/dist/src/server/types/prompt.d.ts.map +1 -1
  108. package/dist/src/server/types/resource.d.ts +60 -10
  109. package/dist/src/server/types/resource.d.ts.map +1 -1
  110. package/dist/src/server/types/tool-context.d.ts +132 -1
  111. package/dist/src/server/types/tool-context.d.ts.map +1 -1
  112. package/dist/src/server/types/tool.d.ts +43 -2
  113. package/dist/src/server/types/tool.d.ts.map +1 -1
  114. package/dist/src/server/types/widget.d.ts +11 -1
  115. package/dist/src/server/types/widget.d.ts.map +1 -1
  116. package/dist/src/server/utils/response-helpers.d.ts +65 -33
  117. package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
  118. package/dist/src/server/widgets/index.d.ts +3 -3
  119. package/dist/src/server/widgets/index.d.ts.map +1 -1
  120. package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
  121. package/dist/src/server/widgets/ui-resource-registration.d.ts +13 -25
  122. package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
  123. package/dist/src/server/widgets/widget-helpers.d.ts +11 -6
  124. package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
  125. package/dist/src/server/widgets/widget-types.d.ts +3 -3
  126. package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
  127. package/dist/src/session.d.ts +372 -2
  128. package/dist/src/session.d.ts.map +1 -1
  129. package/dist/src/task_managers/sse.d.ts +2 -2
  130. package/dist/src/task_managers/sse.d.ts.map +1 -1
  131. package/dist/src/task_managers/stdio.d.ts +2 -2
  132. package/dist/src/task_managers/stdio.d.ts.map +1 -1
  133. package/dist/src/task_managers/streamable_http.d.ts +2 -2
  134. package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
  135. package/dist/src/telemetry/events.d.ts +219 -0
  136. package/dist/src/telemetry/events.d.ts.map +1 -1
  137. package/dist/src/telemetry/index.d.ts +2 -2
  138. package/dist/src/telemetry/index.d.ts.map +1 -1
  139. package/dist/src/telemetry/telemetry.d.ts +56 -1
  140. package/dist/src/telemetry/telemetry.d.ts.map +1 -1
  141. package/dist/src/telemetry/utils.d.ts +1 -1
  142. package/dist/src/telemetry/utils.d.ts.map +1 -1
  143. package/dist/src/version.d.ts +8 -0
  144. package/dist/src/version.d.ts.map +1 -0
  145. package/dist/{tool-execution-helpers-IVUDHXMK.js → tool-execution-helpers-XFVBSRXM.js} +9 -2
  146. package/dist/tsup.config.d.ts.map +1 -1
  147. package/package.json +6 -5
  148. package/dist/chunk-MTHLLDCX.js +0 -97
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  BaseConnector
3
- } from "./chunk-ZQUCGISK.js";
3
+ } from "./chunk-PL645KUX.js";
4
+ import {
5
+ generateUUID,
6
+ getPackageVersion
7
+ } from "./chunk-6EYDSXO6.js";
4
8
  import {
5
9
  logger
6
10
  } from "./chunk-34R6SIER.js";
7
- import {
8
- generateUUID
9
- } from "./chunk-MTHLLDCX.js";
10
11
  import {
11
12
  __name
12
13
  } from "./chunk-3GQAWCBQ.js";
@@ -82,17 +83,201 @@ var MCPSession = class {
82
83
  getRoots() {
83
84
  return this.connector.getRoots();
84
85
  }
86
+ /**
87
+ * Get the cached list of tools from the server.
88
+ *
89
+ * @returns Array of available tools
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const tools = session.tools;
94
+ * console.log(`Available tools: ${tools.map(t => t.name).join(", ")}`);
95
+ * ```
96
+ */
97
+ get tools() {
98
+ return this.connector.tools;
99
+ }
100
+ /**
101
+ * Get the server capabilities advertised during initialization.
102
+ *
103
+ * @returns Server capabilities object
104
+ */
105
+ get serverCapabilities() {
106
+ return this.connector.serverCapabilities;
107
+ }
108
+ /**
109
+ * Get the server information (name and version).
110
+ *
111
+ * @returns Server info object or null if not available
112
+ */
113
+ get serverInfo() {
114
+ return this.connector.serverInfo;
115
+ }
116
+ /**
117
+ * Call a tool on the server.
118
+ *
119
+ * @param name - Name of the tool to call
120
+ * @param args - Arguments to pass to the tool
121
+ * @param options - Optional request options (timeout, progress handlers, etc.)
122
+ * @returns Result from the tool execution
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const result = await session.callTool("add", { a: 5, b: 3 });
127
+ * console.log(`Result: ${result.content[0].text}`);
128
+ * ```
129
+ */
130
+ async callTool(name, args, options) {
131
+ return this.connector.callTool(name, args, options);
132
+ }
133
+ /**
134
+ * List resources from the server with optional pagination.
135
+ *
136
+ * @param cursor - Optional cursor for pagination
137
+ * @param options - Request options
138
+ * @returns Resource list with optional nextCursor for pagination
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const result = await session.listResources();
143
+ * console.log(`Found ${result.resources.length} resources`);
144
+ * ```
145
+ */
146
+ async listResources(cursor, options) {
147
+ return this.connector.listResources(cursor, options);
148
+ }
149
+ /**
150
+ * List all resources from the server, automatically handling pagination.
151
+ *
152
+ * @param options - Request options
153
+ * @returns Complete list of all resources
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const result = await session.listAllResources();
158
+ * console.log(`Total resources: ${result.resources.length}`);
159
+ * ```
160
+ */
161
+ async listAllResources(options) {
162
+ return this.connector.listAllResources(options);
163
+ }
164
+ /**
165
+ * List resource templates from the server.
166
+ *
167
+ * @param options - Request options
168
+ * @returns List of available resource templates
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const result = await session.listResourceTemplates();
173
+ * console.log(`Available templates: ${result.resourceTemplates.length}`);
174
+ * ```
175
+ */
176
+ async listResourceTemplates(options) {
177
+ return this.connector.listResourceTemplates(options);
178
+ }
179
+ /**
180
+ * Read a resource by URI.
181
+ *
182
+ * @param uri - URI of the resource to read
183
+ * @param options - Request options
184
+ * @returns Resource content
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const resource = await session.readResource("file:///path/to/file.txt");
189
+ * console.log(resource.contents);
190
+ * ```
191
+ */
192
+ async readResource(uri, options) {
193
+ return this.connector.readResource(uri, options);
194
+ }
195
+ /**
196
+ * Subscribe to resource updates.
197
+ *
198
+ * @param uri - URI of the resource to subscribe to
199
+ * @param options - Request options
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * await session.subscribeToResource("file:///path/to/file.txt");
204
+ * // Now you'll receive notifications when this resource changes
205
+ * ```
206
+ */
207
+ async subscribeToResource(uri, options) {
208
+ return this.connector.subscribeToResource(uri, options);
209
+ }
210
+ /**
211
+ * Unsubscribe from resource updates.
212
+ *
213
+ * @param uri - URI of the resource to unsubscribe from
214
+ * @param options - Request options
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * await session.unsubscribeFromResource("file:///path/to/file.txt");
219
+ * ```
220
+ */
221
+ async unsubscribeFromResource(uri, options) {
222
+ return this.connector.unsubscribeFromResource(uri, options);
223
+ }
224
+ /**
225
+ * List available prompts from the server.
226
+ *
227
+ * @returns List of available prompts
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const result = await session.listPrompts();
232
+ * console.log(`Available prompts: ${result.prompts.length}`);
233
+ * ```
234
+ */
235
+ async listPrompts() {
236
+ return this.connector.listPrompts();
237
+ }
238
+ /**
239
+ * Get a specific prompt with arguments.
240
+ *
241
+ * @param name - Name of the prompt to get
242
+ * @param args - Arguments for the prompt
243
+ * @returns Prompt result
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const prompt = await session.getPrompt("greeting", { name: "Alice" });
248
+ * console.log(prompt.messages);
249
+ * ```
250
+ */
251
+ async getPrompt(name, args) {
252
+ return this.connector.getPrompt(name, args);
253
+ }
254
+ /**
255
+ * Send a raw request through the client.
256
+ *
257
+ * @param method - MCP method name
258
+ * @param params - Request parameters
259
+ * @param options - Request options
260
+ * @returns Response from the server
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const result = await session.request("custom/method", { key: "value" });
265
+ * ```
266
+ */
267
+ async request(method, params = null, options) {
268
+ return this.connector.request(method, params, options);
269
+ }
85
270
  };
86
271
 
87
272
  // src/connectors/http.ts
88
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
273
+ import { Client } from "@mcp-use/modelcontextprotocol-sdk/client/index.js";
89
274
  import {
90
275
  StreamableHTTPClientTransport,
91
276
  StreamableHTTPError
92
- } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
277
+ } from "@mcp-use/modelcontextprotocol-sdk/client/streamableHttp.js";
93
278
 
94
279
  // src/task_managers/sse.ts
95
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
280
+ import { SSEClientTransport } from "@mcp-use/modelcontextprotocol-sdk/client/sse.js";
96
281
 
97
282
  // src/task_managers/base.ts
98
283
  var ConnectionManager = class {
@@ -303,15 +488,16 @@ var HttpConnector = class extends BaseConnector {
303
488
  let fallbackReason = "Unknown error";
304
489
  let is401Error = false;
305
490
  if (err instanceof StreamableHTTPError) {
306
- is401Error = err.code === 401;
307
- if (err.code === 400 && err.message.includes("Missing session ID")) {
491
+ const streamableErr = err;
492
+ is401Error = streamableErr.code === 401;
493
+ if (streamableErr.code === 400 && streamableErr.message.includes("Missing session ID")) {
308
494
  fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
309
495
  logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
310
- } else if (err.code === 404 || err.code === 405) {
311
- fallbackReason = `Server returned ${err.code} - server likely doesn't support streamable HTTP`;
496
+ } else if (streamableErr.code === 404 || streamableErr.code === 405) {
497
+ fallbackReason = `Server returned ${streamableErr.code} - server likely doesn't support streamable HTTP`;
312
498
  logger.debug(fallbackReason);
313
499
  } else {
314
- fallbackReason = `Server returned ${err.code}: ${err.message}`;
500
+ fallbackReason = `Server returned ${streamableErr.code}: ${streamableErr.message}`;
315
501
  logger.debug(fallbackReason);
316
502
  }
317
503
  } else if (err instanceof Error) {
@@ -451,6 +637,10 @@ var HttpConnector = class extends BaseConnector {
451
637
  logger.debug(
452
638
  `Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`
453
639
  );
640
+ this.trackConnectorInit({
641
+ serverUrl: this.baseUrl,
642
+ publicIdentifier: `${this.baseUrl} (streamable-http)`
643
+ });
454
644
  } catch (err) {
455
645
  await this.cleanupResources();
456
646
  throw err;
@@ -498,6 +688,10 @@ var HttpConnector = class extends BaseConnector {
498
688
  logger.debug(
499
689
  `Successfully connected to MCP implementation via HTTP/SSE: ${baseUrl}`
500
690
  );
691
+ this.trackConnectorInit({
692
+ serverUrl: this.baseUrl,
693
+ publicIdentifier: `${this.baseUrl} (sse)`
694
+ });
501
695
  } catch (err) {
502
696
  await this.cleanupResources();
503
697
  throw err;
@@ -913,6 +1107,13 @@ var BrowserMCPClient = class _BrowserMCPClient extends BaseMCPClient {
913
1107
  static {
914
1108
  __name(this, "BrowserMCPClient");
915
1109
  }
1110
+ /**
1111
+ * Get the mcp-use package version.
1112
+ * Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
1113
+ */
1114
+ static getPackageVersion() {
1115
+ return getPackageVersion();
1116
+ }
916
1117
  constructor(config) {
917
1118
  super(config);
918
1119
  }
@@ -2,14 +2,15 @@ import {
2
2
  ElicitationValidationError
3
3
  } from "./chunk-KUEVOU4M.js";
4
4
  import {
5
+ Telemetry,
5
6
  generateUUID
6
- } from "./chunk-MTHLLDCX.js";
7
+ } from "./chunk-6EYDSXO6.js";
7
8
  import {
8
9
  __name
9
10
  } from "./chunk-3GQAWCBQ.js";
10
11
 
11
12
  // src/server/tools/tool-execution-helpers.ts
12
- import { toJsonSchemaCompat } from "@modelcontextprotocol/sdk/server/zod-json-schema-compat.js";
13
+ import { toJsonSchemaCompat } from "@mcp-use/modelcontextprotocol-sdk/server/zod-json-schema-compat.js";
13
14
  function findSessionContext(sessions, initialRequestContext, extraProgressToken, extraSendNotification) {
14
15
  let requestContext = initialRequestContext;
15
16
  let session;
@@ -196,6 +197,9 @@ function createSampleMethod(createMessage, progressToken, sendNotification) {
196
197
  `Sampling timed out after ${timeout}ms`
197
198
  );
198
199
  console.log("[SAMPLING DEBUG] Got result:", result);
200
+ Telemetry.getInstance().trackServerContext({
201
+ contextType: "sample"
202
+ }).catch((e) => console.debug(`Failed to track sample context: ${e}`));
199
203
  return result;
200
204
  } catch (error) {
201
205
  console.error("[SAMPLING DEBUG] Error during sampling:", error);
@@ -219,6 +223,9 @@ function createElicitMethod(elicitInput) {
219
223
  const { timeout } = options ?? {};
220
224
  const sdkTimeout = timeout && timeout !== Infinity ? timeout : 2147483647;
221
225
  const result = await elicitInput(sdkParams, { timeout: sdkTimeout });
226
+ Telemetry.getInstance().trackServerContext({
227
+ contextType: "elicit"
228
+ }).catch((e) => console.debug(`Failed to track elicit context: ${e}`));
222
229
  if (zodSchema && result.action === "accept" && result.data) {
223
230
  try {
224
231
  const validatedData = zodSchema.parse(result.data);
@@ -227,9 +234,10 @@ function createElicitMethod(elicitInput) {
227
234
  data: validatedData
228
235
  };
229
236
  } catch (error) {
237
+ const err = error;
230
238
  throw new ElicitationValidationError(
231
- `Elicitation data validation failed: ${error.message}`,
232
- error
239
+ `Elicitation data validation failed: ${err.message}`,
240
+ err
233
241
  );
234
242
  }
235
243
  }
@@ -252,7 +260,129 @@ function createReportProgressMethod(progressToken, sendNotification) {
252
260
  return void 0;
253
261
  }
254
262
  __name(createReportProgressMethod, "createReportProgressMethod");
255
- function createEnhancedContext(baseContext, createMessage, elicitInput, progressToken, sendNotification) {
263
+ var LOG_LEVELS = {
264
+ debug: 0,
265
+ info: 1,
266
+ notice: 2,
267
+ warning: 3,
268
+ error: 4,
269
+ critical: 5,
270
+ alert: 6,
271
+ emergency: 7
272
+ };
273
+ var VALID_LOG_LEVELS = [
274
+ "debug",
275
+ "info",
276
+ "notice",
277
+ "warning",
278
+ "error",
279
+ "critical",
280
+ "alert",
281
+ "emergency"
282
+ ];
283
+ function isValidLogLevel(level) {
284
+ return VALID_LOG_LEVELS.includes(level);
285
+ }
286
+ __name(isValidLogLevel, "isValidLogLevel");
287
+ function shouldLogMessage(messageLevel, minLevel) {
288
+ if (!minLevel) {
289
+ return true;
290
+ }
291
+ if (!isValidLogLevel(messageLevel) || !isValidLogLevel(minLevel)) {
292
+ return true;
293
+ }
294
+ return LOG_LEVELS[messageLevel] >= LOG_LEVELS[minLevel];
295
+ }
296
+ __name(shouldLogMessage, "shouldLogMessage");
297
+ function createLogMethod(sendNotification, minLogLevel) {
298
+ if (!sendNotification) {
299
+ return void 0;
300
+ }
301
+ return async (level, message, logger) => {
302
+ if (!shouldLogMessage(level, minLogLevel)) {
303
+ return;
304
+ }
305
+ await sendNotification({
306
+ method: "notifications/message",
307
+ params: {
308
+ level,
309
+ data: message,
310
+ logger: logger || "tool"
311
+ }
312
+ });
313
+ Telemetry.getInstance().trackServerContext({
314
+ contextType: "notification",
315
+ notificationType: "message"
316
+ }).catch(
317
+ (e) => console.debug(`Failed to track notification context: ${e}`)
318
+ );
319
+ };
320
+ }
321
+ __name(createLogMethod, "createLogMethod");
322
+ function createClientCapabilityChecker(clientCapabilities) {
323
+ const caps = clientCapabilities || {};
324
+ return {
325
+ can(capability) {
326
+ return capability in caps;
327
+ },
328
+ capabilities() {
329
+ return { ...caps };
330
+ }
331
+ };
332
+ }
333
+ __name(createClientCapabilityChecker, "createClientCapabilityChecker");
334
+ function createSendNotificationMethod(sessionId, sessions) {
335
+ if (!sessionId || !sessions) {
336
+ return void 0;
337
+ }
338
+ return async (method, params) => {
339
+ const session = sessions.get(sessionId);
340
+ if (!session?.sendNotification) {
341
+ console.warn(
342
+ `[MCP] Cannot send notification to session ${sessionId} - no sendNotification function`
343
+ );
344
+ return;
345
+ }
346
+ try {
347
+ await session.sendNotification({
348
+ method,
349
+ params: params || {}
350
+ });
351
+ } catch (error) {
352
+ console.error(
353
+ `[MCP] Error sending notification to session ${sessionId}:`,
354
+ error
355
+ );
356
+ }
357
+ };
358
+ }
359
+ __name(createSendNotificationMethod, "createSendNotificationMethod");
360
+ function createSendNotificationToSessionMethod(sessions) {
361
+ if (!sessions) {
362
+ return void 0;
363
+ }
364
+ return async (sessionId, method, params) => {
365
+ const session = sessions.get(sessionId);
366
+ if (!session?.sendNotification) {
367
+ return false;
368
+ }
369
+ try {
370
+ await session.sendNotification({
371
+ method,
372
+ params: params || {}
373
+ });
374
+ return true;
375
+ } catch (error) {
376
+ console.error(
377
+ `[MCP] Error sending notification to session ${sessionId}:`,
378
+ error
379
+ );
380
+ return false;
381
+ }
382
+ };
383
+ }
384
+ __name(createSendNotificationToSessionMethod, "createSendNotificationToSessionMethod");
385
+ function createEnhancedContext(baseContext, createMessage, elicitInput, progressToken, sendNotification, minLogLevel, clientCapabilities, sessionId, sessions) {
256
386
  const enhancedContext = baseContext ? Object.create(baseContext) : {};
257
387
  enhancedContext.sample = createSampleMethod(
258
388
  createMessage,
@@ -264,6 +394,24 @@ function createEnhancedContext(baseContext, createMessage, elicitInput, progress
264
394
  progressToken,
265
395
  sendNotification
266
396
  );
397
+ enhancedContext.log = createLogMethod(sendNotification, minLogLevel);
398
+ enhancedContext.client = createClientCapabilityChecker(clientCapabilities);
399
+ if (sessionId) {
400
+ enhancedContext.session = {
401
+ sessionId
402
+ };
403
+ }
404
+ const sendNotificationMethod = createSendNotificationMethod(
405
+ sessionId,
406
+ sessions
407
+ );
408
+ if (sendNotificationMethod) {
409
+ enhancedContext.sendNotification = sendNotificationMethod;
410
+ }
411
+ const sendNotificationToSessionMethod = createSendNotificationToSessionMethod(sessions);
412
+ if (sendNotificationToSessionMethod) {
413
+ enhancedContext.sendNotificationToSession = sendNotificationToSessionMethod;
414
+ }
267
415
  return enhancedContext;
268
416
  }
269
417
  __name(createEnhancedContext, "createEnhancedContext");
@@ -276,5 +424,8 @@ export {
276
424
  createSampleMethod,
277
425
  createElicitMethod,
278
426
  createReportProgressMethod,
427
+ VALID_LOG_LEVELS,
428
+ isValidLogLevel,
429
+ shouldLogMessage,
279
430
  createEnhancedContext
280
431
  };
@@ -261,7 +261,7 @@ var BrowserOAuthClientProvider = class {
261
261
  };
262
262
 
263
263
  // src/auth/callback.ts
264
- import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
264
+ import { auth } from "@mcp-use/modelcontextprotocol-sdk/client/auth.js";
265
265
  async function onMcpAuthorization() {
266
266
  const queryParams = new URLSearchParams(window.location.search);
267
267
  const code = queryParams.get("code");
@@ -369,16 +369,44 @@ async function onMcpAuthorization() {
369
369
  );
370
370
  }
371
371
  try {
372
- document.body.innerHTML = `
373
- <div style="font-family: sans-serif; padding: 20px;">
374
- <h1>Authentication Error</h1>
375
- <p style="color: red; background-color: #ffebeb; border: 1px solid red; padding: 10px; border-radius: 4px;">
376
- ${errorMessage}
377
- </p>
378
- <p>You can close this window or <a href="#" onclick="window.close(); return false;">click here to close</a>.</p>
379
- <pre style="font-size: 0.8em; color: #555; margin-top: 20px; white-space: pre-wrap;">${err instanceof Error ? err.stack : ""}</pre>
380
- </div>
381
- `;
372
+ document.body.innerHTML = "";
373
+ const container = document.createElement("div");
374
+ container.style.fontFamily = "sans-serif";
375
+ container.style.padding = "20px";
376
+ const heading = document.createElement("h1");
377
+ heading.textContent = "Authentication Error";
378
+ container.appendChild(heading);
379
+ const errorPara = document.createElement("p");
380
+ errorPara.style.color = "red";
381
+ errorPara.style.backgroundColor = "#ffebeb";
382
+ errorPara.style.border = "1px solid red";
383
+ errorPara.style.padding = "10px";
384
+ errorPara.style.borderRadius = "4px";
385
+ errorPara.textContent = errorMessage;
386
+ container.appendChild(errorPara);
387
+ const closePara = document.createElement("p");
388
+ closePara.textContent = "You can close this window or ";
389
+ const closeLink = document.createElement("a");
390
+ closeLink.href = "#";
391
+ closeLink.textContent = "click here to close";
392
+ closeLink.onclick = (e) => {
393
+ e.preventDefault();
394
+ window.close();
395
+ return false;
396
+ };
397
+ closePara.appendChild(closeLink);
398
+ closePara.appendChild(document.createTextNode("."));
399
+ container.appendChild(closePara);
400
+ if (err instanceof Error && err.stack) {
401
+ const stackPre = document.createElement("pre");
402
+ stackPre.style.fontSize = "0.8em";
403
+ stackPre.style.color = "#555";
404
+ stackPre.style.marginTop = "20px";
405
+ stackPre.style.whiteSpace = "pre-wrap";
406
+ stackPre.textContent = err.stack;
407
+ container.appendChild(stackPre);
408
+ }
409
+ document.body.appendChild(container);
382
410
  } catch (displayError) {
383
411
  console.error(
384
412
  `${logPrefix} Could not display error in callback window:`,
@@ -5,14 +5,18 @@ import {
5
5
  // src/server/context-storage.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";
7
7
  var requestContextStorage = new AsyncLocalStorage();
8
- async function runWithContext(context, fn) {
9
- return requestContextStorage.run(context, fn);
8
+ async function runWithContext(context, fn, sessionId) {
9
+ return requestContextStorage.run({ honoContext: context, sessionId }, fn);
10
10
  }
11
11
  __name(runWithContext, "runWithContext");
12
12
  function getRequestContext() {
13
- return requestContextStorage.getStore();
13
+ return requestContextStorage.getStore()?.honoContext;
14
14
  }
15
15
  __name(getRequestContext, "getRequestContext");
16
+ function getSessionId() {
17
+ return requestContextStorage.getStore()?.sessionId;
18
+ }
19
+ __name(getSessionId, "getSessionId");
16
20
  function hasRequestContext() {
17
21
  return requestContextStorage.getStore() !== void 0;
18
22
  }
@@ -21,5 +25,6 @@ __name(hasRequestContext, "hasRequestContext");
21
25
  export {
22
26
  runWithContext,
23
27
  getRequestContext,
28
+ getSessionId,
24
29
  hasRequestContext
25
30
  };
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  BrowserMCPClient
3
- } from "./chunk-D22NUQTL.js";
3
+ } from "./chunk-BFSVTG6G.js";
4
4
  import {
5
5
  BrowserOAuthClientProvider,
6
6
  sanitizeUrl
7
- } from "./chunk-3R5PDYIN.js";
7
+ } from "./chunk-J75I2C26.js";
8
8
  import {
9
9
  __name
10
10
  } from "./chunk-3GQAWCBQ.js";
@@ -260,15 +260,16 @@ function useMcp(options) {
260
260
  }
261
261
  return "success";
262
262
  } catch (err) {
263
- const errorMessage = err?.message || String(err);
264
- if (err.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
263
+ const error2 = err;
264
+ const errorMessage = error2?.message || String(err);
265
+ if (error2.code === 401 || errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
265
266
  if (authProviderRef.current) {
266
267
  addLog(
267
268
  "info",
268
269
  "Authentication required. OAuth provider available."
269
270
  );
270
271
  try {
271
- const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
272
+ const { auth } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
272
273
  const baseUrl = new URL(url).origin;
273
274
  auth(authProviderRef.current, { serverUrl: baseUrl }).catch(
274
275
  () => {
@@ -309,7 +310,10 @@ function useMcp(options) {
309
310
  );
310
311
  return "failed";
311
312
  }
312
- failConnection(errorMessage, err);
313
+ failConnection(
314
+ errorMessage,
315
+ error2 instanceof Error ? error2 : new Error(String(error2))
316
+ );
313
317
  return "failed";
314
318
  }
315
319
  }, "tryConnectWithTransport");
@@ -433,7 +437,7 @@ function useMcp(options) {
433
437
  });
434
438
  authProviderRef.current = freshAuthProvider;
435
439
  addLog("info", "Triggering fresh OAuth authorization...");
436
- const { auth } = await import("@modelcontextprotocol/sdk/client/auth.js");
440
+ const { auth } = await import("@mcp-use/modelcontextprotocol-sdk/client/auth.js");
437
441
  const baseUrl = new URL(url).origin;
438
442
  auth(freshAuthProvider, {
439
443
  serverUrl: baseUrl
@@ -441,7 +445,7 @@ function useMcp(options) {
441
445
  addLog(
442
446
  "info",
443
447
  "OAuth flow initiated:",
444
- err?.message || "Redirecting..."
448
+ err instanceof Error ? err.message : "Redirecting..."
445
449
  );
446
450
  });
447
451
  } catch (authError) {
@@ -1183,7 +1187,8 @@ function WidgetControls({
1183
1187
  const result = await callTool(toolName, args);
1184
1188
  setActionResult(`Success: ${JSON.stringify(result, null, 2)}`);
1185
1189
  } catch (error) {
1186
- setActionResult(`Error: ${error.message}`);
1190
+ const err = error;
1191
+ setActionResult(`Error: ${err.message}`);
1187
1192
  }
1188
1193
  }, "handleCallTool");
1189
1194
  const handleSendFollowUpMessage = /* @__PURE__ */ __name(async () => {
@@ -1192,7 +1197,8 @@ function WidgetControls({
1192
1197
  await sendFollowUpMessage(followUpMessage);
1193
1198
  setActionResult("Follow-up message sent successfully");
1194
1199
  } catch (error) {
1195
- setActionResult(`Error: ${error.message}`);
1200
+ const err = error;
1201
+ setActionResult(`Error: ${err.message}`);
1196
1202
  }
1197
1203
  }, "handleSendFollowUpMessage");
1198
1204
  const handleOpenExternal = /* @__PURE__ */ __name(() => {
@@ -1200,7 +1206,8 @@ function WidgetControls({
1200
1206
  openExternal(externalUrl);
1201
1207
  setActionResult(`Opened external link: ${externalUrl}`);
1202
1208
  } catch (error) {
1203
- setActionResult(`Error: ${error.message}`);
1209
+ const err = error;
1210
+ setActionResult(`Error: ${err.message}`);
1204
1211
  }
1205
1212
  }, "handleOpenExternal");
1206
1213
  const handleRequestDisplayMode = /* @__PURE__ */ __name(async (mode) => {
@@ -1209,7 +1216,8 @@ function WidgetControls({
1209
1216
  const result = await requestDisplayMode(mode);
1210
1217
  setActionResult(`Display mode granted: ${result.mode}`);
1211
1218
  } catch (error) {
1212
- setActionResult(`Error: ${error.message}`);
1219
+ const err = error;
1220
+ setActionResult(`Error: ${err.message}`);
1213
1221
  }
1214
1222
  }, "handleRequestDisplayMode");
1215
1223
  const handleSetState = /* @__PURE__ */ __name(async () => {
@@ -1219,7 +1227,8 @@ function WidgetControls({
1219
1227
  await setState(newState);
1220
1228
  setActionResult(`State updated: ${JSON.stringify(newState, null, 2)}`);
1221
1229
  } catch (error) {
1222
- setActionResult(`Error: ${error.message}`);
1230
+ const err = error;
1231
+ setActionResult(`Error: ${err.message}`);
1223
1232
  }
1224
1233
  }, "handleSetState");
1225
1234
  const handleFullscreen = /* @__PURE__ */ __name(async () => {