mcp-use 1.9.1-canary.1 → 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.
- package/README.md +9 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/chunk-6EYDSXO6.js +942 -0
- package/dist/{chunk-D22NUQTL.js → chunk-BFSVTG6G.js} +213 -12
- package/dist/{chunk-33U4IA4N.js → chunk-BPP5XYP6.js} +99 -5
- package/dist/{chunk-3R5PDYIN.js → chunk-J75I2C26.js} +39 -11
- package/dist/{chunk-MUZ5WYE3.js → chunk-NBSNYHID.js} +22 -13
- package/dist/{chunk-U5BX3ISQ.js → chunk-NRALSDBH.js} +22 -408
- package/dist/{chunk-ZQUCGISK.js → chunk-PL645KUX.js} +21 -5
- package/dist/{chunk-QREDNTLS.js → chunk-ZMA4JG4C.js} +1 -1
- package/dist/index.cjs +854 -122
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -23
- package/dist/src/adapters/langchain_adapter.d.ts +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/index.cjs +2071 -1620
- package/dist/src/agents/index.js +4 -4
- package/dist/src/agents/mcp_agent.d.ts +5 -0
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/auth/browser-provider.d.ts +2 -2
- package/dist/src/auth/browser-provider.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.cjs +39 -11
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/types.d.ts +1 -1
- package/dist/src/auth/types.d.ts.map +1 -1
- package/dist/src/browser.cjs +3299 -2601
- package/dist/src/browser.d.ts +2 -1
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +10 -5
- package/dist/src/client/browser.d.ts +5 -0
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/connectors/codeMode.d.ts +1 -1
- package/dist/src/client/connectors/codeMode.d.ts.map +1 -1
- package/dist/src/client/executors/base.d.ts +1 -1
- package/dist/src/client/executors/base.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +13 -4
- package/dist/src/client/prompts.js +3 -2
- package/dist/src/client.d.ts +7 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +56 -6
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts +1 -1
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/oauth-helper.d.ts.map +1 -1
- package/dist/src/react/WidgetControls.d.ts.map +1 -1
- package/dist/src/react/index.cjs +1098 -47
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +5 -5
- package/dist/src/react/types.d.ts +1 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts +4 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1723 -274
- package/dist/src/server/index.d.ts +3 -2
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +488 -245
- package/dist/src/server/mcp-server.d.ts +77 -27
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/oauth/middleware.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/auth0.d.ts +1 -1
- package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/custom.d.ts +4 -2
- package/dist/src/server/oauth/providers/custom.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/keycloak.d.ts +1 -1
- package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/supabase.d.ts +1 -1
- package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/types.d.ts +9 -5
- package/dist/src/server/oauth/providers/types.d.ts.map +1 -1
- package/dist/src/server/oauth/providers.d.ts +27 -9
- package/dist/src/server/oauth/providers.d.ts.map +1 -1
- package/dist/src/server/oauth/setup.d.ts +5 -4
- package/dist/src/server/oauth/setup.d.ts.map +1 -1
- package/dist/src/server/oauth/utils.d.ts +3 -2
- package/dist/src/server/oauth/utils.d.ts.map +1 -1
- package/dist/src/server/prompts/conversion.d.ts +1 -1
- package/dist/src/server/prompts/conversion.d.ts.map +1 -1
- package/dist/src/server/prompts/index.d.ts +6 -5
- package/dist/src/server/prompts/index.d.ts.map +1 -1
- package/dist/src/server/resources/conversion.d.ts +1 -1
- package/dist/src/server/resources/conversion.d.ts.map +1 -1
- package/dist/src/server/resources/index.d.ts +44 -25
- package/dist/src/server/resources/index.d.ts.map +1 -1
- package/dist/src/server/resources/subscriptions.d.ts +1 -1
- package/dist/src/server/resources/subscriptions.d.ts.map +1 -1
- package/dist/src/server/sessions/session-manager.d.ts +11 -5
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts +31 -8
- package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
- package/dist/src/server/tools/tool-registration.d.ts +21 -7
- package/dist/src/server/tools/tool-registration.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +25 -9
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +3 -3
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +3 -2
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +60 -10
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool-context.d.ts +116 -1
- package/dist/src/server/types/tool-context.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +43 -2
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +11 -1
- package/dist/src/server/types/widget.d.ts.map +1 -1
- package/dist/src/server/utils/response-helpers.d.ts +17 -29
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/index.d.ts +3 -3
- package/dist/src/server/widgets/index.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/server/widgets/ui-resource-registration.d.ts +13 -25
- package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-helpers.d.ts +11 -6
- package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-types.d.ts +3 -3
- package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
- package/dist/src/session.d.ts +372 -2
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/sse.d.ts +2 -2
- package/dist/src/task_managers/sse.d.ts.map +1 -1
- package/dist/src/task_managers/stdio.d.ts +2 -2
- package/dist/src/task_managers/stdio.d.ts.map +1 -1
- package/dist/src/task_managers/streamable_http.d.ts +2 -2
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts +219 -0
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +56 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/src/version.d.ts +8 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/{tool-execution-helpers-BQJTPWPN.js → tool-execution-helpers-XFVBSRXM.js} +3 -2
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +6 -5
- package/dist/chunk-MTHLLDCX.js +0 -97
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseConnector
|
|
3
|
-
} from "./chunk-
|
|
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
|
|
273
|
+
import { Client } from "@mcp-use/modelcontextprotocol-sdk/client/index.js";
|
|
89
274
|
import {
|
|
90
275
|
StreamableHTTPClientTransport,
|
|
91
276
|
StreamableHTTPError
|
|
92
|
-
} from "@modelcontextprotocol
|
|
277
|
+
} from "@mcp-use/modelcontextprotocol-sdk/client/streamableHttp.js";
|
|
93
278
|
|
|
94
279
|
// src/task_managers/sse.ts
|
|
95
|
-
import { SSEClientTransport } from "@modelcontextprotocol
|
|
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
|
-
|
|
307
|
-
|
|
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 (
|
|
311
|
-
fallbackReason = `Server returned ${
|
|
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 ${
|
|
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-
|
|
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
|
|
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: ${
|
|
232
|
-
|
|
239
|
+
`Elicitation data validation failed: ${err.message}`,
|
|
240
|
+
err
|
|
233
241
|
);
|
|
234
242
|
}
|
|
235
243
|
}
|
|
@@ -302,10 +310,79 @@ function createLogMethod(sendNotification, minLogLevel) {
|
|
|
302
310
|
logger: logger || "tool"
|
|
303
311
|
}
|
|
304
312
|
});
|
|
313
|
+
Telemetry.getInstance().trackServerContext({
|
|
314
|
+
contextType: "notification",
|
|
315
|
+
notificationType: "message"
|
|
316
|
+
}).catch(
|
|
317
|
+
(e) => console.debug(`Failed to track notification context: ${e}`)
|
|
318
|
+
);
|
|
305
319
|
};
|
|
306
320
|
}
|
|
307
321
|
__name(createLogMethod, "createLogMethod");
|
|
308
|
-
function
|
|
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) {
|
|
309
386
|
const enhancedContext = baseContext ? Object.create(baseContext) : {};
|
|
310
387
|
enhancedContext.sample = createSampleMethod(
|
|
311
388
|
createMessage,
|
|
@@ -318,6 +395,23 @@ function createEnhancedContext(baseContext, createMessage, elicitInput, progress
|
|
|
318
395
|
sendNotification
|
|
319
396
|
);
|
|
320
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
|
+
}
|
|
321
415
|
return enhancedContext;
|
|
322
416
|
}
|
|
323
417
|
__name(createEnhancedContext, "createEnhancedContext");
|
|
@@ -261,7 +261,7 @@ var BrowserOAuthClientProvider = class {
|
|
|
261
261
|
};
|
|
262
262
|
|
|
263
263
|
// src/auth/callback.ts
|
|
264
|
-
import { auth } from "@modelcontextprotocol
|
|
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
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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:`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BrowserMCPClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BFSVTG6G.js";
|
|
4
4
|
import {
|
|
5
5
|
BrowserOAuthClientProvider,
|
|
6
6
|
sanitizeUrl
|
|
7
|
-
} from "./chunk-
|
|
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
|
|
264
|
-
|
|
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
|
|
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(
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1230
|
+
const err = error;
|
|
1231
|
+
setActionResult(`Error: ${err.message}`);
|
|
1223
1232
|
}
|
|
1224
1233
|
}, "handleSetState");
|
|
1225
1234
|
const handleFullscreen = /* @__PURE__ */ __name(async () => {
|