mcp-use
Version:
Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.
106 lines • 4.71 kB
TypeScript
import type { CreateMessageRequest, CreateMessageResult, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult } from "@modelcontextprotocol/sdk/types.js";
import { BaseMCPClient } from "./client/base.js";
import type { ExecutionResult } from "./client/codeExecutor.js";
import { BaseCodeExecutor } from "./client/codeExecutor.js";
import type { BaseConnector } from "./connectors/base.js";
export type CodeExecutorFunction = (code: string, timeout?: number) => Promise<ExecutionResult>;
export type CodeExecutorType = "vm" | "e2b";
export interface VMExecutorOptions {
timeoutMs?: number;
memoryLimitMb?: number;
}
export interface E2BExecutorOptions {
apiKey: string;
timeoutMs?: number;
}
export type ExecutorOptions = VMExecutorOptions | E2BExecutorOptions;
export interface CodeModeConfig {
enabled: boolean;
executor?: CodeExecutorType | CodeExecutorFunction | BaseCodeExecutor;
executorOptions?: ExecutorOptions;
}
export interface MCPClientOptions {
codeMode?: boolean | CodeModeConfig;
/**
* Optional callback function to handle sampling requests from servers.
* When provided, the client will declare sampling capability and handle
* `sampling/createMessage` requests by calling this callback.
*/
onSampling?: (params: CreateMessageRequest["params"]) => Promise<CreateMessageResult>;
/**
* @deprecated Use `onSampling` instead. This option will be removed in a future version.
* Optional callback function to handle sampling requests from servers.
* When provided, the client will declare sampling capability and handle
* `sampling/createMessage` requests by calling this callback.
*/
samplingCallback?: (params: CreateMessageRequest["params"]) => Promise<CreateMessageResult>;
/**
* Optional callback function to handle elicitation requests from servers.
* When provided, the client will declare elicitation capability and handle
* `elicitation/create` requests by calling this callback.
*
* Elicitation allows servers to request additional information from users:
* - Form mode: Collect structured data with JSON schema validation
* - URL mode: Direct users to external URLs for sensitive interactions
*/
elicitationCallback?: (params: ElicitRequestFormParams | ElicitRequestURLParams) => Promise<ElicitResult>;
}
export { BaseCodeExecutor, E2BCodeExecutor, isVMAvailable, VMCodeExecutor, } from "./client/codeExecutor.js";
export { MCPSession } from "./session.js";
export type { CallToolResult, Notification, Root, Tool } from "./session.js";
/**
* Node.js-specific MCPClient implementation
*
* Extends the base client with Node.js-specific features like:
* - File system operations (saveConfig)
* - Config file loading (fromConfigFile)
* - All connector types including StdioConnector
* - Code execution mode
*/
export declare class MCPClient extends BaseMCPClient {
/**
* Get the mcp-use package version.
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
*/
static getPackageVersion(): string;
codeMode: boolean;
private _codeExecutor;
private _customCodeExecutor;
private _codeExecutorConfig;
private _executorOptions?;
private _samplingCallback?;
private _elicitationCallback?;
constructor(config?: string | Record<string, any>, options?: MCPClientOptions);
private _trackClientInit;
static fromDict(cfg: Record<string, any>, options?: MCPClientOptions): MCPClient;
static fromConfigFile(path: string, options?: MCPClientOptions): MCPClient;
/**
* Save configuration to a file (Node.js only)
*/
saveConfig(filepath: string): void;
/**
* Create a connector from server configuration (Node.js version)
* Supports all connector types including StdioConnector
*/
protected createConnectorFromConfig(serverConfig: Record<string, any>): BaseConnector;
private _setupCodeModeConnector;
private _ensureCodeExecutor;
/**
* Execute code in code mode
*/
executeCode(code: string, timeout?: number): Promise<ExecutionResult>;
/**
* Search available tools (used by code mode)
*/
searchTools(query?: string, detailLevel?: "names" | "descriptions" | "full"): Promise<import("./client/codeExecutor.js").ToolSearchResponse>;
/**
* Override getServerNames to exclude internal code_mode server
*/
getServerNames(): string[];
/**
* Close the client and clean up resources including code executors.
* This ensures E2B sandboxes and other resources are properly released.
*/
close(): Promise<void>;
}
//# sourceMappingURL=client.d.ts.map