mcp-use 1.0.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/README.md +190 -2
- package/dist/{chunk-4DEFXVWT.js → chunk-CWWNPIJZ.js} +2 -2
- package/dist/{chunk-JXLQRAW2.js → chunk-MZPKOZE4.js} +129 -17
- package/dist/{chunk-YUSC6R6V.js → chunk-TJXUCAST.js} +1 -1
- package/dist/index.cjs +239 -31
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -17
- package/dist/src/browser.cjs +1 -1
- package/dist/src/browser.js +1 -1
- package/dist/src/connectors/base.d.ts +579 -59
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/react/index.cjs +2 -2
- package/dist/src/react/index.js +2 -2
- package/dist/src/server/index.cjs +128 -17
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +1 -3
- package/dist/src/server/mcp-server.d.ts +66 -4
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types.d.ts +39 -7
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
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
|
-
/**
|
3192
|
-
|
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
|
-
|
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.
|
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 ===
|
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
|
-
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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
|
-
*
|
3982
|
-
*
|
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
|
-
|
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
|
-
|
4001
|
-
|
4002
|
-
|
4003
|
-
|
4004
|
-
|
4005
|
-
|
4006
|
-
|
4007
|
-
|
4008
|
-
|
4009
|
-
|
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 || "
|
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 || "
|
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
|
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';
|
package/dist/index.d.ts.map
CHANGED
@@ -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,EAAE,MAAM,8BAA8B,CAAA;AAG7F,OAAO,EAAE,eAAe,EAAE,
|
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,EAAE,MAAM,8BAA8B,CAAA;AAG7F,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAGxE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC9F,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGrH,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACpF,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAGtD,cAAc,sBAAsB,CAAA;AAGpC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAG3G,YAAY,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-
|
3
|
+
} from "./chunk-CWWNPIJZ.js";
|
4
4
|
import {
|
5
5
|
BrowserOAuthClientProvider,
|
6
6
|
onMcpAuthorization
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-TJXUCAST.js";
|
8
8
|
import {
|
9
|
-
McpServer,
|
10
9
|
createMCPServer
|
11
|
-
} from "./chunk-
|
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
|
-
/**
|
2683
|
-
|
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
|
-
|
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.
|
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 ===
|
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
|
-
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,
|
package/dist/src/browser.cjs
CHANGED
@@ -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 || "
|
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")
|