@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.
- package/README.md +127 -4
- package/dist/.tsbuildinfo +1 -0
- package/dist/auth/browser.d.ts +149 -0
- package/dist/auth/browser.d.ts.map +1 -0
- package/dist/auth/callback.d.ts +9 -0
- package/dist/auth/callback.d.ts.map +1 -0
- package/dist/auth/flow.d.ts +23 -0
- package/dist/auth/flow.d.ts.map +1 -0
- package/dist/auth/node.d.ts +100 -0
- package/dist/auth/node.d.ts.map +1 -0
- package/dist/auth/popup.d.ts +67 -0
- package/dist/auth/popup.d.ts.map +1 -0
- package/dist/auth/session-store.d.ts +114 -0
- package/dist/auth/session-store.d.ts.map +1 -0
- package/dist/auth/storage-file.d.ts +18 -0
- package/dist/auth/storage-file.d.ts.map +1 -0
- package/dist/auth/storage.d.ts +25 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/url.d.ts +17 -0
- package/dist/auth/url.d.ts.map +1 -0
- package/dist/code-mode/connector.d.ts +27 -0
- package/dist/code-mode/connector.d.ts.map +1 -0
- package/dist/code-mode/executor-e2b.d.ts +46 -0
- package/dist/code-mode/executor-e2b.d.ts.map +1 -0
- package/dist/code-mode/executor-vm.d.ts +39 -0
- package/dist/code-mode/executor-vm.d.ts.map +1 -0
- package/dist/code-mode/executor.d.ts +66 -0
- package/dist/code-mode/executor.d.ts.map +1 -0
- package/dist/core/base.d.ts +418 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/browser.d.ts +20 -0
- package/dist/core/browser.d.ts.map +1 -0
- package/dist/core/config.d.ts +149 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/node.d.ts +441 -0
- package/dist/core/node.d.ts.map +1 -0
- package/dist/core/session.d.ts +683 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/index-browser.d.ts +25 -0
- package/dist/index-browser.d.ts.map +1 -0
- package/dist/index-browser.js +4150 -0
- package/dist/index-browser.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5598 -0
- package/dist/index.js.map +1 -0
- package/dist/react/McpClientProvider.d.ts +242 -0
- package/dist/react/McpClientProvider.d.ts.map +1 -0
- package/dist/react/index.d.ts +33 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7936 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/rpc-logger.d.ts +42 -0
- package/dist/react/rpc-logger.d.ts.map +1 -0
- package/dist/react/storage.d.ts +51 -0
- package/dist/react/storage.d.ts.map +1 -0
- package/dist/react/types.d.ts +596 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/useMcp-helpers.d.ts +99 -0
- package/dist/react/useMcp-helpers.d.ts.map +1 -0
- package/dist/react/useMcp-operations.d.ts +156 -0
- package/dist/react/useMcp-operations.d.ts.map +1 -0
- package/dist/react/useMcp.d.ts +48 -0
- package/dist/react/useMcp.d.ts.map +1 -0
- package/dist/react/useMcpServerQueues.d.ts +376 -0
- package/dist/react/useMcpServerQueues.d.ts.map +1 -0
- package/dist/react/view/ViewRenderer.d.ts +12 -0
- package/dist/react/view/ViewRenderer.d.ts.map +1 -0
- package/dist/react/view/ext-apps-bridge.d.ts +3 -0
- package/dist/react/view/ext-apps-bridge.d.ts.map +1 -0
- package/dist/react/view/parse-custom-props.d.ts +2 -0
- package/dist/react/view/parse-custom-props.d.ts.map +1 -0
- package/dist/react/view/resolve-view-resource.d.ts +12 -0
- package/dist/react/view/resolve-view-resource.d.ts.map +1 -0
- package/dist/react/view/sandbox-blob-url.d.ts +25 -0
- package/dist/react/view/sandbox-blob-url.d.ts.map +1 -0
- package/dist/react/view/types.d.ts +97 -0
- package/dist/react/view/types.d.ts.map +1 -0
- package/dist/react/view/use-display-mode.d.ts +18 -0
- package/dist/react/view/use-display-mode.d.ts.map +1 -0
- package/dist/react/view/view-detection.d.ts +4 -0
- package/dist/react/view/view-detection.d.ts.map +1 -0
- package/dist/telemetry/client-telemetry.d.ts +13 -0
- package/dist/telemetry/client-telemetry.d.ts.map +1 -0
- package/dist/telemetry/configure-browser.d.ts +2 -0
- package/dist/telemetry/configure-browser.d.ts.map +1 -0
- package/dist/telemetry/configure-node.d.ts +2 -0
- package/dist/telemetry/configure-node.d.ts.map +1 -0
- package/dist/telemetry/connector-telemetry.d.ts +8 -0
- package/dist/telemetry/connector-telemetry.d.ts.map +1 -0
- package/dist/telemetry/events.d.ts +91 -0
- package/dist/telemetry/events.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/tel-fetch.d.ts +25 -0
- package/dist/telemetry/tel-fetch.d.ts.map +1 -0
- package/dist/telemetry/telemetry-browser.d.ts +6 -0
- package/dist/telemetry/telemetry-browser.d.ts.map +1 -0
- package/dist/telemetry/telemetry-node.d.ts +8 -0
- package/dist/telemetry/telemetry-node.d.ts.map +1 -0
- package/dist/telemetry/telemetry.d.ts +79 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/dist/transport/base.d.ts +505 -0
- package/dist/transport/base.d.ts.map +1 -0
- package/dist/transport/connection-manager.d.ts +55 -0
- package/dist/transport/connection-manager.d.ts.map +1 -0
- package/dist/transport/http.d.ts +74 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/stdio.d.ts +48 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/utils/elicitation.d.ts +52 -0
- package/dist/utils/elicitation.d.ts.map +1 -0
- package/dist/utils/favicon.d.ts +6 -0
- package/dist/utils/favicon.d.ts.map +1 -0
- package/dist/utils/json-schema-validator.d.ts +13 -0
- package/dist/utils/json-schema-validator.d.ts.map +1 -0
- package/dist/utils/logging.d.ts +32 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/version.d.ts +3 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/package.json +77 -8
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import type { ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, OAuthClientProvider } from "@modelcontextprotocol/client";
|
|
2
|
+
import { BaseMCPClient } from "./base.js";
|
|
3
|
+
import type { ExecutionResult, ToolSearchResponse } from "../code-mode/executor.js";
|
|
4
|
+
import { BaseCodeExecutor } from "../code-mode/executor.js";
|
|
5
|
+
import { type AutoOAuthOptions, type SamplingCreateMessageParams, type SamplingCreateMessageResult } from "./config.js";
|
|
6
|
+
import type { BaseConnector } from "../transport/base.js";
|
|
7
|
+
/** Read and parse a JSON MCP client config file. Node-only. */
|
|
8
|
+
export declare function loadConfigFile(filepath: string): Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* Custom function type for code execution in code mode.
|
|
11
|
+
* Allows providing a custom executor implementation.
|
|
12
|
+
*/
|
|
13
|
+
export type CodeExecutorFunction = (code: string, timeout?: number) => Promise<ExecutionResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Built-in code executor types.
|
|
16
|
+
* - `"vm"`: Node.js VM-based executor (default, local execution)
|
|
17
|
+
* - `"e2b"`: E2B cloud sandbox executor (secure remote execution)
|
|
18
|
+
*/
|
|
19
|
+
export type CodeExecutorType = "vm" | "e2b";
|
|
20
|
+
/**
|
|
21
|
+
* Configuration options for the VM-based code executor.
|
|
22
|
+
*/
|
|
23
|
+
export interface VMExecutorOptions {
|
|
24
|
+
/** Maximum execution time in milliseconds. Default: 30000 (30 seconds) */
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
/** Memory limit in megabytes. Default: undefined (no limit) */
|
|
27
|
+
memoryLimitMb?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for the E2B cloud sandbox executor.
|
|
31
|
+
*/
|
|
32
|
+
export interface E2BExecutorOptions {
|
|
33
|
+
/** E2B API key (required). Get one at https://e2b.dev */
|
|
34
|
+
apiKey: string;
|
|
35
|
+
/** Maximum execution time in milliseconds. Default: 300000 (5 minutes) */
|
|
36
|
+
timeoutMs?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Union type for executor configuration options.
|
|
40
|
+
*/
|
|
41
|
+
export type ExecutorOptions = VMExecutorOptions | E2BExecutorOptions;
|
|
42
|
+
/**
|
|
43
|
+
* Advanced configuration for code execution mode.
|
|
44
|
+
*/
|
|
45
|
+
export interface CodeModeConfig {
|
|
46
|
+
/** Whether to enable code execution mode */
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
/** Executor type or custom implementation. Defaults to "vm" */
|
|
49
|
+
executor?: CodeExecutorType | CodeExecutorFunction | BaseCodeExecutor;
|
|
50
|
+
/** Type-safe configuration options for the executor */
|
|
51
|
+
executorOptions?: ExecutorOptions;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for configuring MCPClient behavior.
|
|
55
|
+
*/
|
|
56
|
+
export interface MCPClientOptions {
|
|
57
|
+
/** Enable code execution mode (simple boolean or advanced configuration) */
|
|
58
|
+
codeMode?: boolean | CodeModeConfig;
|
|
59
|
+
/**
|
|
60
|
+
* Optional callback function to handle sampling requests from servers.
|
|
61
|
+
* When provided, the client will declare sampling capability and handle
|
|
62
|
+
* `sampling/createMessage` requests by calling this callback.
|
|
63
|
+
*
|
|
64
|
+
* @deprecated Sampling is deprecated by the 2026 protocol. Retained for v1
|
|
65
|
+
* push requests and v2 multi-round-trip compatibility.
|
|
66
|
+
*/
|
|
67
|
+
onSampling?: (params: SamplingCreateMessageParams) => Promise<SamplingCreateMessageResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Optional callback function to handle elicitation requests from servers.
|
|
70
|
+
* When provided, the client will declare elicitation capability and handle
|
|
71
|
+
* `elicitation/create` requests by calling this callback.
|
|
72
|
+
*
|
|
73
|
+
* Elicitation allows servers to request additional information from users:
|
|
74
|
+
* - Form mode: Collect structured data with JSON schema validation
|
|
75
|
+
* - URL mode: Direct users to external URLs for sensitive interactions
|
|
76
|
+
*/
|
|
77
|
+
onElicitation?: (params: ElicitRequestFormParams | ElicitRequestURLParams) => Promise<ElicitResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Optional callback function for server notifications.
|
|
80
|
+
* Applied as default when per-server config does not specify one.
|
|
81
|
+
*/
|
|
82
|
+
onNotification?: (notification: import("@modelcontextprotocol/client").Notification) => void | Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export { BaseCodeExecutor } from "../code-mode/executor.js";
|
|
85
|
+
export { E2BCodeExecutor } from "../code-mode/executor-e2b.js";
|
|
86
|
+
export { isVMAvailable, VMCodeExecutor } from "../code-mode/executor-vm.js";
|
|
87
|
+
export { accept, acceptWithDefaults, applyDefaults, cancel, decline, getDefaults, validate, } from "../utils/elicitation.js";
|
|
88
|
+
export type { ElicitContent, ElicitValidationResult, } from "../utils/elicitation.js";
|
|
89
|
+
export { MCPSession } from "./session.js";
|
|
90
|
+
export type { CallToolResult, MetaObject, Notification, Root, Tool, } from "./session.js";
|
|
91
|
+
/**
|
|
92
|
+
* Node.js-specific MCP client implementation with advanced features.
|
|
93
|
+
*
|
|
94
|
+
* The MCPClient class provides a complete MCP client implementation for Node.js
|
|
95
|
+
* environments, extending {@link BaseMCPClient} with platform-specific capabilities:
|
|
96
|
+
*
|
|
97
|
+
* - **All Connector Types**: Supports Stdio, HTTP, and WebSocket connectors
|
|
98
|
+
* - **Code Execution Mode**: Execute code dynamically using VM or E2B sandboxes
|
|
99
|
+
* - **File System Operations**: Load and save configurations from/to files
|
|
100
|
+
* - **Sampling & Elicitation**: Handle advanced MCP protocol features
|
|
101
|
+
* - **Session Management**: Create and manage multiple server connections
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Basic usage with config file
|
|
106
|
+
* const client = new MCPClient('./mcp-config.json');
|
|
107
|
+
* const session = await client.createSession('my-server');
|
|
108
|
+
* const tools = await session.listTools();
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // With inline configuration
|
|
114
|
+
* const client = new MCPClient({
|
|
115
|
+
* mcpServers: {
|
|
116
|
+
* 'filesystem': {
|
|
117
|
+
* command: 'npx',
|
|
118
|
+
* args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp']
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // With code execution mode
|
|
127
|
+
* const client = new MCPClient('./config.json', {
|
|
128
|
+
* codeMode: {
|
|
129
|
+
* enabled: true,
|
|
130
|
+
* executor: 'e2b',
|
|
131
|
+
* executorOptions: { apiKey: process.env.E2B_API_KEY }
|
|
132
|
+
* }
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* const result = await client.executeCode('console.log("Hello!")');
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @see {@link BaseMCPClient} for base client functionality
|
|
139
|
+
* @see {@link MCPSession} for session management
|
|
140
|
+
*/
|
|
141
|
+
export declare class MCPClient extends BaseMCPClient {
|
|
142
|
+
/**
|
|
143
|
+
* Gets the mcp-use package version.
|
|
144
|
+
*
|
|
145
|
+
* This static method returns the version string of the installed mcp-use package,
|
|
146
|
+
* which is useful for debugging and compatibility checks.
|
|
147
|
+
*
|
|
148
|
+
* @returns The package version string (e.g., "1.13.2")
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* console.log(`mcp-use version: ${MCPClient.getPackageVersion()}`);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
static getPackageVersion(): string;
|
|
156
|
+
/**
|
|
157
|
+
* Indicates whether code execution mode is enabled.
|
|
158
|
+
*
|
|
159
|
+
* When true, the client provides special tools for executing code dynamically
|
|
160
|
+
* through the {@link executeCode} and {@link searchTools} methods.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* if (client.codeMode) {
|
|
165
|
+
* const result = await client.executeCode('return 2 + 2');
|
|
166
|
+
* console.log(result.output); // "4"
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
codeMode: boolean;
|
|
171
|
+
private _codeExecutor;
|
|
172
|
+
private _customCodeExecutor;
|
|
173
|
+
private _codeExecutorConfig;
|
|
174
|
+
private _executorOptions?;
|
|
175
|
+
private _globalCallbacks;
|
|
176
|
+
/**
|
|
177
|
+
* Creates a new MCPClient instance.
|
|
178
|
+
*
|
|
179
|
+
* The client can be initialized with either a configuration object, a path to
|
|
180
|
+
* a configuration file, or no configuration at all (servers can be added later
|
|
181
|
+
* using {@link addServer}).
|
|
182
|
+
*
|
|
183
|
+
* @param config - Configuration object or path to JSON config file. If omitted,
|
|
184
|
+
* starts with empty configuration
|
|
185
|
+
* @param options - Optional client behavior configuration
|
|
186
|
+
* @param options.codeMode - Enable code execution mode (boolean or advanced config)
|
|
187
|
+
* @param options.onSampling - Callback for handling sampling requests from servers
|
|
188
|
+
* @param options.onElicitation - Callback for handling elicitation requests
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* // From config file
|
|
193
|
+
* const client = new MCPClient('./mcp-config.json');
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* // From inline config
|
|
199
|
+
* const client = new MCPClient({
|
|
200
|
+
* mcpServers: {
|
|
201
|
+
* 'my-server': {
|
|
202
|
+
* command: 'node',
|
|
203
|
+
* args: ['server.js']
|
|
204
|
+
* }
|
|
205
|
+
* }
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // With code mode enabled
|
|
212
|
+
* const client = new MCPClient('./config.json', {
|
|
213
|
+
* codeMode: true
|
|
214
|
+
* });
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* // With sampling callback
|
|
220
|
+
* const client = new MCPClient('./config.json', {
|
|
221
|
+
* onSampling: async (params) => {
|
|
222
|
+
* // Call your LLM here
|
|
223
|
+
* return anthropic.messages.create(params);
|
|
224
|
+
* }
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @see {@link fromDict} for creating from config object (alternative syntax)
|
|
229
|
+
* @see {@link fromConfigFile} for creating from file (alternative syntax)
|
|
230
|
+
*/
|
|
231
|
+
constructor(config?: string | Record<string, any>, options?: MCPClientOptions);
|
|
232
|
+
/**
|
|
233
|
+
* Creates a client instance from a configuration dictionary.
|
|
234
|
+
*
|
|
235
|
+
* This static factory method provides an alternative syntax for creating
|
|
236
|
+
* a client from an inline configuration object.
|
|
237
|
+
*
|
|
238
|
+
* @param cfg - Configuration dictionary with server definitions
|
|
239
|
+
* @param options - Optional client behavior configuration
|
|
240
|
+
* @returns New MCPClient instance
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const client = MCPClient.fromDict({
|
|
245
|
+
* mcpServers: {
|
|
246
|
+
* 'filesystem': {
|
|
247
|
+
* command: 'npx',
|
|
248
|
+
* args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp']
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @see {@link constructor} for direct instantiation
|
|
255
|
+
* @see {@link fromConfigFile} for loading from file
|
|
256
|
+
*/
|
|
257
|
+
static fromDict(cfg: Record<string, any>, options?: MCPClientOptions): MCPClient;
|
|
258
|
+
/**
|
|
259
|
+
* Creates a client instance from a configuration file.
|
|
260
|
+
*
|
|
261
|
+
* This static factory method loads MCP server configurations from a JSON
|
|
262
|
+
* file and creates a new client instance.
|
|
263
|
+
*
|
|
264
|
+
* @param path - Path to the JSON configuration file
|
|
265
|
+
* @param options - Optional client behavior configuration
|
|
266
|
+
* @returns New MCPClient instance
|
|
267
|
+
* @throws {Error} If the file cannot be read or parsed
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const client = MCPClient.fromConfigFile('./mcp-config.json');
|
|
272
|
+
* await client.createAllSessions();
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* // With code mode
|
|
278
|
+
* const client = MCPClient.fromConfigFile('./config.json', {
|
|
279
|
+
* codeMode: true
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* @see {@link constructor} for direct instantiation
|
|
284
|
+
* @see {@link fromDict} for inline configuration
|
|
285
|
+
*/
|
|
286
|
+
static fromConfigFile(path: string, options?: MCPClientOptions): MCPClient;
|
|
287
|
+
/**
|
|
288
|
+
* Saves the current configuration to a file.
|
|
289
|
+
*
|
|
290
|
+
* This Node.js-specific method writes the client's current configuration
|
|
291
|
+
* (including all server definitions) to a JSON file. The directory will be
|
|
292
|
+
* created if it doesn't exist.
|
|
293
|
+
*
|
|
294
|
+
* @param filepath - Path where the configuration file should be saved
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const client = new MCPClient();
|
|
299
|
+
* client.addServer('my-server', {
|
|
300
|
+
* command: 'node',
|
|
301
|
+
* args: ['server.js']
|
|
302
|
+
* });
|
|
303
|
+
*
|
|
304
|
+
* // Save configuration for later use
|
|
305
|
+
* client.saveConfig('./mcp-config.json');
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* @see {@link fromConfigFile} for loading configurations
|
|
309
|
+
*/
|
|
310
|
+
saveConfig(filepath: string): void;
|
|
311
|
+
protected createDefaultOAuthProvider(serverUrl: string, options?: AutoOAuthOptions): Promise<OAuthClientProvider>;
|
|
312
|
+
/**
|
|
313
|
+
* Create a connector from server configuration (Node.js version)
|
|
314
|
+
* Supports all connector types including StdioConnector (lazy-loaded to avoid pulling Node-only code into browser bundles).
|
|
315
|
+
*/
|
|
316
|
+
protected createConnectorFromConfig(serverConfig: Record<string, any>): Promise<BaseConnector>;
|
|
317
|
+
private _setupCodeModeConnector;
|
|
318
|
+
private _ensureCodeExecutor;
|
|
319
|
+
/**
|
|
320
|
+
* Executes JavaScript/TypeScript code in a sandboxed environment.
|
|
321
|
+
*
|
|
322
|
+
* This method is only available when code mode is enabled. It executes the
|
|
323
|
+
* provided code in an isolated environment (VM or E2B sandbox) and returns
|
|
324
|
+
* the results including stdout, stderr, and return value.
|
|
325
|
+
*
|
|
326
|
+
* @param code - JavaScript/TypeScript code to execute
|
|
327
|
+
* @param timeout - Optional execution timeout in milliseconds
|
|
328
|
+
* @returns Execution result with output, errors, and return value
|
|
329
|
+
* @throws {Error} If code mode is not enabled
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const client = new MCPClient('./config.json', { codeMode: true });
|
|
334
|
+
*
|
|
335
|
+
* const result = await client.executeCode(`
|
|
336
|
+
* console.log('Hello, world!');
|
|
337
|
+
* return 2 + 2;
|
|
338
|
+
* `);
|
|
339
|
+
*
|
|
340
|
+
* console.log(result.stdout); // "Hello, world!\n"
|
|
341
|
+
* console.log(result.returnValue); // 4
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```typescript
|
|
346
|
+
* // With timeout
|
|
347
|
+
* try {
|
|
348
|
+
* const result = await client.executeCode('while(true) {}', 1000);
|
|
349
|
+
* } catch (error) {
|
|
350
|
+
* console.log('Execution timed out');
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @see {@link searchTools} for discovering available tools in code mode
|
|
355
|
+
*/
|
|
356
|
+
executeCode(code: string, timeout?: number): Promise<ExecutionResult>;
|
|
357
|
+
/**
|
|
358
|
+
* Searches for available tools across all MCP servers.
|
|
359
|
+
*
|
|
360
|
+
* This method is only available when code mode is enabled. It searches
|
|
361
|
+
* through tools from all active servers and returns matching tools based
|
|
362
|
+
* on the query and detail level.
|
|
363
|
+
*
|
|
364
|
+
* @param query - Optional search query to filter tools (defaults to empty string for all tools)
|
|
365
|
+
* @param detailLevel - Level of detail to return: "names", "descriptions", or "full"
|
|
366
|
+
* @returns Tool search results with matching tools
|
|
367
|
+
* @throws {Error} If code mode is not enabled
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const client = new MCPClient('./config.json', { codeMode: true });
|
|
372
|
+
* await client.createAllSessions();
|
|
373
|
+
*
|
|
374
|
+
* // Search for all tools
|
|
375
|
+
* const allTools = await client.searchTools();
|
|
376
|
+
* console.log(`Found ${allTools.tools.length} tools`);
|
|
377
|
+
*
|
|
378
|
+
* // Search for specific tools
|
|
379
|
+
* const fileTools = await client.searchTools('file', 'descriptions');
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* @see {@link executeCode} for executing code in code mode
|
|
383
|
+
*/
|
|
384
|
+
searchTools(query?: string, detailLevel?: "names" | "descriptions" | "full"): Promise<ToolSearchResponse>;
|
|
385
|
+
/**
|
|
386
|
+
* Gets the names of all configured MCP servers (excluding internal servers).
|
|
387
|
+
*
|
|
388
|
+
* This method overrides the base implementation to filter out internal
|
|
389
|
+
* meta-servers like the code mode server, which is an implementation detail
|
|
390
|
+
* not intended for direct user interaction.
|
|
391
|
+
*
|
|
392
|
+
* @returns Array of user-configured server names
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* const names = client.getServerNames();
|
|
397
|
+
* console.log(`User servers: ${names.join(', ')}`);
|
|
398
|
+
* // Note: 'code_mode' is excluded even if code mode is enabled
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @see {@link activeSessions} for servers with active sessions
|
|
402
|
+
*/
|
|
403
|
+
getServerNames(): string[];
|
|
404
|
+
/**
|
|
405
|
+
* Closes the client and cleans up all resources.
|
|
406
|
+
*
|
|
407
|
+
* This method performs a complete cleanup by:
|
|
408
|
+
* 1. Shutting down code executors (VM or E2B sandboxes)
|
|
409
|
+
* 2. Closing all active MCP sessions
|
|
410
|
+
* 3. Releasing any other held resources
|
|
411
|
+
*
|
|
412
|
+
* Always call this method when you're done with the client to ensure
|
|
413
|
+
* proper resource cleanup, especially when using E2B sandboxes which
|
|
414
|
+
* have associated costs.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const client = new MCPClient('./config.json', { codeMode: true });
|
|
419
|
+
* await client.createAllSessions();
|
|
420
|
+
*
|
|
421
|
+
* // Do work...
|
|
422
|
+
*
|
|
423
|
+
* // Clean up
|
|
424
|
+
* await client.close();
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* // Use in shutdown handler
|
|
430
|
+
* process.on('SIGINT', async () => {
|
|
431
|
+
* console.log('Shutting down...');
|
|
432
|
+
* await client.close();
|
|
433
|
+
* process.exit(0);
|
|
434
|
+
* });
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
437
|
+
* @see {@link closeAllSessions} for closing just the sessions
|
|
438
|
+
*/
|
|
439
|
+
close(): Promise<void>;
|
|
440
|
+
}
|
|
441
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/core/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EACn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