@mcp-use/client 0.0.0-bootstrap.0 → 2.0.0-beta.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.
Files changed (121) hide show
  1. package/README.md +127 -4
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/auth/browser.d.ts +149 -0
  4. package/dist/auth/browser.d.ts.map +1 -0
  5. package/dist/auth/callback.d.ts +9 -0
  6. package/dist/auth/callback.d.ts.map +1 -0
  7. package/dist/auth/flow.d.ts +23 -0
  8. package/dist/auth/flow.d.ts.map +1 -0
  9. package/dist/auth/node.d.ts +100 -0
  10. package/dist/auth/node.d.ts.map +1 -0
  11. package/dist/auth/popup.d.ts +67 -0
  12. package/dist/auth/popup.d.ts.map +1 -0
  13. package/dist/auth/session-store.d.ts +114 -0
  14. package/dist/auth/session-store.d.ts.map +1 -0
  15. package/dist/auth/storage-file.d.ts +18 -0
  16. package/dist/auth/storage-file.d.ts.map +1 -0
  17. package/dist/auth/storage.d.ts +25 -0
  18. package/dist/auth/storage.d.ts.map +1 -0
  19. package/dist/auth/url.d.ts +17 -0
  20. package/dist/auth/url.d.ts.map +1 -0
  21. package/dist/code-mode/connector.d.ts +27 -0
  22. package/dist/code-mode/connector.d.ts.map +1 -0
  23. package/dist/code-mode/executor-e2b.d.ts +46 -0
  24. package/dist/code-mode/executor-e2b.d.ts.map +1 -0
  25. package/dist/code-mode/executor-vm.d.ts +39 -0
  26. package/dist/code-mode/executor-vm.d.ts.map +1 -0
  27. package/dist/code-mode/executor.d.ts +66 -0
  28. package/dist/code-mode/executor.d.ts.map +1 -0
  29. package/dist/core/base.d.ts +418 -0
  30. package/dist/core/base.d.ts.map +1 -0
  31. package/dist/core/browser.d.ts +20 -0
  32. package/dist/core/browser.d.ts.map +1 -0
  33. package/dist/core/config.d.ts +149 -0
  34. package/dist/core/config.d.ts.map +1 -0
  35. package/dist/core/node.d.ts +441 -0
  36. package/dist/core/node.d.ts.map +1 -0
  37. package/dist/core/session.d.ts +683 -0
  38. package/dist/core/session.d.ts.map +1 -0
  39. package/dist/index-browser.d.ts +25 -0
  40. package/dist/index-browser.d.ts.map +1 -0
  41. package/dist/index-browser.js +4150 -0
  42. package/dist/index-browser.js.map +1 -0
  43. package/dist/index.d.ts +23 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +5598 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/react/McpClientProvider.d.ts +242 -0
  48. package/dist/react/McpClientProvider.d.ts.map +1 -0
  49. package/dist/react/index.d.ts +33 -0
  50. package/dist/react/index.d.ts.map +1 -0
  51. package/dist/react/index.js +7936 -0
  52. package/dist/react/index.js.map +1 -0
  53. package/dist/react/rpc-logger.d.ts +42 -0
  54. package/dist/react/rpc-logger.d.ts.map +1 -0
  55. package/dist/react/storage.d.ts +51 -0
  56. package/dist/react/storage.d.ts.map +1 -0
  57. package/dist/react/types.d.ts +596 -0
  58. package/dist/react/types.d.ts.map +1 -0
  59. package/dist/react/useMcp-helpers.d.ts +99 -0
  60. package/dist/react/useMcp-helpers.d.ts.map +1 -0
  61. package/dist/react/useMcp-operations.d.ts +156 -0
  62. package/dist/react/useMcp-operations.d.ts.map +1 -0
  63. package/dist/react/useMcp.d.ts +48 -0
  64. package/dist/react/useMcp.d.ts.map +1 -0
  65. package/dist/react/useMcpServerQueues.d.ts +376 -0
  66. package/dist/react/useMcpServerQueues.d.ts.map +1 -0
  67. package/dist/react/view/ViewRenderer.d.ts +12 -0
  68. package/dist/react/view/ViewRenderer.d.ts.map +1 -0
  69. package/dist/react/view/ext-apps-bridge.d.ts +3 -0
  70. package/dist/react/view/ext-apps-bridge.d.ts.map +1 -0
  71. package/dist/react/view/parse-custom-props.d.ts +2 -0
  72. package/dist/react/view/parse-custom-props.d.ts.map +1 -0
  73. package/dist/react/view/resolve-view-resource.d.ts +12 -0
  74. package/dist/react/view/resolve-view-resource.d.ts.map +1 -0
  75. package/dist/react/view/sandbox-blob-url.d.ts +25 -0
  76. package/dist/react/view/sandbox-blob-url.d.ts.map +1 -0
  77. package/dist/react/view/types.d.ts +97 -0
  78. package/dist/react/view/types.d.ts.map +1 -0
  79. package/dist/react/view/use-display-mode.d.ts +18 -0
  80. package/dist/react/view/use-display-mode.d.ts.map +1 -0
  81. package/dist/react/view/view-detection.d.ts +4 -0
  82. package/dist/react/view/view-detection.d.ts.map +1 -0
  83. package/dist/telemetry/client-telemetry.d.ts +13 -0
  84. package/dist/telemetry/client-telemetry.d.ts.map +1 -0
  85. package/dist/telemetry/configure-browser.d.ts +2 -0
  86. package/dist/telemetry/configure-browser.d.ts.map +1 -0
  87. package/dist/telemetry/configure-node.d.ts +2 -0
  88. package/dist/telemetry/configure-node.d.ts.map +1 -0
  89. package/dist/telemetry/connector-telemetry.d.ts +8 -0
  90. package/dist/telemetry/connector-telemetry.d.ts.map +1 -0
  91. package/dist/telemetry/events.d.ts +91 -0
  92. package/dist/telemetry/events.d.ts.map +1 -0
  93. package/dist/telemetry/index.d.ts +3 -0
  94. package/dist/telemetry/index.d.ts.map +1 -0
  95. package/dist/telemetry/tel-fetch.d.ts +25 -0
  96. package/dist/telemetry/tel-fetch.d.ts.map +1 -0
  97. package/dist/telemetry/telemetry-browser.d.ts +6 -0
  98. package/dist/telemetry/telemetry-browser.d.ts.map +1 -0
  99. package/dist/telemetry/telemetry-node.d.ts +8 -0
  100. package/dist/telemetry/telemetry-node.d.ts.map +1 -0
  101. package/dist/telemetry/telemetry.d.ts +79 -0
  102. package/dist/telemetry/telemetry.d.ts.map +1 -0
  103. package/dist/transport/base.d.ts +505 -0
  104. package/dist/transport/base.d.ts.map +1 -0
  105. package/dist/transport/connection-manager.d.ts +55 -0
  106. package/dist/transport/connection-manager.d.ts.map +1 -0
  107. package/dist/transport/http.d.ts +74 -0
  108. package/dist/transport/http.d.ts.map +1 -0
  109. package/dist/transport/stdio.d.ts +48 -0
  110. package/dist/transport/stdio.d.ts.map +1 -0
  111. package/dist/utils/elicitation.d.ts +52 -0
  112. package/dist/utils/elicitation.d.ts.map +1 -0
  113. package/dist/utils/favicon.d.ts +6 -0
  114. package/dist/utils/favicon.d.ts.map +1 -0
  115. package/dist/utils/json-schema-validator.d.ts +13 -0
  116. package/dist/utils/json-schema-validator.d.ts.map +1 -0
  117. package/dist/utils/logging.d.ts +32 -0
  118. package/dist/utils/logging.d.ts.map +1 -0
  119. package/dist/utils/version.d.ts +3 -0
  120. package/dist/utils/version.d.ts.map +1 -0
  121. package/package.json +77 -8
@@ -0,0 +1,418 @@
1
+ import type { OAuthClientProvider } from "@modelcontextprotocol/client";
2
+ import type { BaseConnector } from "../transport/base.js";
3
+ import type { AutoOAuthOptions, MCPClientConfigShape, ServerConfig } from "./config.js";
4
+ import { MCPSession } from "./session.js";
5
+ import type { MCPConnection } from "./session.js";
6
+ /**
7
+ * Base MCPClient class with shared functionality across all environments.
8
+ *
9
+ * This abstract class provides the core client logic for managing MCP servers,
10
+ * sessions, and configurations. It works in both Node.js and browser environments
11
+ * by delegating platform-specific operations to concrete implementations.
12
+ *
13
+ * Platform-specific implementations (like {@link MCPClient} for Node.js) should
14
+ * extend this class and override the abstract {@link createConnectorFromConfig}
15
+ * method to provide environment-specific connector creation.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Typically used through concrete implementations
20
+ * import { MCPClient } from "@mcp-use/client";
21
+ *
22
+ * const client = new MCPClient({
23
+ * mcpServers: {
24
+ * 'my-server': {
25
+ * command: 'node',
26
+ * args: ['server.js']
27
+ * }
28
+ * }
29
+ * });
30
+ * ```
31
+ *
32
+ * @see {@link MCPClient} for Node.js-specific implementation
33
+ * @see {@link MCPSession} for session management
34
+ */
35
+ export declare abstract class BaseMCPClient {
36
+ /**
37
+ * Internal configuration object containing MCP server definitions.
38
+ * @protected
39
+ */
40
+ protected config: MCPClientConfigShape;
41
+ /**
42
+ * Map of server names to their active sessions.
43
+ * @protected
44
+ */
45
+ protected sessions: Record<string, MCPSession>;
46
+ /**
47
+ * List of server names that have active sessions.
48
+ * This array is kept in sync with the sessions map and can be used
49
+ * to iterate over active connections.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * console.log(`Active servers: ${client.activeSessions.join(', ')}`);
54
+ * ```
55
+ */
56
+ activeSessions: string[];
57
+ /**
58
+ * Creates a new BaseMCPClient instance.
59
+ *
60
+ * @param config - Optional configuration object with MCP server definitions
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const client = new MCPClient({
65
+ * mcpServers: {
66
+ * 'example': {
67
+ * command: 'node',
68
+ * args: ['server.js']
69
+ * }
70
+ * }
71
+ * });
72
+ * ```
73
+ */
74
+ constructor(config?: MCPClientConfigShape);
75
+ /**
76
+ * Creates a client instance from a configuration dictionary.
77
+ *
78
+ * This static factory method must be implemented by concrete subclasses
79
+ * to provide proper type information and platform-specific initialization.
80
+ *
81
+ * @param _cfg - Configuration dictionary
82
+ * @returns Client instance
83
+ * @throws {Error} If called on the base class instead of a concrete implementation
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const client = MCPClient.fromDict({
88
+ * mcpServers: {
89
+ * 'my-server': { command: 'node', args: ['server.js'] }
90
+ * }
91
+ * });
92
+ * ```
93
+ */
94
+ static fromDict(_cfg: MCPClientConfigShape): BaseMCPClient;
95
+ /**
96
+ * Adds a new MCP server configuration to the client.
97
+ *
98
+ * This method adds or updates a server configuration dynamically without
99
+ * needing to restart the client. The server can then be used to create
100
+ * new sessions.
101
+ *
102
+ * @param name - Unique name for the server
103
+ * @param serverConfig - Server configuration object (connector type, command, args, etc.)
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * client.addServer('new-server', {
108
+ * command: 'python',
109
+ * args: ['server.py']
110
+ * });
111
+ *
112
+ * // Now you can create a session
113
+ * const session = await client.createSession('new-server');
114
+ * ```
115
+ *
116
+ * @see {@link removeServer} for removing servers
117
+ * @see {@link getServerConfig} for retrieving configurations
118
+ */
119
+ addServer(name: string, serverConfig: ServerConfig): void;
120
+ /**
121
+ * Removes an MCP server configuration from the client.
122
+ *
123
+ * This method removes a server configuration and cleans up any active
124
+ * sessions associated with that server. If there's an active session,
125
+ * it will be removed from the active sessions list.
126
+ *
127
+ * @param name - Name of the server to remove
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * // Remove a server configuration
132
+ * await client.removeServer('old-server');
133
+ *
134
+ * // The server name will no longer appear in getServerNames()
135
+ * console.log(client.getServerNames()); // 'old-server' is gone
136
+ * ```
137
+ *
138
+ * @see {@link addServer} for adding servers
139
+ * @see {@link closeSession} for properly closing sessions before removal
140
+ */
141
+ removeServer(name: string): Promise<void>;
142
+ /**
143
+ * Gets the names of all configured MCP servers.
144
+ *
145
+ * @returns Array of server names defined in the configuration
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const serverNames = client.getServerNames();
150
+ * console.log(`Configured servers: ${serverNames.join(', ')}`);
151
+ *
152
+ * // Create sessions for all servers
153
+ * for (const name of serverNames) {
154
+ * await client.createSession(name);
155
+ * }
156
+ * ```
157
+ *
158
+ * @see {@link activeSessions} for servers with active sessions
159
+ */
160
+ getServerNames(): string[];
161
+ /**
162
+ * Gets the configuration for a specific MCP server.
163
+ *
164
+ * @param name - Name of the server
165
+ * @returns Server configuration object, or undefined if not found
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const config = client.getServerConfig('my-server');
170
+ * if (config) {
171
+ * console.log(`Command: ${config.command}`);
172
+ * console.log(`Args: ${config.args.join(' ')}`);
173
+ * }
174
+ * ```
175
+ *
176
+ * @see {@link getConfig} for retrieving the entire configuration
177
+ */
178
+ getServerConfig(name: string): ServerConfig | undefined;
179
+ /**
180
+ * Gets the complete client configuration.
181
+ *
182
+ * @returns Complete configuration object including all server definitions
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const config = client.getConfig();
187
+ * console.log(`Total servers: ${Object.keys(config.mcpServers).length}`);
188
+ * ```
189
+ *
190
+ * @see {@link getServerConfig} for retrieving individual server configurations
191
+ */
192
+ getConfig(): MCPClientConfigShape;
193
+ /**
194
+ * Creates a connector from server configuration.
195
+ *
196
+ * This abstract method must be implemented by platform-specific subclasses
197
+ * to create the appropriate connector type (Stdio, HTTP, WebSocket, etc.)
198
+ * based on the server configuration and runtime environment.
199
+ *
200
+ * @param serverConfig - Server configuration object
201
+ * @returns Platform-specific connector instance
202
+ * @protected
203
+ */
204
+ protected abstract createConnectorFromConfig(serverConfig: ServerConfig): BaseConnector | Promise<BaseConnector>;
205
+ /**
206
+ * Platform OAuth provider used when an HTTP server has no bearer token /
207
+ * `authProvider`. Node and browser entries implement this via their
208
+ * `createOAuthProvider` export.
209
+ */
210
+ protected abstract createDefaultOAuthProvider(serverUrl: string, options?: AutoOAuthOptions): Promise<OAuthClientProvider>;
211
+ /**
212
+ * Creates a new session for connecting to an MCP server.
213
+ *
214
+ * @deprecated Use {@link connect}; modern MCP servers are sessionless.
215
+ *
216
+ * This method initializes a connection to the specified server using the
217
+ * configuration provided during client construction. Sessions manage the
218
+ * lifecycle of connections and provide methods for calling tools, listing
219
+ * resources, and more.
220
+ *
221
+ * If a session already exists for the server, it will be replaced with a new one.
222
+ *
223
+ * @param serverName - The name of the server as defined in the client configuration
224
+ * @param autoInitialize - Whether to automatically initialize the session (default: true)
225
+ * @returns A promise that resolves to the created MCPSession instance
226
+ * @throws {Error} If the server is not found in the configuration
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * // Create and initialize a session
231
+ * const session = await client.createSession('my-server');
232
+ * const tools = await session.listTools();
233
+ *
234
+ * // Create without auto-initialization
235
+ * const session = await client.createSession('my-server', false);
236
+ * await session.connect();
237
+ * await session.initialize();
238
+ * ```
239
+ *
240
+ * @see {@link MCPSession} for session management methods
241
+ * @see {@link closeSession} for closing sessions
242
+ * @see {@link getSession} for retrieving existing sessions
243
+ */
244
+ createSession(serverName: string, autoInitialize?: boolean): Promise<MCPSession>;
245
+ /**
246
+ * Connect to a configured MCP server and return a ready, protocol-neutral
247
+ * connection.
248
+ *
249
+ * The returned connection represents either a legacy sessionful server or a
250
+ * modern sessionless server uniformly. Inspect {@link MCPConnection.info} for
251
+ * the negotiated protocol version and normalized server metadata.
252
+ *
253
+ * @param serverName - The configured server name.
254
+ */
255
+ connect(serverName: string): Promise<MCPConnection>;
256
+ /**
257
+ * Creates sessions for all configured MCP servers.
258
+ *
259
+ * This is a convenience method that iterates through all servers in the
260
+ * configuration and creates a session for each one. Sessions are created
261
+ * sequentially to avoid overwhelming the system.
262
+ *
263
+ * @param autoInitialize - Whether to automatically initialize each session (default: true)
264
+ * @returns A promise that resolves to a map of server names to sessions
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * // Create sessions for all configured servers
269
+ * const sessions = await client.createAllSessions();
270
+ * console.log(`Created ${Object.keys(sessions).length} sessions`);
271
+ *
272
+ * // List tools from all servers
273
+ * for (const [name, session] of Object.entries(sessions)) {
274
+ * const tools = await session.listTools();
275
+ * console.log(`${name}: ${tools.length} tools`);
276
+ * }
277
+ * ```
278
+ *
279
+ * @see {@link createSession} for creating individual sessions
280
+ * @see {@link closeAllSessions} for closing all sessions
281
+ */
282
+ createAllSessions(autoInitialize?: boolean): Promise<Record<string, MCPSession>>;
283
+ /**
284
+ * Connect to every configured server sequentially.
285
+ *
286
+ * Each result uses the same {@link MCPConnection} API regardless of whether
287
+ * the negotiated protocol is legacy/sessionful or modern/sessionless.
288
+ */
289
+ connectAll(): Promise<Record<string, MCPConnection>>;
290
+ /**
291
+ * Retrieves an existing session by server name.
292
+ *
293
+ * This method returns null if no session exists, making it safe for
294
+ * checking session existence without throwing errors.
295
+ *
296
+ * @param serverName - Name of the server
297
+ * @returns The session instance or null if not found
298
+ *
299
+ * @example
300
+ * ```typescript
301
+ * const session = client.getSession('my-server');
302
+ * if (session) {
303
+ * const tools = await session.listTools();
304
+ * } else {
305
+ * console.log('Session not found, creating...');
306
+ * await client.createSession('my-server');
307
+ * }
308
+ * ```
309
+ *
310
+ * @see {@link requireSession} for getting a session that throws if not found
311
+ * @see {@link createSession} for creating sessions
312
+ */
313
+ getSession(serverName: string): MCPSession | null;
314
+ /**
315
+ * Retrieves an existing session by server name, throwing if not found.
316
+ *
317
+ * This method is useful when you need to ensure a session exists before
318
+ * proceeding. It throws a descriptive error if the session is not found.
319
+ *
320
+ * @param serverName - Name of the server
321
+ * @returns The session instance
322
+ * @throws {Error} If the session is not found
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * try {
327
+ * const session = client.requireSession('my-server');
328
+ * const tools = await session.listTools();
329
+ * } catch (error) {
330
+ * console.error('Session not found:', error.message);
331
+ * }
332
+ * ```
333
+ *
334
+ * @see {@link getSession} for a null-returning alternative
335
+ * @see {@link createSession} for creating sessions
336
+ */
337
+ requireSession(serverName: string): MCPSession;
338
+ /**
339
+ * Gets all active sessions as a map of server names to sessions.
340
+ *
341
+ * @returns Map of server names to their active sessions
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * const sessions = client.getAllActiveSessions();
346
+ *
347
+ * // Iterate over all active sessions
348
+ * for (const [name, session] of Object.entries(sessions)) {
349
+ * console.log(`Server: ${name}`);
350
+ * const tools = await session.listTools();
351
+ * console.log(` Tools: ${tools.length}`);
352
+ * }
353
+ * ```
354
+ *
355
+ * @see {@link activeSessions} for just the list of server names
356
+ * @see {@link getSession} for retrieving individual sessions
357
+ */
358
+ getAllActiveSessions(): Record<string, MCPSession>;
359
+ /**
360
+ * Closes a session and cleans up its resources.
361
+ *
362
+ * This method gracefully disconnects from the server and removes the
363
+ * session from the active sessions list. It's safe to call even if
364
+ * the session doesn't exist.
365
+ *
366
+ * @param serverName - Name of the server whose session should be closed
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * // Close a specific session
371
+ * await client.closeSession('my-server');
372
+ *
373
+ * // Verify it's closed
374
+ * console.log(client.activeSessions.includes('my-server')); // false
375
+ * ```
376
+ *
377
+ * @see {@link closeAllSessions} for closing all sessions at once
378
+ * @see {@link createSession} for creating new sessions
379
+ */
380
+ closeSession(serverName: string): Promise<void>;
381
+ /**
382
+ * Closes all active sessions and cleans up their resources.
383
+ *
384
+ * This method iterates through all sessions and attempts to close each one
385
+ * gracefully. If any session fails to close, the error is logged but the
386
+ * method continues to close remaining sessions.
387
+ *
388
+ * This is particularly useful for cleanup on application shutdown.
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * // Clean shutdown
393
+ * try {
394
+ * await client.closeAllSessions();
395
+ * console.log('All sessions closed successfully');
396
+ * } catch (error) {
397
+ * console.error('Error during cleanup:', error);
398
+ * }
399
+ * ```
400
+ *
401
+ * @example
402
+ * ```typescript
403
+ * // Use in application shutdown handler
404
+ * process.on('SIGINT', async () => {
405
+ * console.log('Shutting down...');
406
+ * await client.closeAllSessions();
407
+ * process.exit(0);
408
+ * });
409
+ * ```
410
+ *
411
+ * @see {@link closeSession} for closing individual sessions
412
+ * @see {@link createAllSessions} for creating sessions
413
+ */
414
+ closeAllSessions(): Promise<void>;
415
+ /** Close every active MCP connection. */
416
+ close(): Promise<void>;
417
+ }
418
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/core/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,gBAAgB,EAEhB,oBAAoB,EACpB,YAAY,EACb,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAiBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8BAAsB,aAAa;IACjC;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAM;IAE5C;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAM;IAEpD;;;;;;;;;OASG;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CAAC;IActC;;;;;OAKG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAIjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAQxD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;IAUrD;;;;;;;;;;;;;;;;;;;OAmBG;IACI,oBAAoB,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAMzD;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4B5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACU,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB9C,yCAAyC;IAC5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -0,0 +1,20 @@
1
+ import type { OAuthClientProvider } from "@modelcontextprotocol/client";
2
+ import type { AutoOAuthOptions } from "./config.js";
3
+ import type { BaseConnector } from "../transport/base.js";
4
+ import { BaseMCPClient } from "./base.js";
5
+ export declare class BrowserMCPClient extends BaseMCPClient {
6
+ /**
7
+ * Get the mcp-use package version.
8
+ * Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
9
+ */
10
+ static getPackageVersion(): string;
11
+ constructor(config?: Record<string, any>);
12
+ static fromDict(cfg: Record<string, any>): BrowserMCPClient;
13
+ protected createDefaultOAuthProvider(serverUrl: string, options?: AutoOAuthOptions): Promise<OAuthClientProvider>;
14
+ /**
15
+ * Create a connector from server configuration (Browser version)
16
+ * Supports HTTP connector only
17
+ */
18
+ protected createConnectorFromConfig(serverConfig: Record<string, any>): BaseConnector;
19
+ }
20
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/core/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,aAAa,CAAC;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AA4B1C,qBAAa,gBAAiB,SAAQ,aAAa;IACjD;;;OAGG;WACW,iBAAiB,IAAI,MAAM;gBAI7B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;WAK1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,gBAAgB;cAIlD,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,mBAAmB,CAAC;IAI/B;;;OAGG;IACH,SAAS,CAAC,yBAAyB,CACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAChC,aAAa;CAyDjB"}
@@ -0,0 +1,149 @@
1
+ import type { ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, Notification, AuthProvider, OAuthClientInformation, OAuthClientProvider, Root, RequestTypeMap, RequestOptions, ResultTypeMap, ClientOptions, VersionNegotiationMode } from "@modelcontextprotocol/client";
2
+ import type { BaseConnector, ConnectorInitOptions } from "../transport/base.js";
3
+ import type { ClientInfo } from "../transport/http.js";
4
+ /** Params for `sampling/createMessage` (avoids deprecated `CreateMessageRequest`). */
5
+ export type SamplingCreateMessageParams = RequestTypeMap["sampling/createMessage"]["params"];
6
+ /** Result for `sampling/createMessage` (avoids deprecated `CreateMessageResult`). */
7
+ export type SamplingCreateMessageResult = ResultTypeMap["sampling/createMessage"];
8
+ /** Callback for sampling requests (canonical name). */
9
+ export type OnSamplingCallback = (params: SamplingCreateMessageParams) => Promise<SamplingCreateMessageResult>;
10
+ /** Callback for elicitation requests (canonical name). */
11
+ export type OnElicitationCallback = (params: ElicitRequestFormParams | ElicitRequestURLParams) => Promise<ElicitResult>;
12
+ /** Callback for notifications (canonical name). */
13
+ export type OnNotificationCallback = (notification: Notification) => void | Promise<void>;
14
+ /**
15
+ * Callback options shared by per-server config and global defaults.
16
+ */
17
+ export interface CallbackConfig {
18
+ /**
19
+ * Callback for sampling input.
20
+ *
21
+ * @deprecated Sampling is deprecated by the 2026 protocol. Retained for v1
22
+ * push requests and the v2 `input_required` compatibility window.
23
+ */
24
+ onSampling?: OnSamplingCallback;
25
+ /** Callback for elicitation requests from servers. */
26
+ onElicitation?: OnElicitationCallback;
27
+ /** Callback for notifications from servers. */
28
+ onNotification?: OnNotificationCallback;
29
+ }
30
+ /**
31
+ * Resolves effective callbacks from per-server and global config.
32
+ */
33
+ export declare function resolveCallbacks(perServer: CallbackConfig | undefined, globalDefaults: CallbackConfig | undefined): {
34
+ onSampling?: OnSamplingCallback;
35
+ onElicitation?: OnElicitationCallback;
36
+ onNotification?: OnNotificationCallback;
37
+ };
38
+ /**
39
+ * Base server configuration with common optional fields
40
+ */
41
+ interface BaseServerConfig extends CallbackConfig {
42
+ clientInfo?: ClientInfo;
43
+ /** Initial roots advertised to the server. */
44
+ roots?: Root[];
45
+ /** Options forwarded to the official MCP SDK Client. */
46
+ clientOptions?: ClientOptions;
47
+ /** Default timeout/cancellation options for requests. */
48
+ defaultRequestOptions?: RequestOptions;
49
+ }
50
+ /**
51
+ * Server configuration for STDIO connectors
52
+ */
53
+ export interface StdioServerConfig extends BaseServerConfig {
54
+ command: string;
55
+ args: string[];
56
+ env?: Record<string, string>;
57
+ cwd?: string;
58
+ /**
59
+ * Protocol version negotiation mode. Defaults to `"legacy"` for stdio (the
60
+ * SDK advises against probing for spawn-per-invocation tools). See
61
+ * {@link StdioConnector}.
62
+ */
63
+ protocolNegotiation?: VersionNegotiationMode;
64
+ }
65
+ /**
66
+ * Options forwarded to the platform `createOAuthProvider` when the client
67
+ * auto-provisions OAuth for an HTTP server. Platform-specific fields
68
+ * (e.g. Node `openBrowser`, browser `oauthProxyUrl`) are accepted and ignored
69
+ * by the other runtime.
70
+ */
71
+ export interface AutoOAuthOptions {
72
+ storageKeyPrefix?: string;
73
+ clientName?: string;
74
+ clientUri?: string;
75
+ logoUri?: string;
76
+ callbackUrl?: string;
77
+ clientMetadataUrl?: string;
78
+ scope?: string;
79
+ /** Pre-registered public client id (skips DCR). */
80
+ staticClientInfo?: OAuthClientInformation;
81
+ /** Node: preferred loopback port. */
82
+ preferredPort?: number;
83
+ /** Node: ports to walk on EADDRINUSE. */
84
+ portRange?: number;
85
+ /** Node: loopback wait timeout in ms. */
86
+ authTimeoutMs?: number;
87
+ /** Node: override browser launch (CLI prints the URL instead). */
88
+ openBrowser?: (url: string) => void | Promise<void>;
89
+ /** Browser: wait for explicit authenticate() instead of auto popup. */
90
+ preventAutoAuth?: boolean;
91
+ /** Browser: full-page redirect instead of popup. */
92
+ useRedirectFlow?: boolean;
93
+ /** Browser: same-origin OAuth BFF base URL. */
94
+ oauthProxyUrl?: string;
95
+ /** Browser: route OAuth HTTP through `oauthProxyUrl` (default true when set). */
96
+ proxyOAuthRequests?: boolean;
97
+ }
98
+ /**
99
+ * Server configuration for HTTP connectors
100
+ */
101
+ export interface HttpServerConfig extends BaseServerConfig {
102
+ url: string;
103
+ headers?: Record<string, string>;
104
+ fetch?: typeof fetch;
105
+ authToken?: string;
106
+ /** Connection timeout in milliseconds. */
107
+ timeout?: number;
108
+ authProvider?: AuthProvider | OAuthClientProvider;
109
+ /**
110
+ * Auto-OAuth options for HTTP servers.
111
+ * - omit / `{}`: client creates the platform provider on connect
112
+ * - `false`: disable auto-OAuth (e.g. CLI `--no-oauth`)
113
+ * - object: forwarded to `createOAuthProvider`
114
+ *
115
+ * Ignored when `authProvider` or `authToken` is set, or when `headers`
116
+ * already includes `Authorization`.
117
+ */
118
+ oauth?: AutoOAuthOptions | false;
119
+ /**
120
+ * Protocol version negotiation mode. Defaults to `"auto"` to negotiate both
121
+ * v1 and v2 MCP servers. See {@link HttpConnector}.
122
+ */
123
+ protocolNegotiation?: VersionNegotiationMode;
124
+ }
125
+ /** True when the client should auto-create an OAuth provider for this server. */
126
+ export declare function shouldAutoProvisionOAuth(serverConfig: ServerConfig): serverConfig is HttpServerConfig;
127
+ /**
128
+ * Discriminated union of all supported server configuration types
129
+ */
130
+ export type ServerConfig = StdioServerConfig | HttpServerConfig;
131
+ /**
132
+ * Top-level MCP client configuration shape.
133
+ * May include global callback defaults and clientInfo applied when per-server config omits them.
134
+ */
135
+ export interface MCPClientConfigShape extends CallbackConfig {
136
+ /** Default clientInfo for all servers; overridable per server. */
137
+ clientInfo?: ClientInfo;
138
+ mcpServers?: Record<string, ServerConfig>;
139
+ }
140
+ /**
141
+ * Normalizes and validates clientInfo from config.
142
+ * Ensures required fields (name, version) are present and merges with defaults.
143
+ */
144
+ export declare function normalizeClientInfo(input: unknown): ClientInfo;
145
+ /** Resolve SDK client options, expanding the MCP Apps `views` capability shorthand. */
146
+ export declare function resolveClientOptions(clientOptions: ClientOptions | undefined): ClientOptions | undefined;
147
+ export declare function createConnectorFromConfig(serverConfig: ServerConfig, connectorOptions?: Partial<ConnectorInitOptions>): BaseConnector;
148
+ export {};
149
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACnB,IAAI,EACJ,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,EACb,sBAAsB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAA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