@mcp-use/client 2.2.4 → 2.2.5

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 (134) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/auth/browser.d.ts +218 -0
  3. package/dist/auth/browser.d.ts.map +1 -0
  4. package/dist/auth/callback.d.ts +9 -0
  5. package/dist/auth/callback.d.ts.map +1 -0
  6. package/dist/auth/flow.d.ts +32 -0
  7. package/dist/auth/flow.d.ts.map +1 -0
  8. package/dist/auth/node.d.ts +212 -0
  9. package/dist/auth/node.d.ts.map +1 -0
  10. package/dist/auth/popup.d.ts +67 -0
  11. package/dist/auth/popup.d.ts.map +1 -0
  12. package/dist/auth/session-store.d.ts +125 -0
  13. package/dist/auth/session-store.d.ts.map +1 -0
  14. package/dist/auth/storage-file.d.ts +18 -0
  15. package/dist/auth/storage-file.d.ts.map +1 -0
  16. package/dist/auth/storage.d.ts +34 -0
  17. package/dist/auth/storage.d.ts.map +1 -0
  18. package/dist/auth/url.d.ts +17 -0
  19. package/dist/auth/url.d.ts.map +1 -0
  20. package/dist/code-mode/connector.d.ts +27 -0
  21. package/dist/code-mode/connector.d.ts.map +1 -0
  22. package/dist/code-mode/executor-e2b.d.ts +46 -0
  23. package/dist/code-mode/executor-e2b.d.ts.map +1 -0
  24. package/dist/code-mode/executor-vm.d.ts +39 -0
  25. package/dist/code-mode/executor-vm.d.ts.map +1 -0
  26. package/dist/code-mode/executor.d.ts +81 -0
  27. package/dist/code-mode/executor.d.ts.map +1 -0
  28. package/dist/core/base.d.ts +423 -0
  29. package/dist/core/base.d.ts.map +1 -0
  30. package/dist/core/browser.d.ts +32 -0
  31. package/dist/core/browser.d.ts.map +1 -0
  32. package/dist/core/config.d.ts +225 -0
  33. package/dist/core/config.d.ts.map +1 -0
  34. package/dist/core/node.d.ts +437 -0
  35. package/dist/core/node.d.ts.map +1 -0
  36. package/dist/core/session.d.ts +792 -0
  37. package/dist/core/session.d.ts.map +1 -0
  38. package/dist/core/skills.d.ts +47 -0
  39. package/dist/core/skills.d.ts.map +1 -0
  40. package/dist/index-browser.d.ts +26 -0
  41. package/dist/index-browser.d.ts.map +1 -0
  42. package/dist/index-browser.js +4767 -0
  43. package/dist/index-browser.js.map +1 -0
  44. package/dist/index.d.ts +23 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +6113 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/react/McpClientProvider.d.ts +254 -0
  49. package/dist/react/McpClientProvider.d.ts.map +1 -0
  50. package/dist/react/index.d.ts +39 -0
  51. package/dist/react/index.d.ts.map +1 -0
  52. package/dist/react/index.js +9444 -0
  53. package/dist/react/index.js.map +1 -0
  54. package/dist/react/rpc-logger.d.ts +47 -0
  55. package/dist/react/rpc-logger.d.ts.map +1 -0
  56. package/dist/react/storage.d.ts +98 -0
  57. package/dist/react/storage.d.ts.map +1 -0
  58. package/dist/react/token-expiry.d.ts +9 -0
  59. package/dist/react/token-expiry.d.ts.map +1 -0
  60. package/dist/react/types.d.ts +727 -0
  61. package/dist/react/types.d.ts.map +1 -0
  62. package/dist/react/useMcp-helpers.d.ts +99 -0
  63. package/dist/react/useMcp-helpers.d.ts.map +1 -0
  64. package/dist/react/useMcp-operations.d.ts +180 -0
  65. package/dist/react/useMcp-operations.d.ts.map +1 -0
  66. package/dist/react/useMcp.d.ts +48 -0
  67. package/dist/react/useMcp.d.ts.map +1 -0
  68. package/dist/react/useMcpServerQueues.d.ts +403 -0
  69. package/dist/react/useMcpServerQueues.d.ts.map +1 -0
  70. package/dist/react/view/ViewRenderer.d.ts +20 -0
  71. package/dist/react/view/ViewRenderer.d.ts.map +1 -0
  72. package/dist/react/view/ext-apps-bridge.d.ts +3 -0
  73. package/dist/react/view/ext-apps-bridge.d.ts.map +1 -0
  74. package/dist/react/view/initialized-sync.d.ts +13 -0
  75. package/dist/react/view/initialized-sync.d.ts.map +1 -0
  76. package/dist/react/view/inject-openai-file-apis.d.ts +9 -0
  77. package/dist/react/view/inject-openai-file-apis.d.ts.map +1 -0
  78. package/dist/react/view/parse-custom-props.d.ts +10 -0
  79. package/dist/react/view/parse-custom-props.d.ts.map +1 -0
  80. package/dist/react/view/resolve-view-resource.d.ts +22 -0
  81. package/dist/react/view/resolve-view-resource.d.ts.map +1 -0
  82. package/dist/react/view/sandbox-blob-url.d.ts +27 -0
  83. package/dist/react/view/sandbox-blob-url.d.ts.map +1 -0
  84. package/dist/react/view/types.d.ts +220 -0
  85. package/dist/react/view/types.d.ts.map +1 -0
  86. package/dist/react/view/use-display-mode.d.ts +19 -0
  87. package/dist/react/view/use-display-mode.d.ts.map +1 -0
  88. package/dist/react/view/view-detection.d.ts +22 -0
  89. package/dist/react/view/view-detection.d.ts.map +1 -0
  90. package/dist/react/view/view-host-policy.d.ts +61 -0
  91. package/dist/react/view/view-host-policy.d.ts.map +1 -0
  92. package/dist/sandbox.d.ts +2 -0
  93. package/dist/sandbox.d.ts.map +1 -0
  94. package/dist/sandbox.js +288 -0
  95. package/dist/sandbox.js.map +1 -0
  96. package/dist/telemetry/client-telemetry.d.ts +13 -0
  97. package/dist/telemetry/client-telemetry.d.ts.map +1 -0
  98. package/dist/telemetry/configure-browser.d.ts +2 -0
  99. package/dist/telemetry/configure-browser.d.ts.map +1 -0
  100. package/dist/telemetry/configure-node.d.ts +2 -0
  101. package/dist/telemetry/configure-node.d.ts.map +1 -0
  102. package/dist/telemetry/connector-telemetry.d.ts +8 -0
  103. package/dist/telemetry/connector-telemetry.d.ts.map +1 -0
  104. package/dist/telemetry/events.d.ts +91 -0
  105. package/dist/telemetry/events.d.ts.map +1 -0
  106. package/dist/telemetry/index.d.ts +3 -0
  107. package/dist/telemetry/index.d.ts.map +1 -0
  108. package/dist/telemetry/tel-fetch.d.ts +19 -0
  109. package/dist/telemetry/tel-fetch.d.ts.map +1 -0
  110. package/dist/telemetry/telemetry-browser.d.ts +6 -0
  111. package/dist/telemetry/telemetry-browser.d.ts.map +1 -0
  112. package/dist/telemetry/telemetry-node.d.ts +8 -0
  113. package/dist/telemetry/telemetry-node.d.ts.map +1 -0
  114. package/dist/telemetry/telemetry.d.ts +75 -0
  115. package/dist/telemetry/telemetry.d.ts.map +1 -0
  116. package/dist/transport/base.d.ts +656 -0
  117. package/dist/transport/base.d.ts.map +1 -0
  118. package/dist/transport/connection-manager.d.ts +59 -0
  119. package/dist/transport/connection-manager.d.ts.map +1 -0
  120. package/dist/transport/http.d.ts +137 -0
  121. package/dist/transport/http.d.ts.map +1 -0
  122. package/dist/transport/stdio.d.ts +97 -0
  123. package/dist/transport/stdio.d.ts.map +1 -0
  124. package/dist/utils/elicitation.d.ts +54 -0
  125. package/dist/utils/elicitation.d.ts.map +1 -0
  126. package/dist/utils/favicon.d.ts +6 -0
  127. package/dist/utils/favicon.d.ts.map +1 -0
  128. package/dist/utils/json-schema-validator.d.ts +13 -0
  129. package/dist/utils/json-schema-validator.d.ts.map +1 -0
  130. package/dist/utils/logging.d.ts +33 -0
  131. package/dist/utils/logging.d.ts.map +1 -0
  132. package/dist/utils/version.d.ts +9 -0
  133. package/dist/utils/version.d.ts.map +1 -0
  134. package/package.json +1 -1
@@ -0,0 +1,81 @@
1
+ import type { Tool } from "@modelcontextprotocol/client";
2
+ import type { CodeExecutorFunction, MCPClient } from "../core/node.js";
3
+ export interface ExecutionResult {
4
+ result: unknown;
5
+ logs: string[];
6
+ error: string | null;
7
+ execution_time: number;
8
+ }
9
+ interface ToolSearchResult {
10
+ name: string;
11
+ server: string;
12
+ description?: string;
13
+ input_schema?: Tool["inputSchema"];
14
+ }
15
+ interface ToolSearchMeta {
16
+ total_tools: number;
17
+ namespaces: string[];
18
+ result_count: number;
19
+ }
20
+ export interface ToolSearchResponse {
21
+ meta: ToolSearchMeta;
22
+ results: ToolSearchResult[];
23
+ }
24
+ type SearchToolsFunction = (query?: string, detailLevel?: "names" | "descriptions" | "full") => Promise<ToolSearchResponse>;
25
+ interface ToolNamespaceInfo {
26
+ serverName: string;
27
+ tools: Tool[];
28
+ session: any;
29
+ }
30
+ /**
31
+ * Abstract base class for code executors.
32
+ * Provides shared functionality for connecting to MCP servers and building tool contexts.
33
+ */
34
+ export declare abstract class BaseCodeExecutor {
35
+ protected client: MCPClient;
36
+ protected _connecting: boolean;
37
+ constructor(client: MCPClient);
38
+ /**
39
+ * Execute code with access to MCP tools.
40
+ * @param code - The code to execute
41
+ * @param timeout - Execution timeout in milliseconds
42
+ */
43
+ abstract execute(code: string, timeout?: number): Promise<ExecutionResult>;
44
+ /**
45
+ * Clean up resources used by the executor.
46
+ * Should be called when the executor is no longer needed.
47
+ */
48
+ abstract cleanup(): Promise<void>;
49
+ /**
50
+ * Ensure all configured MCP servers are connected before execution.
51
+ * Prevents race conditions with a connection lock.
52
+ */
53
+ protected ensureServersConnected(): Promise<void>;
54
+ /**
55
+ * Get tool namespace information from all active MCP sessions.
56
+ * Filters out the internal code_mode server.
57
+ */
58
+ protected getToolNamespaces(): ToolNamespaceInfo[];
59
+ /**
60
+ * Create a search function for discovering available MCP tools.
61
+ * Used by code execution environments to find tools at runtime.
62
+ */
63
+ createSearchToolsFunction(): SearchToolsFunction;
64
+ }
65
+ /**
66
+ * Adapts a plain `(code, timeout) => Promise<ExecutionResult>` function to the
67
+ * {@link BaseCodeExecutor} interface so a custom executor participates in the
68
+ * normal executor lifecycle (`searchTools`, `close()` cleanup).
69
+ *
70
+ * The function is invoked with the `MCPClient` as its `this`, matching how a
71
+ * custom executor was called before this adapter existed. Cleanup is a no-op:
72
+ * the caller owns whatever runtime the function wraps.
73
+ */
74
+ export declare class FunctionCodeExecutor extends BaseCodeExecutor {
75
+ private fn;
76
+ constructor(client: MCPClient, fn: CodeExecutorFunction);
77
+ execute(code: string, timeout?: number): Promise<ExecutionResult>;
78
+ cleanup(): Promise<void>;
79
+ }
80
+ export {};
81
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../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,GAAG,OAAO,CAAC,eAAe,CAAC;IAE1E;;;OAGG;IACH,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAEjC;;;OAGG;cACa,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BvD;;;OAGG;IACH,SAAS,CAAC,iBAAiB,IAAI,iBAAiB,EAAE;IA6BlD;;;OAGG;IACI,yBAAyB,IAAI,mBAAmB;CAoExD;AAED;;;;;;;;GAQG;AACH,qBAAa,oBAAqB,SAAQ,gBAAgB;IACxD,OAAO,CAAC,EAAE,CAAuB;gBAErB,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,oBAAoB;IAKjD,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIjE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
@@ -0,0 +1,423 @@
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 such as the Node.js `MCPClient` 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 MCPSession} for session management
33
+ */
34
+ export declare abstract class BaseMCPClient {
35
+ /**
36
+ * Internal configuration object containing MCP server definitions.
37
+ */
38
+ protected config: MCPClientConfigShape;
39
+ /**
40
+ * Map of server names to their active sessions.
41
+ */
42
+ protected sessions: Record<string, MCPSession>;
43
+ /**
44
+ * Tracks teardown by session identity so overlapping cleanup paths share the
45
+ * same disconnect. In particular, createSession() can replace a session while
46
+ * closeSession() is already disconnecting it.
47
+ */
48
+ private readonly sessionDisconnects;
49
+ /**
50
+ * List of server names that have active sessions.
51
+ * This array is kept in sync with the sessions map and can be used
52
+ * to iterate over active connections.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * console.log(`Active servers: ${client.activeSessions.join(', ')}`);
57
+ * ```
58
+ */
59
+ activeSessions: string[];
60
+ /**
61
+ * Creates a new BaseMCPClient instance.
62
+ *
63
+ * @param config - Optional configuration object with MCP server definitions
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const client = new MCPClient({
68
+ * mcpServers: {
69
+ * 'example': {
70
+ * command: 'node',
71
+ * args: ['server.js']
72
+ * }
73
+ * }
74
+ * });
75
+ * ```
76
+ */
77
+ constructor(config?: MCPClientConfigShape);
78
+ private disconnectSession;
79
+ /**
80
+ * Creates a client instance from a configuration dictionary.
81
+ *
82
+ * This static factory method must be implemented by concrete subclasses
83
+ * to provide proper type information and platform-specific initialization.
84
+ *
85
+ * @param _cfg - Configuration dictionary
86
+ * @returns Client instance
87
+ * @throws If called on the base class instead of a concrete implementation
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const client = MCPClient.fromDict({
92
+ * mcpServers: {
93
+ * 'my-server': { command: 'node', args: ['server.js'] }
94
+ * }
95
+ * });
96
+ * ```
97
+ */
98
+ static fromDict(_cfg: MCPClientConfigShape): BaseMCPClient;
99
+ /**
100
+ * Adds a new MCP server configuration to the client.
101
+ *
102
+ * This method adds or updates a server configuration dynamically without
103
+ * needing to restart the client. The server can then be used to create
104
+ * new sessions.
105
+ *
106
+ * @param name - Unique name for the server
107
+ * @param serverConfig - Server configuration object (connector type, command, args, etc.)
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * client.addServer('new-server', {
112
+ * command: 'python',
113
+ * args: ['server.py']
114
+ * });
115
+ *
116
+ * // Now you can create a session
117
+ * const session = await client.createSession('new-server');
118
+ * ```
119
+ *
120
+ * @see {@link removeServer} for removing servers
121
+ * @see {@link getServerConfig} for retrieving configurations
122
+ */
123
+ addServer(name: string, serverConfig: ServerConfig): void;
124
+ /**
125
+ * Removes an MCP server configuration from the client.
126
+ *
127
+ * This method removes a server configuration and cleans up any active
128
+ * sessions associated with that server. If there's an active session,
129
+ * it will be removed from the active sessions list.
130
+ *
131
+ * @param name - Name of the server to remove
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Remove a server configuration
136
+ * await client.removeServer('old-server');
137
+ *
138
+ * // The server name will no longer appear in getServerNames()
139
+ * console.log(client.getServerNames()); // 'old-server' is gone
140
+ * ```
141
+ *
142
+ * @see {@link addServer} for adding servers
143
+ * @see {@link closeSession} for properly closing sessions before removal
144
+ */
145
+ removeServer(name: string): Promise<void>;
146
+ /**
147
+ * Gets the names of all configured MCP servers.
148
+ *
149
+ * @returns Array of server names defined in the configuration
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const serverNames = client.getServerNames();
154
+ * console.log(`Configured servers: ${serverNames.join(', ')}`);
155
+ *
156
+ * // Create sessions for all servers
157
+ * for (const name of serverNames) {
158
+ * await client.createSession(name);
159
+ * }
160
+ * ```
161
+ *
162
+ * @see {@link activeSessions} for servers with active sessions
163
+ */
164
+ getServerNames(): string[];
165
+ /**
166
+ * Gets the configuration for a specific MCP server.
167
+ *
168
+ * @param name - Name of the server
169
+ * @returns Server configuration object, or undefined if not found
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * const config = client.getServerConfig('my-server');
174
+ * if (config) {
175
+ * console.log(`Command: ${config.command}`);
176
+ * console.log(`Args: ${config.args.join(' ')}`);
177
+ * }
178
+ * ```
179
+ *
180
+ * @see {@link getConfig} for retrieving the entire configuration
181
+ */
182
+ getServerConfig(name: string): ServerConfig | undefined;
183
+ /**
184
+ * Gets the complete client configuration.
185
+ *
186
+ * @returns Complete configuration object including all server definitions
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const config = client.getConfig();
191
+ * console.log(`Total servers: ${Object.keys(config.mcpServers).length}`);
192
+ * ```
193
+ *
194
+ * @see {@link getServerConfig} for retrieving individual server configurations
195
+ */
196
+ getConfig(): MCPClientConfigShape;
197
+ /**
198
+ * Creates a connector from server configuration.
199
+ *
200
+ * This abstract method must be implemented by platform-specific subclasses
201
+ * to create the appropriate connector type (Stdio, HTTP, WebSocket, etc.)
202
+ * based on the server configuration and runtime environment.
203
+ *
204
+ * @param serverConfig - Server configuration object
205
+ * @returns Platform-specific connector instance
206
+ */
207
+ protected abstract createConnectorFromConfig(serverConfig: ServerConfig): BaseConnector | Promise<BaseConnector>;
208
+ /**
209
+ * Platform OAuth provider used when an HTTP server has no bearer token /
210
+ * `authProvider`. Node and browser entries implement this via their
211
+ * `createOAuthProvider` export.
212
+ */
213
+ protected abstract createDefaultOAuthProvider(serverUrl: string, options?: AutoOAuthOptions): Promise<OAuthClientProvider>;
214
+ /**
215
+ * Creates a new session for connecting to an MCP server.
216
+ *
217
+ * @deprecated Use {@link connect}; modern MCP servers are sessionless.
218
+ *
219
+ * This method initializes a connection to the specified server using the
220
+ * configuration provided during client construction. Sessions manage the
221
+ * lifecycle of connections and provide methods for calling tools, listing
222
+ * resources, and more.
223
+ *
224
+ * If a session already exists for the server, it will be replaced with a new
225
+ * one and the previous session is disconnected; any previously returned
226
+ * reference to it becomes unusable.
227
+ *
228
+ * @param serverName - The name of the server as defined in the client configuration
229
+ * @param autoInitialize - Whether to automatically initialize the session (default: true)
230
+ * @returns A promise that resolves to the created MCPSession instance
231
+ * @throws If the server is not found in the configuration
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * // Create and initialize a session
236
+ * const session = await client.createSession('my-server');
237
+ * const tools = await session.listTools();
238
+ *
239
+ * // Create without auto-initialization
240
+ * const session = await client.createSession('my-server', false);
241
+ * await session.connect();
242
+ * await session.initialize();
243
+ * ```
244
+ *
245
+ * @see {@link MCPSession} for session management methods
246
+ * @see {@link closeSession} for closing sessions
247
+ * @see {@link getSession} for retrieving existing sessions
248
+ */
249
+ createSession(serverName: string, autoInitialize?: boolean): Promise<MCPSession>;
250
+ /**
251
+ * Connect to a configured MCP server and return a ready, protocol-neutral
252
+ * connection.
253
+ *
254
+ * The returned connection represents either a legacy sessionful server or a
255
+ * modern sessionless server uniformly. Inspect {@link MCPConnection.info} for
256
+ * the negotiated protocol version and normalized server metadata.
257
+ *
258
+ * @param serverName - The configured server name.
259
+ */
260
+ connect(serverName: string): Promise<MCPConnection>;
261
+ /**
262
+ * Creates sessions for all configured MCP servers.
263
+ *
264
+ * This is a convenience method that iterates through all servers in the
265
+ * configuration and creates a session for each one. Sessions are created
266
+ * sequentially to avoid overwhelming the system.
267
+ *
268
+ * @param autoInitialize - Whether to automatically initialize each session (default: true)
269
+ * @returns A promise that resolves to a map of server names to sessions
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * // Create sessions for all configured servers
274
+ * const sessions = await client.createAllSessions();
275
+ * console.log(`Created ${Object.keys(sessions).length} sessions`);
276
+ *
277
+ * // List tools from all servers
278
+ * for (const [name, session] of Object.entries(sessions)) {
279
+ * const tools = await session.listTools();
280
+ * console.log(`${name}: ${tools.length} tools`);
281
+ * }
282
+ * ```
283
+ *
284
+ * @see {@link createSession} for creating individual sessions
285
+ * @see {@link closeAllSessions} for closing all sessions
286
+ */
287
+ createAllSessions(autoInitialize?: boolean): Promise<Record<string, MCPSession>>;
288
+ /**
289
+ * Connect to every configured server sequentially.
290
+ *
291
+ * Each result uses the same {@link MCPConnection} API regardless of whether
292
+ * the negotiated protocol is legacy/sessionful or modern/sessionless.
293
+ */
294
+ connectAll(): Promise<Record<string, MCPConnection>>;
295
+ /**
296
+ * Retrieves an existing session by server name.
297
+ *
298
+ * This method returns null if no session exists, making it safe for
299
+ * checking session existence without throwing errors.
300
+ *
301
+ * @param serverName - Name of the server
302
+ * @returns The session instance or null if not found
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * const session = client.getSession('my-server');
307
+ * if (session) {
308
+ * const tools = await session.listTools();
309
+ * } else {
310
+ * console.log('Session not found, creating...');
311
+ * await client.createSession('my-server');
312
+ * }
313
+ * ```
314
+ *
315
+ * @see {@link requireSession} for getting a session that throws if not found
316
+ * @see {@link createSession} for creating sessions
317
+ */
318
+ getSession(serverName: string): MCPSession | null;
319
+ /**
320
+ * Retrieves an existing session by server name, throwing if not found.
321
+ *
322
+ * This method is useful when you need to ensure a session exists before
323
+ * proceeding. It throws a descriptive error if the session is not found.
324
+ *
325
+ * @param serverName - Name of the server
326
+ * @returns The session instance
327
+ * @throws If the session is not found
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * try {
332
+ * const session = client.requireSession('my-server');
333
+ * const tools = await session.listTools();
334
+ * } catch (error) {
335
+ * console.error('Session not found:', error.message);
336
+ * }
337
+ * ```
338
+ *
339
+ * @see {@link getSession} for a null-returning alternative
340
+ * @see {@link createSession} for creating sessions
341
+ */
342
+ requireSession(serverName: string): MCPSession;
343
+ /**
344
+ * Gets all active sessions as a map of server names to sessions.
345
+ *
346
+ * @returns Map of server names to their active sessions
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * const sessions = client.getAllActiveSessions();
351
+ *
352
+ * // Iterate over all active sessions
353
+ * for (const [name, session] of Object.entries(sessions)) {
354
+ * console.log(`Server: ${name}`);
355
+ * const tools = await session.listTools();
356
+ * console.log(` Tools: ${tools.length}`);
357
+ * }
358
+ * ```
359
+ *
360
+ * @see {@link activeSessions} for just the list of server names
361
+ * @see {@link getSession} for retrieving individual sessions
362
+ */
363
+ getAllActiveSessions(): Record<string, MCPSession>;
364
+ /**
365
+ * Closes a session and cleans up its resources.
366
+ *
367
+ * This method gracefully disconnects from the server and removes the
368
+ * session from the active sessions list. It's safe to call even if
369
+ * the session doesn't exist.
370
+ *
371
+ * @param serverName - Name of the server whose session should be closed
372
+ *
373
+ * @example
374
+ * ```typescript
375
+ * // Close a specific session
376
+ * await client.closeSession('my-server');
377
+ *
378
+ * // Verify it's closed
379
+ * console.log(client.activeSessions.includes('my-server')); // false
380
+ * ```
381
+ *
382
+ * @see {@link closeAllSessions} for closing all sessions at once
383
+ * @see {@link createSession} for creating new sessions
384
+ */
385
+ closeSession(serverName: string): Promise<void>;
386
+ /**
387
+ * Closes all active sessions and cleans up their resources.
388
+ *
389
+ * This method iterates through all sessions and attempts to close each one
390
+ * gracefully. If any session fails to close, the error is logged but the
391
+ * method continues to close remaining sessions.
392
+ *
393
+ * This is particularly useful for cleanup on application shutdown.
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * // Clean shutdown
398
+ * try {
399
+ * await client.closeAllSessions();
400
+ * console.log('All sessions closed successfully');
401
+ * } catch (error) {
402
+ * console.error('Error during cleanup:', error);
403
+ * }
404
+ * ```
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * // Use in application shutdown handler
409
+ * process.on('SIGINT', async () => {
410
+ * console.log('Shutting down...');
411
+ * await client.closeAllSessions();
412
+ * process.exit(0);
413
+ * });
414
+ * ```
415
+ *
416
+ * @see {@link closeSession} for closing individual sessions
417
+ * @see {@link createAllSessions} for creating sessions
418
+ */
419
+ closeAllSessions(): Promise<void>;
420
+ /** Close every active MCP connection. */
421
+ close(): Promise<void>;
422
+ }
423
+ //# 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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0B,CAC3C,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,mBAAmB,CAAC;IAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACU,aAAa,CACxB,UAAU,EAAE,MAAM,EAClB,cAAc,UAAO,GACpB,OAAO,CAAC,UAAU,CAAC;IAiGtB;;;;;;;;;OASG;IACU,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAIhE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,iBAAiB,CAC5B,cAAc,UAAO,GACpB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,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,32 @@
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
+ * Returns the installed `@mcp-use/client` package version.
8
+ *
9
+ * @returns The package version string.
10
+ */
11
+ static getPackageVersion(): string;
12
+ /**
13
+ * Creates a browser MCP client.
14
+ *
15
+ * @param config - Client configuration containing an optional `mcpServers` map.
16
+ */
17
+ constructor(config?: Record<string, any>);
18
+ /**
19
+ * Creates a browser client from an inline configuration object.
20
+ *
21
+ * @param cfg - Client configuration containing an optional `mcpServers` map.
22
+ * @returns A browser client initialized with `cfg`.
23
+ */
24
+ static fromDict(cfg: Record<string, any>): BrowserMCPClient;
25
+ protected createDefaultOAuthProvider(serverUrl: string, options?: AutoOAuthOptions): Promise<OAuthClientProvider>;
26
+ /**
27
+ * Create a connector from server configuration (Browser version)
28
+ * Supports HTTP connector only
29
+ */
30
+ protected createConnectorFromConfig(serverConfig: Record<string, any>): BaseConnector;
31
+ }
32
+ //# 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;AA0B1C,qBAAa,gBAAiB,SAAQ,aAAa;IACjD;;;;OAIG;WACW,iBAAiB,IAAI,MAAM;IAIzC;;;;OAIG;gBACS,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAKxC;;;;;OAKG;WACW,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;CA2DjB"}