@mcp-use/client 2.0.0-beta.16 → 2.0.0-beta.18

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 (66) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/auth/browser.d.ts +51 -2
  3. package/dist/auth/browser.d.ts.map +1 -1
  4. package/dist/auth/node.d.ts +99 -4
  5. package/dist/auth/node.d.ts.map +1 -1
  6. package/dist/auth/session-store.d.ts +6 -0
  7. package/dist/auth/session-store.d.ts.map +1 -1
  8. package/dist/code-mode/executor-e2b.d.ts.map +1 -1
  9. package/dist/core/base.d.ts +4 -8
  10. package/dist/core/base.d.ts.map +1 -1
  11. package/dist/core/browser.d.ts +14 -2
  12. package/dist/core/browser.d.ts.map +1 -1
  13. package/dist/core/config.d.ts +82 -20
  14. package/dist/core/config.d.ts.map +1 -1
  15. package/dist/core/node.d.ts +7 -10
  16. package/dist/core/node.d.ts.map +1 -1
  17. package/dist/core/session.d.ts +18 -4
  18. package/dist/core/session.d.ts.map +1 -1
  19. package/dist/index-browser.d.ts +1 -0
  20. package/dist/index-browser.d.ts.map +1 -1
  21. package/dist/index-browser.js +142 -21
  22. package/dist/index-browser.js.map +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +228 -37
  25. package/dist/index.js.map +1 -1
  26. package/dist/react/McpClientProvider.d.ts +22 -10
  27. package/dist/react/McpClientProvider.d.ts.map +1 -1
  28. package/dist/react/index.d.ts +2 -0
  29. package/dist/react/index.d.ts.map +1 -1
  30. package/dist/react/index.js +164 -21
  31. package/dist/react/index.js.map +1 -1
  32. package/dist/react/rpc-logger.d.ts +5 -0
  33. package/dist/react/rpc-logger.d.ts.map +1 -1
  34. package/dist/react/storage.d.ts +47 -0
  35. package/dist/react/storage.d.ts.map +1 -1
  36. package/dist/react/types.d.ts +107 -16
  37. package/dist/react/types.d.ts.map +1 -1
  38. package/dist/react/useMcp-operations.d.ts.map +1 -1
  39. package/dist/react/view/ViewRenderer.d.ts +7 -0
  40. package/dist/react/view/ViewRenderer.d.ts.map +1 -1
  41. package/dist/react/view/parse-custom-props.d.ts +8 -0
  42. package/dist/react/view/parse-custom-props.d.ts.map +1 -1
  43. package/dist/react/view/resolve-view-resource.d.ts +10 -0
  44. package/dist/react/view/resolve-view-resource.d.ts.map +1 -1
  45. package/dist/react/view/types.d.ts +89 -0
  46. package/dist/react/view/types.d.ts.map +1 -1
  47. package/dist/react/view/view-detection.d.ts +18 -0
  48. package/dist/react/view/view-detection.d.ts.map +1 -1
  49. package/dist/react/view/view-host-policy.d.ts +35 -0
  50. package/dist/react/view/view-host-policy.d.ts.map +1 -1
  51. package/dist/telemetry/telemetry.d.ts +5 -1
  52. package/dist/telemetry/telemetry.d.ts.map +1 -1
  53. package/dist/transport/base.d.ts +85 -13
  54. package/dist/transport/base.d.ts.map +1 -1
  55. package/dist/transport/connection-manager.d.ts +1 -1
  56. package/dist/transport/http.d.ts +51 -2
  57. package/dist/transport/http.d.ts.map +1 -1
  58. package/dist/transport/stdio.d.ts +29 -1
  59. package/dist/transport/stdio.d.ts.map +1 -1
  60. package/dist/utils/elicitation.d.ts +4 -2
  61. package/dist/utils/elicitation.d.ts.map +1 -1
  62. package/dist/utils/logging.d.ts +1 -0
  63. package/dist/utils/logging.d.ts.map +1 -1
  64. package/dist/utils/version.d.ts +6 -0
  65. package/dist/utils/version.d.ts.map +1 -1
  66. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mcp-use/client — MCP client for connecting to Model Context Protocol servers.
2
+ * `@mcp-use/client` — MCP client for connecting to Model Context Protocol servers.
3
3
  *
4
4
  * Connectors, protocol-neutral MCP connections, project configuration, OAuth,
5
5
  * and code-mode helpers. The SDK negotiates legacy sessionful and modern
package/dist/index.js CHANGED
@@ -209,6 +209,11 @@ var init_base = __esm({
209
209
  notificationHandlers = [];
210
210
  rootsCache = [];
211
211
  activeProgressHandlers = /* @__PURE__ */ new Set();
212
+ /**
213
+ * Creates a connector with shared SDK and callback options.
214
+ *
215
+ * @param opts - Connector initialization options.
216
+ */
212
217
  constructor(opts = {}) {
213
218
  this.opts = opts;
214
219
  if (opts.roots) {
@@ -391,7 +396,9 @@ var init_base = __esm({
391
396
  }
392
397
  }
393
398
  /**
394
- * Get the current roots.
399
+ * Returns the roots currently advertised to the server.
400
+ *
401
+ * @returns A copy of the configured roots.
395
402
  */
396
403
  getRoots() {
397
404
  return [...this.rootsCache];
@@ -460,7 +467,11 @@ var init_base = __esm({
460
467
  "setupElicitationHandler: Elicitation handler registered successfully"
461
468
  );
462
469
  }
463
- /** Disconnect and release resources. */
470
+ /**
471
+ * Disconnects the SDK client and releases transport resources.
472
+ *
473
+ * @returns A promise that resolves after cleanup completes.
474
+ */
464
475
  async disconnect() {
465
476
  if (!this.connected) {
466
477
  logger.debug("Not connected to MCP implementation");
@@ -471,7 +482,7 @@ var init_base = __esm({
471
482
  this.connected = false;
472
483
  logger.debug("Disconnected from MCP implementation");
473
484
  }
474
- /** Check if the client is connected */
485
+ /** Whether an SDK client currently exists for this connector. */
475
486
  get isClientConnected() {
476
487
  return this.client != null;
477
488
  }
@@ -481,6 +492,10 @@ var init_base = __esm({
481
492
  * In the SDK, `Client.connect(transport)` automatically performs the
482
493
  * protocol‑level `initialize` handshake, so we only need to cache the list of
483
494
  * tools and expose some server info.
495
+ *
496
+ * @param defaultRequestOptions - Options used while fetching the initial tool list.
497
+ * @returns The capabilities advertised by the server.
498
+ * @throws When {@link BaseConnector.connect} has not completed.
484
499
  */
485
500
  async initialize(defaultRequestOptions = this.opts.defaultRequestOptions ?? {}) {
486
501
  if (!this.client) {
@@ -518,18 +533,22 @@ var init_base = __esm({
518
533
  logger.debug("Server info:", serverInfo);
519
534
  return capabilities;
520
535
  }
521
- /** Lazily expose the cached tools list. */
536
+ /**
537
+ * Returns the tool list cached during initialization.
538
+ *
539
+ * @throws When {@link BaseConnector.initialize} has not completed.
540
+ */
522
541
  get tools() {
523
542
  if (!this.toolsCache) {
524
543
  throw new Error("MCP client is not initialized; call initialize() first");
525
544
  }
526
545
  return this.toolsCache;
527
546
  }
528
- /** Expose cached server capabilities. */
547
+ /** Capabilities cached during initialization, or an empty object. */
529
548
  get serverCapabilities() {
530
549
  return this.capabilitiesCache || {};
531
550
  }
532
- /** Expose cached server info. */
551
+ /** Server identity cached during initialization, or `null`. */
533
552
  get serverInfo() {
534
553
  return this.serverInfoCache;
535
554
  }
@@ -550,7 +569,15 @@ var init_base = __esm({
550
569
  get negotiatedProtocolVersion() {
551
570
  return this.client?.getNegotiatedProtocolVersion?.();
552
571
  }
553
- /** Call a tool on the server. */
572
+ /**
573
+ * Calls a tool on the connected server.
574
+ *
575
+ * @param name - Tool name.
576
+ * @param args - Tool arguments.
577
+ * @param options - Per-request timeout, cancellation, and progress options.
578
+ * @returns The tool result returned by the server.
579
+ * @throws When the connector is not connected or the tool call fails.
580
+ */
554
581
  async callTool(name, args, options) {
555
582
  if (!this.client) {
556
583
  throw new Error("MCP client is not connected");
@@ -675,7 +702,13 @@ var init_base = __esm({
675
702
  );
676
703
  return result;
677
704
  }
678
- /** Read a resource by URI. */
705
+ /**
706
+ * Reads a resource by URI.
707
+ *
708
+ * @param uri - Resource URI to read.
709
+ * @param options - Per-request options.
710
+ * @returns The resource contents returned by the server.
711
+ */
679
712
  async readResource(uri, options) {
680
713
  if (!this.client) {
681
714
  throw new Error("MCP client is not connected");
@@ -710,6 +743,11 @@ var init_base = __esm({
710
743
  logger.debug(`Unsubscribing from resource: ${uri}`);
711
744
  return await this.client.unsubscribeResource({ uri }, options);
712
745
  }
746
+ /**
747
+ * Lists prompts exposed by the server.
748
+ *
749
+ * @returns The prompt list, or an empty list when prompts are unsupported.
750
+ */
713
751
  async listPrompts() {
714
752
  if (!this.client) {
715
753
  throw new Error("MCP client is not connected");
@@ -730,6 +768,13 @@ var init_base = __esm({
730
768
  throw err;
731
769
  }
732
770
  }
771
+ /**
772
+ * Gets a prompt with the supplied arguments.
773
+ *
774
+ * @param name - Prompt name.
775
+ * @param args - Prompt arguments.
776
+ * @returns The rendered prompt returned by the server.
777
+ */
733
778
  async getPrompt(name, args) {
734
779
  if (!this.client) {
735
780
  throw new Error("MCP client is not connected");
@@ -737,7 +782,14 @@ var init_base = __esm({
737
782
  logger.debug(`Getting prompt ${name}`);
738
783
  return await this.client.getPrompt({ name, arguments: args });
739
784
  }
740
- /** Send a raw request through the client. */
785
+ /**
786
+ * Sends a raw, potentially non-standard request through the SDK client.
787
+ *
788
+ * @param method - JSON-RPC method name.
789
+ * @param params - Request parameters. Defaults to an empty object.
790
+ * @param options - Per-request options.
791
+ * @returns The unvalidated result returned by the server.
792
+ */
741
793
  async request(method, params = null, options) {
742
794
  if (!this.client) {
743
795
  throw new Error("MCP client is not connected");
@@ -959,6 +1011,11 @@ var init_stdio = __esm({
959
1011
  errlog;
960
1012
  clientInfo;
961
1013
  protocolNegotiation;
1014
+ /**
1015
+ * Creates a stdio connector.
1016
+ *
1017
+ * @param options - Process launch, client identity, and shared connector options.
1018
+ */
962
1019
  constructor({
963
1020
  command = "npx",
964
1021
  args = [],
@@ -978,7 +1035,11 @@ var init_stdio = __esm({
978
1035
  this.cwd = rest.cwd;
979
1036
  this.protocolNegotiation = rest.protocolNegotiation ?? "legacy";
980
1037
  }
981
- /** Establish connection to the MCP implementation. */
1038
+ /**
1039
+ * Starts the child process and establishes an MCP connection.
1040
+ *
1041
+ * @returns A promise that resolves after protocol negotiation completes.
1042
+ */
982
1043
  async connect() {
983
1044
  if (this.connected) {
984
1045
  logger.debug("Already connected to MCP implementation");
@@ -1074,6 +1135,11 @@ var init_stdio = __esm({
1074
1135
  throw err;
1075
1136
  }
1076
1137
  }
1138
+ /**
1139
+ * Returns fields identifying the launched command and arguments.
1140
+ *
1141
+ * @returns Stdio connector identity metadata.
1142
+ */
1077
1143
  get publicIdentifier() {
1078
1144
  return {
1079
1145
  type: "stdio",
@@ -1085,6 +1151,12 @@ var init_stdio = __esm({
1085
1151
  serverParams;
1086
1152
  errlog;
1087
1153
  _transport = null;
1154
+ /**
1155
+ * Creates a connection manager for a local server process.
1156
+ *
1157
+ * @param serverParams - Process parameters passed to the SDK transport.
1158
+ * @param errlog - Destination for the child process's standard error stream.
1159
+ */
1088
1160
  constructor(serverParams, errlog = process2.stderr) {
1089
1161
  super();
1090
1162
  this.serverParams = serverParams;
@@ -1134,7 +1206,7 @@ init_connector_telemetry();
1134
1206
  init_logging();
1135
1207
 
1136
1208
  // src/utils/version.ts
1137
- var VERSION = "2.0.0-beta.16";
1209
+ var VERSION = "2.0.0-beta.18";
1138
1210
  function getPackageVersion() {
1139
1211
  return VERSION;
1140
1212
  }
@@ -2335,8 +2407,16 @@ var DEFAULT_PORT = 33418;
2335
2407
  var PORT_RANGE = 10;
2336
2408
  var DEFAULT_AUTH_TIMEOUT_MS2 = 5 * 6e4;
2337
2409
  var OAuthFlowError = class extends Error {
2410
+ /** OAuth or local-flow error code. */
2338
2411
  code;
2412
+ /** Optional human-readable error description. */
2339
2413
  description;
2414
+ /**
2415
+ * Creates an OAuth flow error.
2416
+ *
2417
+ * @param code - OAuth or local-flow error code.
2418
+ * @param description - Optional human-readable description.
2419
+ */
2340
2420
  constructor(code, description) {
2341
2421
  super(description ? `${code}: ${description}` : code);
2342
2422
  this.code = code;
@@ -2386,13 +2466,17 @@ h1{font-size:20px;margin:0 0 12px;color:#b00020}p{line-height:1.5}code{backgroun
2386
2466
  <p><code>${escapeHtml(err)}</code>${desc ? `: ${escapeHtml(desc)}` : ""}</p>
2387
2467
  <p>You can close this tab and return to your terminal.</p></body></html>`;
2388
2468
  var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2469
+ /** Protected MCP server URL associated with this provider. */
2389
2470
  serverUrl;
2471
+ /** Reserved localhost callback port. */
2390
2472
  port;
2391
2473
  session;
2392
2474
  kv;
2393
2475
  authTimeoutMs;
2394
2476
  openBrowserOverride;
2395
2477
  server = null;
2478
+ /** Provider authorization URL, exposed only through the local redirect route. */
2479
+ authorizationUrl = null;
2396
2480
  /** Currently in-flight deferred — used to prevent overlapping flows. */
2397
2481
  pending = null;
2398
2482
  /** Latest deferred (settled or in-flight) for the loopback response. */
@@ -2406,6 +2490,13 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2406
2490
  this.authTimeoutMs = options.authTimeoutMs ?? DEFAULT_AUTH_TIMEOUT_MS2;
2407
2491
  this.openBrowserOverride = options.openBrowser;
2408
2492
  }
2493
+ /**
2494
+ * Creates a Node OAuth provider and reserves a localhost callback port.
2495
+ *
2496
+ * @param serverUrl - Protected MCP server URL.
2497
+ * @param options - OAuth metadata, storage, loopback, and browser options.
2498
+ * @returns A provider ready to participate in the SDK OAuth flow.
2499
+ */
2409
2500
  static async create(serverUrl, options = {}) {
2410
2501
  const serverUrlHash = OAuthSessionStore.hashString(serverUrl);
2411
2502
  const kv = options.kvStore ?? new FileKVStore(serverUrlHash, options.baseDir);
@@ -2438,48 +2529,100 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2438
2529
  return new _NodeOAuthClientProvider(serverUrl, port, session, kv, options);
2439
2530
  }
2440
2531
  // --- Identity passthroughs (parallel to BrowserOAuthClientProvider) ---
2532
+ /** Prefix used for persisted OAuth session keys. */
2441
2533
  get storageKeyPrefix() {
2442
2534
  return this.session.storageKeyPrefix;
2443
2535
  }
2536
+ /** Stable hash of the protected server URL used to namespace storage. */
2444
2537
  get serverUrlHash() {
2445
2538
  return this.session.serverUrlHash;
2446
2539
  }
2447
2540
  // --- SDK Interface (delegated to OAuthSessionStore) ---
2541
+ /** Loopback redirect URL registered for this provider. */
2448
2542
  get redirectUrl() {
2449
2543
  return this.session.redirectUrl;
2450
2544
  }
2545
+ /** OAuth client metadata presented during registration. */
2451
2546
  get clientMetadata() {
2452
2547
  return this.session.clientMetadata;
2453
2548
  }
2549
+ /** OAuth Client ID Metadata Document URL, when configured. */
2454
2550
  get clientMetadataUrl() {
2455
2551
  return this.session.clientMetadataUrl;
2456
2552
  }
2553
+ /**
2554
+ * Loads saved OAuth tokens.
2555
+ *
2556
+ * @param ctx - Optional client registration context.
2557
+ * @returns Saved tokens, or `undefined` when none exist.
2558
+ */
2457
2559
  tokens(ctx) {
2458
2560
  return this.session.tokens(ctx);
2459
2561
  }
2562
+ /**
2563
+ * Persists OAuth tokens.
2564
+ *
2565
+ * @param tokens - Tokens to save.
2566
+ * @param ctx - Optional client registration context.
2567
+ */
2460
2568
  saveTokens(tokens, ctx) {
2461
2569
  return this.session.saveTokens(tokens, ctx);
2462
2570
  }
2571
+ /**
2572
+ * Loads saved OAuth client registration information.
2573
+ *
2574
+ * @param ctx - Optional registration context.
2575
+ * @returns Saved registration information, or `undefined`.
2576
+ */
2463
2577
  clientInformation(ctx) {
2464
2578
  return this.session.clientInformation(ctx);
2465
2579
  }
2580
+ /**
2581
+ * Persists OAuth client registration information.
2582
+ *
2583
+ * @param info - Client information to save.
2584
+ * @param ctx - Optional registration context.
2585
+ */
2466
2586
  saveClientInformation(info, ctx) {
2467
2587
  return this.session.saveClientInformation(info, ctx);
2468
2588
  }
2589
+ /**
2590
+ * Loads the saved PKCE code verifier.
2591
+ *
2592
+ * @returns The saved verifier.
2593
+ */
2469
2594
  codeVerifier() {
2470
2595
  return this.session.codeVerifier();
2471
2596
  }
2597
+ /**
2598
+ * Persists a PKCE code verifier.
2599
+ *
2600
+ * @param codeVerifier - Verifier to save.
2601
+ */
2472
2602
  saveCodeVerifier(codeVerifier) {
2473
2603
  return this.session.saveCodeVerifier(codeVerifier);
2474
2604
  }
2605
+ /**
2606
+ * Invalidates selected persisted OAuth credentials.
2607
+ *
2608
+ * @param scope - Credential group to remove.
2609
+ */
2475
2610
  invalidateCredentials(scope) {
2476
2611
  return this.session.invalidateCredentials(scope);
2477
2612
  }
2478
- /** Persist OAuth discovery state (SEP-2352). Delegated to the session store. */
2613
+ /**
2614
+ * Persists OAuth discovery state.
2615
+ *
2616
+ * @param state - Discovery state to save.
2617
+ */
2479
2618
  saveDiscoveryState(state) {
2480
2619
  return this.session.saveDiscoveryState(state);
2481
2620
  }
2482
- /** Return previously saved OAuth discovery state, or `undefined`. */
2621
+ /**
2622
+ * Returns previously saved OAuth discovery state.
2623
+ *
2624
+ * @returns Saved discovery state, or `undefined`.
2625
+ */
2483
2626
  discoveryState() {
2484
2627
  return this.session.discoveryState();
2485
2628
  }
@@ -2487,6 +2630,10 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2487
2630
  * Bind the loopback server, set up the pending-code deferred, and ask the
2488
2631
  * platform to open the user's browser. Does NOT await the code; the
2489
2632
  * orchestrator awaits via `getAuthorizationCode()`.
2633
+ *
2634
+ * @param authorizationUrl - Authorization URL generated by the SDK.
2635
+ * @returns A promise that resolves once the loopback listener is ready and
2636
+ * the browser-open attempt completes.
2490
2637
  */
2491
2638
  async redirectToAuthorization(authorizationUrl) {
2492
2639
  if (this.pending) {
@@ -2498,6 +2645,7 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2498
2645
  authorizationUrl,
2499
2646
  { flowType: "redirect" }
2500
2647
  );
2648
+ this.authorizationUrl = sanitizedUrl;
2501
2649
  await this.startLoopback();
2502
2650
  this.pending = createDeferred();
2503
2651
  this.lastFlow = this.pending;
@@ -2512,8 +2660,9 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2512
2660
  );
2513
2661
  }, this.authTimeoutMs);
2514
2662
  const opener = this.openBrowserOverride ?? defaultOpener;
2663
+ const launcherUrl = `http://127.0.0.1:${this.port}/authorize`;
2515
2664
  try {
2516
- await opener(sanitizedUrl);
2665
+ await opener(launcherUrl);
2517
2666
  } catch (err) {
2518
2667
  console.error(
2519
2668
  `[mcp-use] Could not open browser automatically: ${err instanceof Error ? err.message : String(err)}`
@@ -2528,6 +2677,8 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2528
2677
  * Must be called after `redirectToAuthorization()`. Returns the same
2529
2678
  * promise whether the callback has fired or not — callers may subscribe
2530
2679
  * before or after.
2680
+ *
2681
+ * @returns The authorization code received by the loopback callback.
2531
2682
  */
2532
2683
  getAuthorizationCode() {
2533
2684
  return this.getAuthorizationResponse().then((response) => response.code);
@@ -2535,6 +2686,9 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2535
2686
  /**
2536
2687
  * Resolves with the authorization code and RFC 9207 issuer captured by the
2537
2688
  * loopback callback.
2689
+ *
2690
+ * @returns The loopback authorization response.
2691
+ * @throws When called before {@link NodeOAuthClientProvider.redirectToAuthorization}.
2538
2692
  */
2539
2693
  getAuthorizationResponse() {
2540
2694
  if (!this.lastFlow) {
@@ -2548,6 +2702,9 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2548
2702
  }
2549
2703
  /**
2550
2704
  * Cancel an in-progress flow (timeout, SIGINT, etc.) and close the loopback.
2705
+ *
2706
+ * Pending calls to {@link NodeOAuthClientProvider.getAuthorizationResponse}
2707
+ * reject with an {@link OAuthFlowError} whose code is `"cancelled"`.
2551
2708
  */
2552
2709
  dispose() {
2553
2710
  if (this.pending) {
@@ -2556,7 +2713,7 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2556
2713
  this.stopLoopback();
2557
2714
  }
2558
2715
  }
2559
- /** Best-effort port for tests / status output. */
2716
+ /** Local callback port, useful for status output and tests. */
2560
2717
  get callbackPort() {
2561
2718
  return this.port;
2562
2719
  }
@@ -2594,6 +2751,7 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2594
2751
  this.server.close();
2595
2752
  this.server = null;
2596
2753
  }
2754
+ this.authorizationUrl = null;
2597
2755
  }
2598
2756
  resolvePending(response) {
2599
2757
  const p = this.pending;
@@ -2609,6 +2767,19 @@ var NodeOAuthClientProvider = class _NodeOAuthClientProvider {
2609
2767
  }
2610
2768
  handleCallback(rawUrl, res) {
2611
2769
  const url = new URL(rawUrl, `http://127.0.0.1:${this.port}`);
2770
+ if (url.pathname === "/authorize") {
2771
+ if (this.authorizationUrl === null || this.pending === null) {
2772
+ res.statusCode = 410;
2773
+ res.end("Authorization flow is not active");
2774
+ return;
2775
+ }
2776
+ res.statusCode = 302;
2777
+ res.setHeader("location", this.authorizationUrl);
2778
+ res.setHeader("cache-control", "no-store");
2779
+ res.setHeader("referrer-policy", "no-referrer");
2780
+ res.end();
2781
+ return;
2782
+ }
2612
2783
  if (url.pathname !== "/callback") {
2613
2784
  res.statusCode = 404;
2614
2785
  res.end("Not Found");
@@ -2716,6 +2887,12 @@ var HttpConnector = class extends BaseConnector {
2716
2887
  reconnectionOptions;
2717
2888
  transportType = null;
2718
2889
  streamableTransport = null;
2890
+ /**
2891
+ * Creates an HTTP connector.
2892
+ *
2893
+ * @param baseUrl - MCP endpoint URL.
2894
+ * @param opts - Authentication, transport, SDK, and reconnection options.
2895
+ */
2719
2896
  constructor(baseUrl, opts = {}) {
2720
2897
  super(opts);
2721
2898
  const originalUrl = baseUrl.replace(/\/$/, "");
@@ -2833,7 +3010,12 @@ var HttpConnector = class extends BaseConnector {
2833
3010
  }
2834
3011
  return { fallbackReason, is401Error, httpStatusCode };
2835
3012
  }
2836
- /** Establish connection to the MCP implementation via streamable HTTP. */
3013
+ /**
3014
+ * Establishes a streamable HTTP connection to the MCP server.
3015
+ *
3016
+ * @returns A promise that resolves after protocol negotiation completes.
3017
+ * @throws An error with `code: 401` when authentication is required.
3018
+ */
2837
3019
  async connect() {
2838
3020
  if (this.connected) {
2839
3021
  logger.debug("Already connected to MCP implementation");
@@ -3061,6 +3243,11 @@ var HttpConnector = class extends BaseConnector {
3061
3243
  throw err;
3062
3244
  }
3063
3245
  }
3246
+ /**
3247
+ * Returns fields that identify the endpoint and negotiated transport.
3248
+ *
3249
+ * @returns HTTP connector identity metadata.
3250
+ */
3064
3251
  get publicIdentifier() {
3065
3252
  return {
3066
3253
  type: "http",
@@ -3069,7 +3256,11 @@ var HttpConnector = class extends BaseConnector {
3069
3256
  protocolEra: this.protocolEra ?? "unknown"
3070
3257
  };
3071
3258
  }
3072
- /** Get the active transport type (`streamable-http` once connected). */
3259
+ /**
3260
+ * Returns the active transport type.
3261
+ *
3262
+ * @returns `"streamable-http"` after connection, otherwise `null`.
3263
+ */
3073
3264
  getTransportType() {
3074
3265
  return this.transportType;
3075
3266
  }
@@ -3444,7 +3635,7 @@ var MCPConnection = class {
3444
3635
  /**
3445
3636
  * Normalized server metadata for this ready connection.
3446
3637
  *
3447
- * @throws {Error} When called before protocol negotiation completes.
3638
+ * @throws When called before protocol negotiation completes.
3448
3639
  */
3449
3640
  get info() {
3450
3641
  const protocolEra = this.protocolEra;
@@ -3656,12 +3847,10 @@ function isOAuthClientProvider(provider) {
3656
3847
  var BaseMCPClient = class {
3657
3848
  /**
3658
3849
  * Internal configuration object containing MCP server definitions.
3659
- * @protected
3660
3850
  */
3661
3851
  config = {};
3662
3852
  /**
3663
3853
  * Map of server names to their active sessions.
3664
- * @protected
3665
3854
  */
3666
3855
  sessions = {};
3667
3856
  /**
@@ -3705,7 +3894,7 @@ var BaseMCPClient = class {
3705
3894
  *
3706
3895
  * @param _cfg - Configuration dictionary
3707
3896
  * @returns Client instance
3708
- * @throws {Error} If called on the base class instead of a concrete implementation
3897
+ * @throws If called on the base class instead of a concrete implementation
3709
3898
  *
3710
3899
  * @example
3711
3900
  * ```typescript
@@ -3847,7 +4036,7 @@ var BaseMCPClient = class {
3847
4036
  * @param serverName - The name of the server as defined in the client configuration
3848
4037
  * @param autoInitialize - Whether to automatically initialize the session (default: true)
3849
4038
  * @returns A promise that resolves to the created MCPSession instance
3850
- * @throws {Error} If the server is not found in the configuration
4039
+ * @throws If the server is not found in the configuration
3851
4040
  *
3852
4041
  * @example
3853
4042
  * ```typescript
@@ -4017,7 +4206,7 @@ var BaseMCPClient = class {
4017
4206
  *
4018
4207
  * @param serverName - Name of the server
4019
4208
  * @returns The session instance
4020
- * @throws {Error} If the session is not found
4209
+ * @throws If the session is not found
4021
4210
  *
4022
4211
  * @example
4023
4212
  * ```typescript
@@ -4401,20 +4590,24 @@ global.search_tools = async (query, detailLevel = 'full') => {
4401
4590
  for (const [serverName, serverTools] of Object.entries(tools)) {
4402
4591
  if (!serverTools || serverTools.length === 0) continue;
4403
4592
  const safeServerName = serverName.replace(/[^a-zA-Z0-9_]/g, "_");
4593
+ const escapedServerName = JSON.stringify(serverName);
4594
+ const escapedSafeServerName = JSON.stringify(safeServerName);
4404
4595
  shim += `
4405
- global['${serverName}'] = {`;
4596
+ global[${escapedServerName}] = {`;
4406
4597
  for (const tool of serverTools) {
4598
+ const escapedToolName = JSON.stringify(tool.name);
4407
4599
  shim += `
4408
- '${tool.name}': async (args) => await global.__callMcpTool('${serverName}', '${tool.name}', args),`;
4600
+ [${escapedToolName}]: async (args) => await global.__callMcpTool(${escapedServerName}, ${escapedToolName}, args),`;
4409
4601
  }
4410
4602
  shim += `
4411
4603
  };
4412
-
4604
+ `;
4605
+ if (safeServerName !== serverName) {
4606
+ shim += `
4413
4607
  // Also expose as safe name if different
4414
- if ('${safeServerName}' !== '${serverName}') {
4415
- global['${safeServerName}'] = global['${serverName}'];
4416
- }
4608
+ global[${escapedSafeServerName}] = global[${escapedServerName}];
4417
4609
  `;
4610
+ }
4418
4611
  }
4419
4612
  return shim;
4420
4613
  }
@@ -5108,9 +5301,7 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
5108
5301
  * @param config - Configuration object or path to JSON config file. If omitted,
5109
5302
  * starts with empty configuration
5110
5303
  * @param options - Optional client behavior configuration
5111
- * @param options.codeMode - Enable code execution mode (boolean or advanced config)
5112
- * @param options.onSampling - Callback for handling sampling requests from servers
5113
- * @param options.onElicitation - Callback for handling elicitation requests
5304
+ * Options can enable code mode or provide sampling and elicitation callbacks.
5114
5305
  *
5115
5306
  * @example
5116
5307
  * ```typescript
@@ -5211,7 +5402,7 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
5211
5402
  * });
5212
5403
  * ```
5213
5404
  *
5214
- * @see {@link constructor} for direct instantiation
5405
+ * @see {@link MCPClient} for direct instantiation
5215
5406
  * @see {@link fromConfigFile} for loading from file
5216
5407
  */
5217
5408
  static fromDict(cfg, options) {
@@ -5226,7 +5417,7 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
5226
5417
  * @param path - Path to the JSON configuration file
5227
5418
  * @param options - Optional client behavior configuration
5228
5419
  * @returns New MCPClient instance
5229
- * @throws {Error} If the file cannot be read or parsed
5420
+ * @throws If the file cannot be read or parsed
5230
5421
  *
5231
5422
  * @example
5232
5423
  * ```typescript
@@ -5242,7 +5433,7 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
5242
5433
  * });
5243
5434
  * ```
5244
5435
  *
5245
- * @see {@link constructor} for direct instantiation
5436
+ * @see {@link MCPClient} for direct instantiation
5246
5437
  * @see {@link fromDict} for inline configuration
5247
5438
  */
5248
5439
  static fromConfigFile(path2, options) {
@@ -5389,7 +5580,7 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
5389
5580
  * @param code - JavaScript/TypeScript code to execute
5390
5581
  * @param timeout - Optional execution timeout in milliseconds
5391
5582
  * @returns Execution result with output, errors, and return value
5392
- * @throws {Error} If code mode is not enabled
5583
+ * @throws If code mode is not enabled
5393
5584
  *
5394
5585
  * @example
5395
5586
  * ```typescript
@@ -5435,7 +5626,7 @@ var MCPClient = class _MCPClient extends BaseMCPClient {
5435
5626
  * @param query - Optional search query to filter tools (defaults to empty string for all tools)
5436
5627
  * @param detailLevel - Level of detail to return: "names", "descriptions", or "full"
5437
5628
  * @returns Tool search results with matching tools
5438
- * @throws {Error} If code mode is not enabled
5629
+ * @throws If code mode is not enabled
5439
5630
  *
5440
5631
  * @example
5441
5632
  * ```typescript