mcp-use 0.3.0 → 1.0.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/index.cjs CHANGED
@@ -486,7 +486,6 @@ __export(index_exports, {
486
486
  MCPAgent: () => MCPAgent,
487
487
  MCPClient: () => MCPClient,
488
488
  MCPSession: () => MCPSession,
489
- McpServer: () => McpServer,
490
489
  OAuthHelper: () => OAuthHelper,
491
490
  ObservabilityManager: () => ObservabilityManager,
492
491
  ReleaseMCPServerConnectionTool: () => ReleaseMCPServerConnectionTool,
@@ -3188,13 +3187,52 @@ var BaseConnector = class {
3188
3187
  logger.debug(`Tool '${name}' returned`, res);
3189
3188
  return res;
3190
3189
  }
3191
- /** List resources from the server. */
3192
- async listResources(options) {
3190
+ /**
3191
+ * List resources from the server with optional pagination
3192
+ *
3193
+ * @param cursor - Optional cursor for pagination
3194
+ * @param options - Request options
3195
+ * @returns Resource list with optional nextCursor for pagination
3196
+ */
3197
+ async listResources(cursor, options) {
3198
+ if (!this.client) {
3199
+ throw new Error("MCP client is not connected");
3200
+ }
3201
+ logger.debug("Listing resources", cursor ? `with cursor: ${cursor}` : "");
3202
+ return await this.client.listResources({ cursor }, options);
3203
+ }
3204
+ /**
3205
+ * List all resources from the server, automatically handling pagination
3206
+ *
3207
+ * @param options - Request options
3208
+ * @returns Complete list of all resources
3209
+ */
3210
+ async listAllResources(options) {
3193
3211
  if (!this.client) {
3194
3212
  throw new Error("MCP client is not connected");
3195
3213
  }
3196
- logger.debug("Listing resources");
3197
- return await this.client.listResources(void 0, options);
3214
+ logger.debug("Listing all resources (with auto-pagination)");
3215
+ const allResources = [];
3216
+ let cursor = void 0;
3217
+ do {
3218
+ const result = await this.client.listResources({ cursor }, options);
3219
+ allResources.push(...result.resources || []);
3220
+ cursor = result.nextCursor;
3221
+ } while (cursor);
3222
+ return { resources: allResources };
3223
+ }
3224
+ /**
3225
+ * List resource templates from the server
3226
+ *
3227
+ * @param options - Request options
3228
+ * @returns List of available resource templates
3229
+ */
3230
+ async listResourceTemplates(options) {
3231
+ if (!this.client) {
3232
+ throw new Error("MCP client is not connected");
3233
+ }
3234
+ logger.debug("Listing resource templates");
3235
+ return await this.client.listResourceTemplates(void 0, options);
3198
3236
  }
3199
3237
  /** Read a resource by URI. */
3200
3238
  async readResource(uri, options) {
@@ -3205,6 +3243,32 @@ var BaseConnector = class {
3205
3243
  const res = await this.client.readResource({ uri }, options);
3206
3244
  return { content: res.content, mimeType: res.mimeType };
3207
3245
  }
3246
+ /**
3247
+ * Subscribe to resource updates
3248
+ *
3249
+ * @param uri - URI of the resource to subscribe to
3250
+ * @param options - Request options
3251
+ */
3252
+ async subscribeToResource(uri, options) {
3253
+ if (!this.client) {
3254
+ throw new Error("MCP client is not connected");
3255
+ }
3256
+ logger.debug(`Subscribing to resource: ${uri}`);
3257
+ return await this.client.subscribeResource({ uri }, options);
3258
+ }
3259
+ /**
3260
+ * Unsubscribe from resource updates
3261
+ *
3262
+ * @param uri - URI of the resource to unsubscribe from
3263
+ * @param options - Request options
3264
+ */
3265
+ async unsubscribeFromResource(uri, options) {
3266
+ if (!this.client) {
3267
+ throw new Error("MCP client is not connected");
3268
+ }
3269
+ logger.debug(`Unsubscribing from resource: ${uri}`);
3270
+ return await this.client.unsubscribeResource({ uri }, options);
3271
+ }
3208
3272
  async listPrompts() {
3209
3273
  if (!this.client) {
3210
3274
  throw new Error("MCP client is not connected");
@@ -3301,12 +3365,16 @@ var HttpConnector = class extends BaseConnector {
3301
3365
  }
3302
3366
  logger.debug(`Connecting to MCP implementation via HTTP: ${baseUrl}`);
3303
3367
  try {
3304
- logger.debug("Attempting streamable HTTP transport...");
3368
+ logger.info("\u{1F504} Attempting streamable HTTP transport...");
3305
3369
  await this.connectWithStreamableHttp(baseUrl);
3370
+ logger.info("\u2705 Successfully connected via streamable HTTP");
3306
3371
  } catch (err) {
3307
3372
  let fallbackReason = "Unknown error";
3308
3373
  if (err instanceof import_streamableHttp2.StreamableHTTPError) {
3309
- if (err.code === 404 || err.code === 405) {
3374
+ if (err.code === 400 && err.message.includes("Missing session ID")) {
3375
+ fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
3376
+ logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
3377
+ } else if (err.code === 404 || err.code === 405) {
3310
3378
  fallbackReason = `Server returned ${err.code} - server likely doesn't support streamable HTTP`;
3311
3379
  logger.debug(fallbackReason);
3312
3380
  } else {
@@ -3315,7 +3383,11 @@ var HttpConnector = class extends BaseConnector {
3315
3383
  }
3316
3384
  } else if (err instanceof Error) {
3317
3385
  const errorStr = err.toString();
3318
- if (errorStr.includes("405 Method Not Allowed") || errorStr.includes("404 Not Found")) {
3386
+ const errorMsg = err.message || "";
3387
+ if (errorStr.includes("Missing session ID") || errorStr.includes("Bad Request: Missing session ID") || errorMsg.includes("FastMCP session ID error")) {
3388
+ fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
3389
+ logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
3390
+ } else if (errorStr.includes("405 Method Not Allowed") || errorStr.includes("404 Not Found")) {
3319
3391
  fallbackReason = "Server doesn't support streamable HTTP (405/404)";
3320
3392
  logger.debug(fallbackReason);
3321
3393
  } else {
@@ -3323,7 +3395,7 @@ var HttpConnector = class extends BaseConnector {
3323
3395
  logger.debug(fallbackReason);
3324
3396
  }
3325
3397
  }
3326
- logger.debug("Falling back to SSE transport...");
3398
+ logger.info("\u{1F504} Falling back to SSE transport...");
3327
3399
  try {
3328
3400
  await this.connectWithSse(baseUrl);
3329
3401
  } catch (sseErr) {
@@ -3354,7 +3426,19 @@ var HttpConnector = class extends BaseConnector {
3354
3426
  );
3355
3427
  const transport = await this.connectionManager.start();
3356
3428
  this.client = new import_client.Client(this.clientInfo, this.opts.clientOptions);
3357
- await this.client.connect(transport);
3429
+ try {
3430
+ await this.client.connect(transport);
3431
+ } catch (connectErr) {
3432
+ if (connectErr instanceof Error) {
3433
+ const errMsg = connectErr.message || connectErr.toString();
3434
+ if (errMsg.includes("Missing session ID") || errMsg.includes("Bad Request: Missing session ID")) {
3435
+ const wrappedError = new Error(`FastMCP session ID error: ${errMsg}`);
3436
+ wrappedError.cause = connectErr;
3437
+ throw wrappedError;
3438
+ }
3439
+ }
3440
+ throw connectErr;
3441
+ }
3358
3442
  this.connected = true;
3359
3443
  this.transportType = "streamable-http";
3360
3444
  logger.debug(`Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`);
@@ -3678,14 +3762,26 @@ var WebSocketConnector = class extends BaseConnector {
3678
3762
  logger.debug("Received unsolicited message", data);
3679
3763
  }
3680
3764
  }, "onMessage");
3681
- socket.addEventListener ? socket.addEventListener("message", onMessage) : socket.on("message", onMessage);
3765
+ if (socket.addEventListener) {
3766
+ socket.addEventListener("message", onMessage);
3767
+ } else {
3768
+ socket.on("message", onMessage);
3769
+ }
3682
3770
  return new Promise((resolve) => {
3683
3771
  const onClose = /* @__PURE__ */ __name(() => {
3684
- socket.removeEventListener ? socket.removeEventListener("message", onMessage) : socket.off("message", onMessage);
3772
+ if (socket.removeEventListener) {
3773
+ socket.removeEventListener("message", onMessage);
3774
+ } else {
3775
+ socket.off("message", onMessage);
3776
+ }
3685
3777
  this.rejectAll(new Error("WebSocket closed"));
3686
3778
  resolve();
3687
3779
  }, "onClose");
3688
- socket.addEventListener ? socket.addEventListener("close", onClose) : socket.on("close", onClose);
3780
+ if (socket.addEventListener) {
3781
+ socket.addEventListener("close", onClose);
3782
+ } else {
3783
+ socket.on("close", onClose);
3784
+ }
3689
3785
  });
3690
3786
  }
3691
3787
  rejectAll(err) {
@@ -3941,6 +4037,7 @@ var McpServer = class {
3941
4037
  version: config2.version
3942
4038
  });
3943
4039
  this.app = (0, import_express.default)();
4040
+ this.app.use(import_express.default.json());
3944
4041
  this.app.use((req, res, next) => {
3945
4042
  res.header("Access-Control-Allow-Origin", "*");
3946
4043
  res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
@@ -3969,7 +4066,10 @@ var McpServer = class {
3969
4066
  * @param resourceDefinition - Configuration object containing resource metadata and handler function
3970
4067
  * @param resourceDefinition.name - Unique identifier for the resource
3971
4068
  * @param resourceDefinition.uri - URI pattern for accessing the resource
3972
- * @param resourceDefinition.resource - Resource metadata (mime type, description, etc.)
4069
+ * @param resourceDefinition.title - Optional human-readable title for the resource
4070
+ * @param resourceDefinition.description - Optional description of the resource
4071
+ * @param resourceDefinition.mimeType - MIME type of the resource content
4072
+ * @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
3973
4073
  * @param resourceDefinition.fn - Async function that returns the resource content
3974
4074
  * @returns The server instance for method chaining
3975
4075
  *
@@ -3978,8 +4078,20 @@ var McpServer = class {
3978
4078
  * server.resource({
3979
4079
  * name: 'config',
3980
4080
  * uri: 'config://app-settings',
3981
- * resource: { mimeType: 'application/json' },
3982
- * fn: async () => ({ theme: 'dark', language: 'en' })
4081
+ * title: 'Application Settings',
4082
+ * mimeType: 'application/json',
4083
+ * description: 'Current application configuration',
4084
+ * annotations: {
4085
+ * audience: ['user'],
4086
+ * priority: 0.8
4087
+ * },
4088
+ * fn: async () => ({
4089
+ * contents: [{
4090
+ * uri: 'config://app-settings',
4091
+ * mimeType: 'application/json',
4092
+ * text: JSON.stringify({ theme: 'dark', language: 'en' })
4093
+ * }]
4094
+ * })
3983
4095
  * })
3984
4096
  * ```
3985
4097
  */
@@ -3987,7 +4099,13 @@ var McpServer = class {
3987
4099
  this.server.resource(
3988
4100
  resourceDefinition.name,
3989
4101
  resourceDefinition.uri,
3990
- resourceDefinition.resource,
4102
+ {
4103
+ name: resourceDefinition.name,
4104
+ title: resourceDefinition.title,
4105
+ description: resourceDefinition.description,
4106
+ mimeType: resourceDefinition.mimeType,
4107
+ annotations: resourceDefinition.annotations
4108
+ },
3991
4109
  async () => {
3992
4110
  return await resourceDefinition.fn();
3993
4111
  }
@@ -3996,18 +4114,76 @@ var McpServer = class {
3996
4114
  }
3997
4115
  /**
3998
4116
  * Define a dynamic resource template with parameters
4117
+ *
4118
+ * Registers a parameterized resource template with the MCP server. Templates use URI
4119
+ * patterns with placeholders that can be filled in at request time, allowing dynamic
4120
+ * resource generation based on parameters.
4121
+ *
4122
+ * @param resourceTemplateDefinition - Configuration object for the resource template
4123
+ * @param resourceTemplateDefinition.name - Unique identifier for the template
4124
+ * @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
4125
+ * @param resourceTemplateDefinition.fn - Async function that generates resource content from URI and params
4126
+ * @returns The server instance for method chaining
4127
+ *
4128
+ * @example
4129
+ * ```typescript
4130
+ * server.resourceTemplate({
4131
+ * name: 'user-profile',
4132
+ * resourceTemplate: {
4133
+ * uriTemplate: 'user://{userId}/profile',
4134
+ * name: 'User Profile',
4135
+ * mimeType: 'application/json'
4136
+ * },
4137
+ * fn: async (uri, params) => ({
4138
+ * contents: [{
4139
+ * uri: uri.toString(),
4140
+ * mimeType: 'application/json',
4141
+ * text: JSON.stringify({ userId: params.userId, name: 'John Doe' })
4142
+ * }]
4143
+ * })
4144
+ * })
4145
+ * ```
3999
4146
  */
4000
- // TODO implement, for some freaky reason this give errors
4001
- // resourceTemplate(resourceTemplateDefinition: ResourceTemplateDefinition): this {
4002
- // this.server.resource(
4003
- // resourceTemplateDefinition.name,
4004
- // resourceTemplateDefinition.resourceTemplate,
4005
- // async (uri, params) => {
4006
- // return await resourceTemplateDefinition.fn(uri, params)
4007
- // },
4008
- // )
4009
- // return this
4010
- // }
4147
+ resourceTemplate(resourceTemplateDefinition) {
4148
+ const template = new import_mcp.ResourceTemplate(
4149
+ resourceTemplateDefinition.resourceTemplate.uriTemplate,
4150
+ {
4151
+ list: void 0,
4152
+ // Optional: callback to list all matching resources
4153
+ complete: void 0
4154
+ // Optional: callback for auto-completion
4155
+ }
4156
+ );
4157
+ const metadata = {};
4158
+ if (resourceTemplateDefinition.resourceTemplate.name) {
4159
+ metadata.name = resourceTemplateDefinition.resourceTemplate.name;
4160
+ }
4161
+ if (resourceTemplateDefinition.title) {
4162
+ metadata.title = resourceTemplateDefinition.title;
4163
+ }
4164
+ if (resourceTemplateDefinition.description || resourceTemplateDefinition.resourceTemplate.description) {
4165
+ metadata.description = resourceTemplateDefinition.description || resourceTemplateDefinition.resourceTemplate.description;
4166
+ }
4167
+ if (resourceTemplateDefinition.resourceTemplate.mimeType) {
4168
+ metadata.mimeType = resourceTemplateDefinition.resourceTemplate.mimeType;
4169
+ }
4170
+ if (resourceTemplateDefinition.annotations) {
4171
+ metadata.annotations = resourceTemplateDefinition.annotations;
4172
+ }
4173
+ this.server.resource(
4174
+ resourceTemplateDefinition.name,
4175
+ template,
4176
+ metadata,
4177
+ async (uri) => {
4178
+ const params = this.parseTemplateUri(
4179
+ resourceTemplateDefinition.resourceTemplate.uriTemplate,
4180
+ uri.toString()
4181
+ );
4182
+ return await resourceTemplateDefinition.fn(uri, params);
4183
+ }
4184
+ );
4185
+ return this;
4186
+ }
4011
4187
  /**
4012
4188
  * Define a tool that can be called by clients
4013
4189
  *
@@ -4389,6 +4565,39 @@ var McpServer = class {
4389
4565
  const matches = uriTemplate.match(/\{([^}]+)\}/g);
4390
4566
  return matches ? matches.map((match) => match.slice(1, -1)) : [];
4391
4567
  }
4568
+ /**
4569
+ * Parse parameter values from a URI based on a template
4570
+ *
4571
+ * Extracts parameter values from an actual URI by matching it against a URI template.
4572
+ * The template contains placeholders like {param} which are extracted as key-value pairs.
4573
+ *
4574
+ * @param template - URI template with placeholders (e.g., "user://{userId}/posts/{postId}")
4575
+ * @param uri - Actual URI to parse (e.g., "user://123/posts/456")
4576
+ * @returns Object mapping parameter names to their values
4577
+ *
4578
+ * @example
4579
+ * ```typescript
4580
+ * const params = this.parseTemplateUri("user://{userId}/posts/{postId}", "user://123/posts/456")
4581
+ * // Returns: { userId: "123", postId: "456" }
4582
+ * ```
4583
+ */
4584
+ parseTemplateUri(template, uri) {
4585
+ const params = {};
4586
+ let regexPattern = template.replace(/[.*+?^$()[\]\\|]/g, "\\$&");
4587
+ const paramNames = [];
4588
+ regexPattern = regexPattern.replace(/\\\{([^}]+)\\\}/g, (_, paramName) => {
4589
+ paramNames.push(paramName);
4590
+ return "([^/]+)";
4591
+ });
4592
+ const regex = new RegExp(`^${regexPattern}$`);
4593
+ const match = uri.match(regex);
4594
+ if (match) {
4595
+ paramNames.forEach((paramName, index) => {
4596
+ params[paramName] = match[index + 1];
4597
+ });
4598
+ }
4599
+ return params;
4600
+ }
4392
4601
  };
4393
4602
  function createMCPServer(name, config2 = {}) {
4394
4603
  const instance = new McpServer({
@@ -4781,7 +4990,7 @@ var BrowserOAuthClientProvider = class {
4781
4990
  this.serverUrl = serverUrl;
4782
4991
  this.storageKeyPrefix = options.storageKeyPrefix || "mcp:auth";
4783
4992
  this.serverUrlHash = this.hashString(serverUrl);
4784
- this.clientName = options.clientName || "MCP Browser Client";
4993
+ this.clientName = options.clientName || "mcp-use";
4785
4994
  this.clientUri = options.clientUri || (typeof window !== "undefined" ? window.location.origin : "");
4786
4995
  this.callbackUrl = (0, import_strict_url_sanitise.sanitizeUrl)(
4787
4996
  options.callbackUrl || (typeof window !== "undefined" ? new URL("/oauth/callback", window.location.origin).toString() : "/oauth/callback")
@@ -5202,7 +5411,7 @@ function useMcp(options) {
5202
5411
  }
5203
5412
  if (!clientRef.current) {
5204
5413
  clientRef.current = new import_client3.Client(
5205
- { name: clientConfig.name || "use-mcp-react-client", version: clientConfig.version || "0.1.0" },
5414
+ { name: clientConfig.name || "mcp-use", version: clientConfig.version || "0.1.0" },
5206
5415
  { capabilities: {} }
5207
5416
  );
5208
5417
  addLog("debug", "MCP Client initialized in connect.");
@@ -5738,7 +5947,6 @@ var import_messages3 = require("@langchain/core/messages");
5738
5947
  MCPAgent,
5739
5948
  MCPClient,
5740
5949
  MCPSession,
5741
- McpServer,
5742
5950
  OAuthHelper,
5743
5951
  ObservabilityManager,
5744
5952
  ReleaseMCPServerConnectionTool,
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export * from './src/agents/utils/index.js';
13
13
  export { ServerManager } from './src/managers/server_manager.js';
14
14
  export * from './src/managers/tools/index.js';
15
15
  export { type ObservabilityConfig, ObservabilityManager } from './src/observability/index.js';
16
- export { createMCPServer, McpServer } from './src/server/index.js';
16
+ export { createMCPServer } from './src/server/index.js';
17
17
  export type { InputDefinition, PromptDefinition, PromptHandler, ResourceDefinition, ResourceHandler, ServerConfig, ToolDefinition, ToolHandler, } from './src/server/types.js';
18
18
  export { setTelemetrySource, Telemetry } from './src/telemetry/index.js';
19
19
  export { OAuthHelper, LINEAR_OAUTH_CONFIG, createOAuthMCPConfig } from './src/oauth-helper.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAEvE,cAAc,6BAA6B,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAEhE,cAAc,+BAA+B,CAAA;AAG7C,OAAO,EAAE,KAAK,mBAAmB,EAAE,oBAAoB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EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAA"}
package/dist/index.js CHANGED
@@ -1,14 +1,13 @@
1
1
  import {
2
2
  useMcp
3
- } from "./chunk-4DEFXVWT.js";
3
+ } from "./chunk-CWWNPIJZ.js";
4
4
  import {
5
5
  BrowserOAuthClientProvider,
6
6
  onMcpAuthorization
7
- } from "./chunk-YUSC6R6V.js";
7
+ } from "./chunk-TJXUCAST.js";
8
8
  import {
9
- McpServer,
10
9
  createMCPServer
11
- } from "./chunk-JXLQRAW2.js";
10
+ } from "./chunk-MZPKOZE4.js";
12
11
  import {
13
12
  Logger,
14
13
  logger
@@ -2679,13 +2678,52 @@ var BaseConnector = class {
2679
2678
  logger.debug(`Tool '${name}' returned`, res);
2680
2679
  return res;
2681
2680
  }
2682
- /** List resources from the server. */
2683
- async listResources(options) {
2681
+ /**
2682
+ * List resources from the server with optional pagination
2683
+ *
2684
+ * @param cursor - Optional cursor for pagination
2685
+ * @param options - Request options
2686
+ * @returns Resource list with optional nextCursor for pagination
2687
+ */
2688
+ async listResources(cursor, options) {
2689
+ if (!this.client) {
2690
+ throw new Error("MCP client is not connected");
2691
+ }
2692
+ logger.debug("Listing resources", cursor ? `with cursor: ${cursor}` : "");
2693
+ return await this.client.listResources({ cursor }, options);
2694
+ }
2695
+ /**
2696
+ * List all resources from the server, automatically handling pagination
2697
+ *
2698
+ * @param options - Request options
2699
+ * @returns Complete list of all resources
2700
+ */
2701
+ async listAllResources(options) {
2684
2702
  if (!this.client) {
2685
2703
  throw new Error("MCP client is not connected");
2686
2704
  }
2687
- logger.debug("Listing resources");
2688
- return await this.client.listResources(void 0, options);
2705
+ logger.debug("Listing all resources (with auto-pagination)");
2706
+ const allResources = [];
2707
+ let cursor = void 0;
2708
+ do {
2709
+ const result = await this.client.listResources({ cursor }, options);
2710
+ allResources.push(...result.resources || []);
2711
+ cursor = result.nextCursor;
2712
+ } while (cursor);
2713
+ return { resources: allResources };
2714
+ }
2715
+ /**
2716
+ * List resource templates from the server
2717
+ *
2718
+ * @param options - Request options
2719
+ * @returns List of available resource templates
2720
+ */
2721
+ async listResourceTemplates(options) {
2722
+ if (!this.client) {
2723
+ throw new Error("MCP client is not connected");
2724
+ }
2725
+ logger.debug("Listing resource templates");
2726
+ return await this.client.listResourceTemplates(void 0, options);
2689
2727
  }
2690
2728
  /** Read a resource by URI. */
2691
2729
  async readResource(uri, options) {
@@ -2696,6 +2734,32 @@ var BaseConnector = class {
2696
2734
  const res = await this.client.readResource({ uri }, options);
2697
2735
  return { content: res.content, mimeType: res.mimeType };
2698
2736
  }
2737
+ /**
2738
+ * Subscribe to resource updates
2739
+ *
2740
+ * @param uri - URI of the resource to subscribe to
2741
+ * @param options - Request options
2742
+ */
2743
+ async subscribeToResource(uri, options) {
2744
+ if (!this.client) {
2745
+ throw new Error("MCP client is not connected");
2746
+ }
2747
+ logger.debug(`Subscribing to resource: ${uri}`);
2748
+ return await this.client.subscribeResource({ uri }, options);
2749
+ }
2750
+ /**
2751
+ * Unsubscribe from resource updates
2752
+ *
2753
+ * @param uri - URI of the resource to unsubscribe from
2754
+ * @param options - Request options
2755
+ */
2756
+ async unsubscribeFromResource(uri, options) {
2757
+ if (!this.client) {
2758
+ throw new Error("MCP client is not connected");
2759
+ }
2760
+ logger.debug(`Unsubscribing from resource: ${uri}`);
2761
+ return await this.client.unsubscribeResource({ uri }, options);
2762
+ }
2699
2763
  async listPrompts() {
2700
2764
  if (!this.client) {
2701
2765
  throw new Error("MCP client is not connected");
@@ -2792,12 +2856,16 @@ var HttpConnector = class extends BaseConnector {
2792
2856
  }
2793
2857
  logger.debug(`Connecting to MCP implementation via HTTP: ${baseUrl}`);
2794
2858
  try {
2795
- logger.debug("Attempting streamable HTTP transport...");
2859
+ logger.info("\u{1F504} Attempting streamable HTTP transport...");
2796
2860
  await this.connectWithStreamableHttp(baseUrl);
2861
+ logger.info("\u2705 Successfully connected via streamable HTTP");
2797
2862
  } catch (err) {
2798
2863
  let fallbackReason = "Unknown error";
2799
2864
  if (err instanceof StreamableHTTPError) {
2800
- if (err.code === 404 || err.code === 405) {
2865
+ if (err.code === 400 && err.message.includes("Missing session ID")) {
2866
+ fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
2867
+ logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
2868
+ } else if (err.code === 404 || err.code === 405) {
2801
2869
  fallbackReason = `Server returned ${err.code} - server likely doesn't support streamable HTTP`;
2802
2870
  logger.debug(fallbackReason);
2803
2871
  } else {
@@ -2806,7 +2874,11 @@ var HttpConnector = class extends BaseConnector {
2806
2874
  }
2807
2875
  } else if (err instanceof Error) {
2808
2876
  const errorStr = err.toString();
2809
- if (errorStr.includes("405 Method Not Allowed") || errorStr.includes("404 Not Found")) {
2877
+ const errorMsg = err.message || "";
2878
+ if (errorStr.includes("Missing session ID") || errorStr.includes("Bad Request: Missing session ID") || errorMsg.includes("FastMCP session ID error")) {
2879
+ fallbackReason = "Server requires session ID (FastMCP compatibility) - using SSE transport";
2880
+ logger.warn(`\u26A0\uFE0F ${fallbackReason}`);
2881
+ } else if (errorStr.includes("405 Method Not Allowed") || errorStr.includes("404 Not Found")) {
2810
2882
  fallbackReason = "Server doesn't support streamable HTTP (405/404)";
2811
2883
  logger.debug(fallbackReason);
2812
2884
  } else {
@@ -2814,7 +2886,7 @@ var HttpConnector = class extends BaseConnector {
2814
2886
  logger.debug(fallbackReason);
2815
2887
  }
2816
2888
  }
2817
- logger.debug("Falling back to SSE transport...");
2889
+ logger.info("\u{1F504} Falling back to SSE transport...");
2818
2890
  try {
2819
2891
  await this.connectWithSse(baseUrl);
2820
2892
  } catch (sseErr) {
@@ -2845,7 +2917,19 @@ var HttpConnector = class extends BaseConnector {
2845
2917
  );
2846
2918
  const transport = await this.connectionManager.start();
2847
2919
  this.client = new Client(this.clientInfo, this.opts.clientOptions);
2848
- await this.client.connect(transport);
2920
+ try {
2921
+ await this.client.connect(transport);
2922
+ } catch (connectErr) {
2923
+ if (connectErr instanceof Error) {
2924
+ const errMsg = connectErr.message || connectErr.toString();
2925
+ if (errMsg.includes("Missing session ID") || errMsg.includes("Bad Request: Missing session ID")) {
2926
+ const wrappedError = new Error(`FastMCP session ID error: ${errMsg}`);
2927
+ wrappedError.cause = connectErr;
2928
+ throw wrappedError;
2929
+ }
2930
+ }
2931
+ throw connectErr;
2932
+ }
2849
2933
  this.connected = true;
2850
2934
  this.transportType = "streamable-http";
2851
2935
  logger.debug(`Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`);
@@ -3165,14 +3249,26 @@ var WebSocketConnector = class extends BaseConnector {
3165
3249
  logger.debug("Received unsolicited message", data);
3166
3250
  }
3167
3251
  }, "onMessage");
3168
- socket.addEventListener ? socket.addEventListener("message", onMessage) : socket.on("message", onMessage);
3252
+ if (socket.addEventListener) {
3253
+ socket.addEventListener("message", onMessage);
3254
+ } else {
3255
+ socket.on("message", onMessage);
3256
+ }
3169
3257
  return new Promise((resolve) => {
3170
3258
  const onClose = /* @__PURE__ */ __name(() => {
3171
- socket.removeEventListener ? socket.removeEventListener("message", onMessage) : socket.off("message", onMessage);
3259
+ if (socket.removeEventListener) {
3260
+ socket.removeEventListener("message", onMessage);
3261
+ } else {
3262
+ socket.off("message", onMessage);
3263
+ }
3172
3264
  this.rejectAll(new Error("WebSocket closed"));
3173
3265
  resolve();
3174
3266
  }, "onClose");
3175
- socket.addEventListener ? socket.addEventListener("close", onClose) : socket.on("close", onClose);
3267
+ if (socket.addEventListener) {
3268
+ socket.addEventListener("close", onClose);
3269
+ } else {
3270
+ socket.on("close", onClose);
3271
+ }
3176
3272
  });
3177
3273
  }
3178
3274
  rejectAll(err) {
@@ -3743,7 +3839,6 @@ export {
3743
3839
  MCPAgent,
3744
3840
  MCPClient,
3745
3841
  MCPSession,
3746
- McpServer,
3747
3842
  OAuthHelper,
3748
3843
  ObservabilityManager,
3749
3844
  ReleaseMCPServerConnectionTool,
@@ -44,7 +44,7 @@ var BrowserOAuthClientProvider = class {
44
44
  this.serverUrl = serverUrl;
45
45
  this.storageKeyPrefix = options.storageKeyPrefix || "mcp:auth";
46
46
  this.serverUrlHash = this.hashString(serverUrl);
47
- this.clientName = options.clientName || "MCP Browser Client";
47
+ this.clientName = options.clientName || "mcp-use";
48
48
  this.clientUri = options.clientUri || (typeof window !== "undefined" ? window.location.origin : "");
49
49
  this.callbackUrl = (0, import_strict_url_sanitise.sanitizeUrl)(
50
50
  options.callbackUrl || (typeof window !== "undefined" ? new URL("/oauth/callback", window.location.origin).toString() : "/oauth/callback")
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  BrowserOAuthClientProvider,
3
3
  onMcpAuthorization
4
- } from "../chunk-YUSC6R6V.js";
4
+ } from "../chunk-TJXUCAST.js";
5
5
  import "../chunk-SHUYVCID.js";
6
6
  export {
7
7
  BrowserOAuthClientProvider,