mcp-use 1.3.4-canary.1 → 1.4.0-canary.3
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/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-6EHM3S3M.js → chunk-35A6O3YH.js} +52 -10
- package/dist/chunk-DSBKVAWD.js +263 -0
- package/dist/{chunk-TIUSJAAE.js → chunk-GRLCLVAK.js} +3 -254
- package/dist/{chunk-QKPVHYJU.js → chunk-RE7EYFDV.js} +1 -1
- package/dist/chunk-WERYJ6PF.js +209 -0
- package/dist/chunk-ZFZPZ4GE.js +21 -0
- package/dist/display-LIYVTGEU.js +350 -0
- package/dist/index.cjs +1539 -284
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +673 -9
- package/dist/src/agents/display.d.ts +54 -0
- package/dist/src/agents/display.d.ts.map +1 -0
- package/dist/src/agents/index.cjs +504 -10
- package/dist/src/agents/index.d.ts +1 -0
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/index.js +10 -18
- package/dist/src/agents/mcp_agent.d.ts +5 -0
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +406 -10
- package/dist/src/browser.js +5 -3
- package/dist/src/client/codeExecutor.d.ts +6 -0
- package/dist/src/client/codeExecutor.d.ts.map +1 -0
- package/dist/src/client/connectors/codeMode.d.ts +27 -0
- package/dist/src/client/connectors/codeMode.d.ts.map +1 -0
- package/dist/src/client/executors/base.d.ts +56 -0
- package/dist/src/client/executors/base.d.ts.map +1 -0
- package/dist/src/client/executors/e2b.d.ts +46 -0
- package/dist/src/client/executors/e2b.d.ts.map +1 -0
- package/dist/src/client/executors/vm.d.ts +30 -0
- package/dist/src/client/executors/vm.d.ts.map +1 -0
- package/dist/src/client/prompts.cjs +401 -0
- package/dist/src/client/prompts.d.ts +13 -0
- package/dist/src/client/prompts.d.ts.map +1 -0
- package/dist/src/client/prompts.js +9 -0
- package/dist/src/client.d.ts +51 -4
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/react/index.js +3 -2
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +14 -4
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { E2BExecutorOptions, MCPClient } from "../../client.js";
|
|
2
|
+
import { BaseCodeExecutor, type ExecutionResult } from "./base.js";
|
|
3
|
+
/**
|
|
4
|
+
* E2B-based code executor using remote sandboxes.
|
|
5
|
+
* Executes code in an E2B sandbox with tool calls proxied back to the host.
|
|
6
|
+
*/
|
|
7
|
+
export declare class E2BCodeExecutor extends BaseCodeExecutor {
|
|
8
|
+
private e2bApiKey;
|
|
9
|
+
private codeExecSandbox;
|
|
10
|
+
private SandboxClass;
|
|
11
|
+
private timeoutMs;
|
|
12
|
+
constructor(client: MCPClient, options: E2BExecutorOptions);
|
|
13
|
+
/**
|
|
14
|
+
* Lazy load E2B Sandbox class.
|
|
15
|
+
* This allows the library to work without E2B installed.
|
|
16
|
+
*/
|
|
17
|
+
private ensureSandboxClass;
|
|
18
|
+
/**
|
|
19
|
+
* Get or create a dedicated sandbox for code execution.
|
|
20
|
+
*/
|
|
21
|
+
private getOrCreateCodeExecSandbox;
|
|
22
|
+
/**
|
|
23
|
+
* Generate the shim code that exposes tools to the sandbox environment.
|
|
24
|
+
* Creates a bridge that intercepts tool calls and sends them back to host.
|
|
25
|
+
*/
|
|
26
|
+
private generateShim;
|
|
27
|
+
/**
|
|
28
|
+
* Build the tool catalog for the shim.
|
|
29
|
+
* Returns a map of server names to their available tools.
|
|
30
|
+
*/
|
|
31
|
+
private buildToolCatalog;
|
|
32
|
+
/**
|
|
33
|
+
* Execute JavaScript/TypeScript code in an E2B sandbox with MCP tool access.
|
|
34
|
+
* Tool calls are proxied back to the host via the bridge pattern.
|
|
35
|
+
*
|
|
36
|
+
* @param code - Code to execute
|
|
37
|
+
* @param timeout - Execution timeout in milliseconds (default: 30000)
|
|
38
|
+
*/
|
|
39
|
+
execute(code: string, timeout?: number): Promise<ExecutionResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Clean up the E2B sandbox.
|
|
42
|
+
* Should be called when the executor is no longer needed.
|
|
43
|
+
*/
|
|
44
|
+
cleanup(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=e2b.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e2b.d.ts","sourceRoot":"","sources":["../../../../src/client/executors/e2b.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAKnE;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB;IAM1D;;;OAGG;YACW,kBAAkB;IAgBhC;;OAEG;YACW,0BAA0B;IAcxC;;;OAGG;IACH,OAAO,CAAC,YAAY;IA6FpB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAwKtE;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAW/B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MCPClient, VMExecutorOptions } from "../../client.js";
|
|
2
|
+
import { BaseCodeExecutor, type ExecutionResult } from "./base.js";
|
|
3
|
+
/**
|
|
4
|
+
* VM-based code executor using Node.js vm module.
|
|
5
|
+
* Executes code in an isolated V8 context with access to MCP tools.
|
|
6
|
+
*/
|
|
7
|
+
export declare class VMCodeExecutor extends BaseCodeExecutor {
|
|
8
|
+
private defaultTimeout;
|
|
9
|
+
private memoryLimitMb?;
|
|
10
|
+
constructor(client: MCPClient, options?: VMExecutorOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Execute JavaScript/TypeScript code with access to MCP tools.
|
|
13
|
+
*
|
|
14
|
+
* @param code - Code to execute
|
|
15
|
+
* @param timeout - Execution timeout in milliseconds (default: configured timeout or 30000)
|
|
16
|
+
*/
|
|
17
|
+
execute(code: string, timeout?: number): Promise<ExecutionResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Build the VM execution context with MCP tools and standard globals.
|
|
20
|
+
*
|
|
21
|
+
* @param logs - Array to capture console output
|
|
22
|
+
*/
|
|
23
|
+
private _buildContext;
|
|
24
|
+
/**
|
|
25
|
+
* Clean up resources.
|
|
26
|
+
* VM executor doesn't need cleanup, but method kept for interface consistency.
|
|
27
|
+
*/
|
|
28
|
+
cleanup(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=vm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vm.d.ts","sourceRoot":"","sources":["../../../../src/client/executors/vm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAEnE;;;GAGG;AACH,qBAAa,cAAe,SAAQ,gBAAgB;IAClD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAC,CAAS;gBAEnB,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAM1D;;;;;OAKG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAkEvE;;;;OAIG;YACW,aAAa;IA6F3B;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/client/prompts.ts
|
|
32
|
+
var prompts_exports = {};
|
|
33
|
+
__export(prompts_exports, {
|
|
34
|
+
PROMPTS: () => PROMPTS
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(prompts_exports);
|
|
37
|
+
|
|
38
|
+
// src/logging.ts
|
|
39
|
+
async function getNodeModules() {
|
|
40
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
41
|
+
try {
|
|
42
|
+
const fs = await import("fs");
|
|
43
|
+
const path = await import("path");
|
|
44
|
+
return { fs: fs.default, path: path.default };
|
|
45
|
+
} catch {
|
|
46
|
+
return { fs: null, path: null };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { fs: null, path: null };
|
|
50
|
+
}
|
|
51
|
+
__name(getNodeModules, "getNodeModules");
|
|
52
|
+
var winston = null;
|
|
53
|
+
function loadWinstonSync() {
|
|
54
|
+
if (typeof require !== "undefined") {
|
|
55
|
+
try {
|
|
56
|
+
winston = require("winston");
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
__name(loadWinstonSync, "loadWinstonSync");
|
|
62
|
+
async function getWinston() {
|
|
63
|
+
if (!winston) {
|
|
64
|
+
winston = await import("winston");
|
|
65
|
+
}
|
|
66
|
+
return winston;
|
|
67
|
+
}
|
|
68
|
+
__name(getWinston, "getWinston");
|
|
69
|
+
var DEFAULT_LOGGER_NAME = "mcp-use";
|
|
70
|
+
function isNodeJSEnvironment() {
|
|
71
|
+
try {
|
|
72
|
+
if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (typeof globalThis.EdgeRuntime !== "undefined" || typeof globalThis.Deno !== "undefined") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const hasNodeGlobals = typeof process !== "undefined" && typeof process.platform !== "undefined" && typeof __dirname !== "undefined";
|
|
79
|
+
return hasNodeGlobals;
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
__name(isNodeJSEnvironment, "isNodeJSEnvironment");
|
|
85
|
+
var SimpleConsoleLogger = class {
|
|
86
|
+
static {
|
|
87
|
+
__name(this, "SimpleConsoleLogger");
|
|
88
|
+
}
|
|
89
|
+
_level;
|
|
90
|
+
name;
|
|
91
|
+
constructor(name = DEFAULT_LOGGER_NAME, level = "info") {
|
|
92
|
+
this.name = name;
|
|
93
|
+
this._level = level;
|
|
94
|
+
}
|
|
95
|
+
shouldLog(level) {
|
|
96
|
+
const levels = [
|
|
97
|
+
"error",
|
|
98
|
+
"warn",
|
|
99
|
+
"info",
|
|
100
|
+
"http",
|
|
101
|
+
"verbose",
|
|
102
|
+
"debug",
|
|
103
|
+
"silly"
|
|
104
|
+
];
|
|
105
|
+
const currentIndex = levels.indexOf(this._level);
|
|
106
|
+
const messageIndex = levels.indexOf(level);
|
|
107
|
+
return messageIndex <= currentIndex;
|
|
108
|
+
}
|
|
109
|
+
formatMessage(level, message) {
|
|
110
|
+
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false });
|
|
111
|
+
return `${timestamp} [${this.name}] ${level}: ${message}`;
|
|
112
|
+
}
|
|
113
|
+
error(message) {
|
|
114
|
+
if (this.shouldLog("error")) {
|
|
115
|
+
console.error(this.formatMessage("error", message));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
warn(message) {
|
|
119
|
+
if (this.shouldLog("warn")) {
|
|
120
|
+
console.warn(this.formatMessage("warn", message));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
info(message) {
|
|
124
|
+
if (this.shouldLog("info")) {
|
|
125
|
+
console.info(this.formatMessage("info", message));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
debug(message) {
|
|
129
|
+
if (this.shouldLog("debug")) {
|
|
130
|
+
console.debug(this.formatMessage("debug", message));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
http(message) {
|
|
134
|
+
if (this.shouldLog("http")) {
|
|
135
|
+
console.log(this.formatMessage("http", message));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
verbose(message) {
|
|
139
|
+
if (this.shouldLog("verbose")) {
|
|
140
|
+
console.log(this.formatMessage("verbose", message));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
silly(message) {
|
|
144
|
+
if (this.shouldLog("silly")) {
|
|
145
|
+
console.log(this.formatMessage("silly", message));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Make it compatible with Winston interface
|
|
149
|
+
get level() {
|
|
150
|
+
return this._level;
|
|
151
|
+
}
|
|
152
|
+
set level(newLevel) {
|
|
153
|
+
this._level = newLevel;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
function resolveLevel(env) {
|
|
157
|
+
const envValue = typeof process !== "undefined" && process.env ? env : void 0;
|
|
158
|
+
switch (envValue?.trim()) {
|
|
159
|
+
case "2":
|
|
160
|
+
return "debug";
|
|
161
|
+
case "1":
|
|
162
|
+
return "info";
|
|
163
|
+
default:
|
|
164
|
+
return "info";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
__name(resolveLevel, "resolveLevel");
|
|
168
|
+
var Logger = class {
|
|
169
|
+
static {
|
|
170
|
+
__name(this, "Logger");
|
|
171
|
+
}
|
|
172
|
+
static instances = {};
|
|
173
|
+
static simpleInstances = {};
|
|
174
|
+
static currentFormat = "minimal";
|
|
175
|
+
static get(name = DEFAULT_LOGGER_NAME) {
|
|
176
|
+
if (!isNodeJSEnvironment()) {
|
|
177
|
+
if (!this.simpleInstances[name]) {
|
|
178
|
+
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
179
|
+
this.simpleInstances[name] = new SimpleConsoleLogger(
|
|
180
|
+
name,
|
|
181
|
+
resolveLevel(debugEnv)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return this.simpleInstances[name];
|
|
185
|
+
}
|
|
186
|
+
if (!this.instances[name]) {
|
|
187
|
+
if (!winston) {
|
|
188
|
+
throw new Error("Winston not loaded - call Logger.configure() first");
|
|
189
|
+
}
|
|
190
|
+
const { createLogger, format } = winston;
|
|
191
|
+
const { combine, timestamp, label, colorize, splat } = format;
|
|
192
|
+
this.instances[name] = createLogger({
|
|
193
|
+
level: resolveLevel(process.env.DEBUG),
|
|
194
|
+
format: combine(
|
|
195
|
+
colorize(),
|
|
196
|
+
splat(),
|
|
197
|
+
label({ label: name }),
|
|
198
|
+
timestamp({ format: "HH:mm:ss" }),
|
|
199
|
+
this.getFormatter()
|
|
200
|
+
),
|
|
201
|
+
transports: []
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return this.instances[name];
|
|
205
|
+
}
|
|
206
|
+
static getFormatter() {
|
|
207
|
+
if (!winston) {
|
|
208
|
+
throw new Error("Winston not loaded");
|
|
209
|
+
}
|
|
210
|
+
const { format } = winston;
|
|
211
|
+
const { printf } = format;
|
|
212
|
+
const minimalFormatter = printf(({ level, message, label, timestamp }) => {
|
|
213
|
+
return `${timestamp} [${label}] ${level}: ${message}`;
|
|
214
|
+
});
|
|
215
|
+
const detailedFormatter = printf(({ level, message, label, timestamp }) => {
|
|
216
|
+
return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
|
|
217
|
+
});
|
|
218
|
+
const emojiFormatter = printf(({ level, message, label, timestamp }) => {
|
|
219
|
+
return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
|
|
220
|
+
});
|
|
221
|
+
switch (this.currentFormat) {
|
|
222
|
+
case "minimal":
|
|
223
|
+
return minimalFormatter;
|
|
224
|
+
case "detailed":
|
|
225
|
+
return detailedFormatter;
|
|
226
|
+
case "emoji":
|
|
227
|
+
return emojiFormatter;
|
|
228
|
+
default:
|
|
229
|
+
return minimalFormatter;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
static async configure(options = {}) {
|
|
233
|
+
const { level, console: console2 = true, file, format = "minimal" } = options;
|
|
234
|
+
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
235
|
+
const resolvedLevel = level ?? resolveLevel(debugEnv);
|
|
236
|
+
this.currentFormat = format;
|
|
237
|
+
if (!isNodeJSEnvironment()) {
|
|
238
|
+
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
239
|
+
logger2.level = resolvedLevel;
|
|
240
|
+
});
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
await getWinston();
|
|
244
|
+
if (!winston) {
|
|
245
|
+
throw new Error("Failed to load winston");
|
|
246
|
+
}
|
|
247
|
+
const root = this.get();
|
|
248
|
+
root.level = resolvedLevel;
|
|
249
|
+
const winstonRoot = root;
|
|
250
|
+
winstonRoot.clear();
|
|
251
|
+
if (console2) {
|
|
252
|
+
winstonRoot.add(new winston.transports.Console());
|
|
253
|
+
}
|
|
254
|
+
if (file) {
|
|
255
|
+
const { fs: nodeFs, path: nodePath } = await getNodeModules();
|
|
256
|
+
if (nodeFs && nodePath) {
|
|
257
|
+
const dir = nodePath.dirname(nodePath.resolve(file));
|
|
258
|
+
if (!nodeFs.existsSync(dir)) {
|
|
259
|
+
nodeFs.mkdirSync(dir, { recursive: true });
|
|
260
|
+
}
|
|
261
|
+
winstonRoot.add(new winston.transports.File({ filename: file }));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const { format: winstonFormat } = winston;
|
|
265
|
+
const { combine, timestamp, label, colorize, splat } = winstonFormat;
|
|
266
|
+
Object.values(this.instances).forEach((logger2) => {
|
|
267
|
+
if (logger2 && "format" in logger2) {
|
|
268
|
+
logger2.level = resolvedLevel;
|
|
269
|
+
logger2.format = combine(
|
|
270
|
+
colorize(),
|
|
271
|
+
splat(),
|
|
272
|
+
label({ label: DEFAULT_LOGGER_NAME }),
|
|
273
|
+
timestamp({ format: "HH:mm:ss" }),
|
|
274
|
+
this.getFormatter()
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
static setDebug(enabled) {
|
|
280
|
+
let level;
|
|
281
|
+
if (enabled === 2 || enabled === true) level = "debug";
|
|
282
|
+
else if (enabled === 1) level = "info";
|
|
283
|
+
else level = "info";
|
|
284
|
+
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
285
|
+
logger2.level = level;
|
|
286
|
+
});
|
|
287
|
+
Object.values(this.instances).forEach((logger2) => {
|
|
288
|
+
if (logger2) {
|
|
289
|
+
logger2.level = level;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
if (typeof process !== "undefined" && process.env) {
|
|
293
|
+
process.env.DEBUG = enabled ? enabled === true ? "2" : String(enabled) : "0";
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
static setFormat(format) {
|
|
297
|
+
this.currentFormat = format;
|
|
298
|
+
this.configure({ format });
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
if (isNodeJSEnvironment()) {
|
|
302
|
+
loadWinstonSync();
|
|
303
|
+
if (winston) {
|
|
304
|
+
Logger.configure();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
var logger = Logger.get();
|
|
308
|
+
|
|
309
|
+
// src/client/connectors/codeMode.ts
|
|
310
|
+
var CODE_MODE_AGENT_PROMPT = `
|
|
311
|
+
## MCP Code Mode Tool Usage Guide
|
|
312
|
+
|
|
313
|
+
You have access to an MCP Code Mode Client that allows you to execute JavaScript/TypeScript code with access to registered tools. Follow this workflow:
|
|
314
|
+
|
|
315
|
+
### 1. Tool Discovery Phase
|
|
316
|
+
**Always start by discovering available tools:**
|
|
317
|
+
- Tools are organized by server namespace (e.g., \`server_name.tool_name\`)
|
|
318
|
+
- Use the \`search_tools(query, detail_level)\` function to find available tools
|
|
319
|
+
- You can access \`__tool_namespaces\` to see all available server namespaces
|
|
320
|
+
|
|
321
|
+
\`\`\`javascript
|
|
322
|
+
// Find all GitHub-related tools
|
|
323
|
+
const tools = await search_tools("github");
|
|
324
|
+
for (const tool of tools) {
|
|
325
|
+
console.log(\`\${tool.server}.\${tool.name}: \${tool.description}\`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Get only tool names for quick overview
|
|
329
|
+
const tools = await search_tools("", "names");
|
|
330
|
+
\`\`\`
|
|
331
|
+
|
|
332
|
+
### 2. Interface Introspection
|
|
333
|
+
**Understand tool contracts before using them:**
|
|
334
|
+
- Use \`search_tools\` to get tool descriptions and input schemas
|
|
335
|
+
- Look for "Access as: server.tool(args)" patterns in descriptions
|
|
336
|
+
|
|
337
|
+
### 3. Code Execution Guidelines
|
|
338
|
+
**When writing code:**
|
|
339
|
+
- Use \`await server.tool({ param: value })\` syntax for all tool calls
|
|
340
|
+
- Tools are async functions that return promises
|
|
341
|
+
- You have access to standard JavaScript globals: \`console\`, \`JSON\`, \`Math\`, \`Date\`, etc.
|
|
342
|
+
- All console output (\`console.log\`, \`console.error\`, etc.) is automatically captured and returned
|
|
343
|
+
- Build properly structured input objects based on interface definitions
|
|
344
|
+
- Handle errors appropriately with try/catch blocks
|
|
345
|
+
- Chain tool calls by using results from previous calls
|
|
346
|
+
|
|
347
|
+
### 4. Best Practices
|
|
348
|
+
- **Discover first, code second**: Always explore available tools before writing execution code
|
|
349
|
+
- **Respect namespaces**: Use full \`server.tool\` names to avoid conflicts
|
|
350
|
+
- **Minimize Context**: Process large data in code, return only essential results
|
|
351
|
+
- **Error handling**: Wrap tool calls in try/catch for robustness
|
|
352
|
+
- **Data flow**: Chain tools by passing outputs as inputs to subsequent tools
|
|
353
|
+
|
|
354
|
+
### 5. Available Runtime Context
|
|
355
|
+
- \`search_tools(query, detail_level)\`: Function to discover tools
|
|
356
|
+
- \`__tool_namespaces\`: Array of available server namespaces
|
|
357
|
+
- All registered tools as \`server.tool\` functions
|
|
358
|
+
- Standard JavaScript built-ins for data processing
|
|
359
|
+
|
|
360
|
+
### Example Workflow
|
|
361
|
+
|
|
362
|
+
\`\`\`javascript
|
|
363
|
+
// 1. Discover available tools
|
|
364
|
+
const github_tools = await search_tools("github pull request");
|
|
365
|
+
console.log(\`Available GitHub PR tools: \${github_tools.map(t => t.name)}\`);
|
|
366
|
+
|
|
367
|
+
// 2. Call tools with proper parameters
|
|
368
|
+
const pr = await github.get_pull_request({
|
|
369
|
+
owner: "facebook",
|
|
370
|
+
repo: "react",
|
|
371
|
+
number: 12345
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// 3. Process results
|
|
375
|
+
let result;
|
|
376
|
+
if (pr.state === 'open' && pr.labels.some(l => l.name === 'bug')) {
|
|
377
|
+
// 4. Chain with other tools
|
|
378
|
+
await slack.post_message({
|
|
379
|
+
channel: "#bugs",
|
|
380
|
+
text: \`\u{1F41B} Bug PR needs review: \${pr.title}\`
|
|
381
|
+
});
|
|
382
|
+
result = "Notification sent";
|
|
383
|
+
} else {
|
|
384
|
+
result = "No action needed";
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 5. Return structured results
|
|
388
|
+
return {
|
|
389
|
+
pr_number: pr.number,
|
|
390
|
+
pr_title: pr.title,
|
|
391
|
+
action_taken: result
|
|
392
|
+
};
|
|
393
|
+
\`\`\`
|
|
394
|
+
|
|
395
|
+
Remember: Always discover and understand available tools before attempting to use them in code execution.
|
|
396
|
+
`;
|
|
397
|
+
|
|
398
|
+
// src/client/prompts.ts
|
|
399
|
+
var PROMPTS = {
|
|
400
|
+
CODE_MODE: CODE_MODE_AGENT_PROMPT
|
|
401
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt templates for MCP code execution mode.
|
|
3
|
+
*
|
|
4
|
+
* This module provides prompt templates to guide agents on how to use
|
|
5
|
+
* MCP tools via code execution.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Collection of prompt templates for MCP agents.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PROMPTS: {
|
|
11
|
+
readonly CODE_MODE: "\n## MCP Code Mode Tool Usage Guide\n\nYou have access to an MCP Code Mode Client that allows you to execute JavaScript/TypeScript code with access to registered tools. Follow this workflow:\n\n### 1. Tool Discovery Phase\n**Always start by discovering available tools:**\n- Tools are organized by server namespace (e.g., `server_name.tool_name`)\n- Use the `search_tools(query, detail_level)` function to find available tools\n- You can access `__tool_namespaces` to see all available server namespaces\n\n```javascript\n// Find all GitHub-related tools\nconst tools = await search_tools(\"github\");\nfor (const tool of tools) {\n console.log(`${tool.server}.${tool.name}: ${tool.description}`);\n}\n\n// Get only tool names for quick overview\nconst tools = await search_tools(\"\", \"names\");\n```\n\n### 2. Interface Introspection\n**Understand tool contracts before using them:**\n- Use `search_tools` to get tool descriptions and input schemas\n- Look for \"Access as: server.tool(args)\" patterns in descriptions\n\n### 3. Code Execution Guidelines\n**When writing code:**\n- Use `await server.tool({ param: value })` syntax for all tool calls\n- Tools are async functions that return promises\n- You have access to standard JavaScript globals: `console`, `JSON`, `Math`, `Date`, etc.\n- All console output (`console.log`, `console.error`, etc.) is automatically captured and returned\n- Build properly structured input objects based on interface definitions\n- Handle errors appropriately with try/catch blocks\n- Chain tool calls by using results from previous calls\n\n### 4. Best Practices\n- **Discover first, code second**: Always explore available tools before writing execution code\n- **Respect namespaces**: Use full `server.tool` names to avoid conflicts\n- **Minimize Context**: Process large data in code, return only essential results\n- **Error handling**: Wrap tool calls in try/catch for robustness\n- **Data flow**: Chain tools by passing outputs as inputs to subsequent tools\n\n### 5. Available Runtime Context\n- `search_tools(query, detail_level)`: Function to discover tools\n- `__tool_namespaces`: Array of available server namespaces\n- All registered tools as `server.tool` functions\n- Standard JavaScript built-ins for data processing\n\n### Example Workflow\n\n```javascript\n// 1. Discover available tools\nconst github_tools = await search_tools(\"github pull request\");\nconsole.log(`Available GitHub PR tools: ${github_tools.map(t => t.name)}`);\n\n// 2. Call tools with proper parameters\nconst pr = await github.get_pull_request({\n owner: \"facebook\",\n repo: \"react\",\n number: 12345\n});\n\n// 3. Process results\nlet result;\nif (pr.state === 'open' && pr.labels.some(l => l.name === 'bug')) {\n // 4. Chain with other tools\n await slack.post_message({\n channel: \"#bugs\",\n text: `🐛 Bug PR needs review: ${pr.title}`\n });\n result = \"Notification sent\";\n} else {\n result = \"No action needed\";\n}\n\n// 5. Return structured results\nreturn {\n pr_number: pr.number,\n pr_title: pr.title,\n action_taken: result\n};\n```\n\nRemember: Always discover and understand available tools before attempting to use them in code execution.\n";
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/client/prompts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,eAAO,MAAM,OAAO;;CAEV,CAAC"}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
|
-
import type { BaseConnector } from "./connectors/base.js";
|
|
2
1
|
import { BaseMCPClient } from "./client/base.js";
|
|
2
|
+
import type { ExecutionResult } from "./client/codeExecutor.js";
|
|
3
|
+
import { BaseCodeExecutor, E2BCodeExecutor, VMCodeExecutor } from "./client/codeExecutor.js";
|
|
4
|
+
import type { BaseConnector } from "./connectors/base.js";
|
|
5
|
+
export type CodeExecutorFunction = (code: string, timeout?: number) => Promise<ExecutionResult>;
|
|
6
|
+
export type CodeExecutorType = "vm" | "e2b";
|
|
7
|
+
export interface VMExecutorOptions {
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
memoryLimitMb?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface E2BExecutorOptions {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export type ExecutorOptions = VMExecutorOptions | E2BExecutorOptions;
|
|
16
|
+
export interface CodeModeConfig {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
executor?: CodeExecutorType | CodeExecutorFunction | BaseCodeExecutor;
|
|
19
|
+
executorOptions?: ExecutorOptions;
|
|
20
|
+
}
|
|
21
|
+
export interface MCPClientOptions {
|
|
22
|
+
codeMode?: boolean | CodeModeConfig;
|
|
23
|
+
}
|
|
24
|
+
export { BaseCodeExecutor, E2BCodeExecutor, VMCodeExecutor };
|
|
3
25
|
/**
|
|
4
26
|
* Node.js-specific MCPClient implementation
|
|
5
27
|
*
|
|
@@ -7,11 +29,17 @@ import { BaseMCPClient } from "./client/base.js";
|
|
|
7
29
|
* - File system operations (saveConfig)
|
|
8
30
|
* - Config file loading (fromConfigFile)
|
|
9
31
|
* - All connector types including StdioConnector
|
|
32
|
+
* - Code execution mode
|
|
10
33
|
*/
|
|
11
34
|
export declare class MCPClient extends BaseMCPClient {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
35
|
+
codeMode: boolean;
|
|
36
|
+
private _codeExecutor;
|
|
37
|
+
private _customCodeExecutor;
|
|
38
|
+
private _codeExecutorConfig;
|
|
39
|
+
private _executorOptions?;
|
|
40
|
+
constructor(config?: string | Record<string, any>, options?: MCPClientOptions);
|
|
41
|
+
static fromDict(cfg: Record<string, any>, options?: MCPClientOptions): MCPClient;
|
|
42
|
+
static fromConfigFile(path: string, options?: MCPClientOptions): MCPClient;
|
|
15
43
|
/**
|
|
16
44
|
* Save configuration to a file (Node.js only)
|
|
17
45
|
*/
|
|
@@ -21,5 +49,24 @@ export declare class MCPClient extends BaseMCPClient {
|
|
|
21
49
|
* Supports all connector types including StdioConnector
|
|
22
50
|
*/
|
|
23
51
|
protected createConnectorFromConfig(serverConfig: Record<string, any>): BaseConnector;
|
|
52
|
+
private _setupCodeModeConnector;
|
|
53
|
+
private _ensureCodeExecutor;
|
|
54
|
+
/**
|
|
55
|
+
* Execute code in code mode
|
|
56
|
+
*/
|
|
57
|
+
executeCode(code: string, timeout?: number): Promise<ExecutionResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Search available tools (used by code mode)
|
|
60
|
+
*/
|
|
61
|
+
searchTools(query?: string, detailLevel?: "names" | "descriptions" | "full"): Promise<import("./client/codeExecutor.js").ToolSearchResult[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Override getServerNames to exclude internal code_mode server
|
|
64
|
+
*/
|
|
65
|
+
getServerNames(): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Close the client and clean up resources including code executors.
|
|
68
|
+
* This ensures E2B sandboxes and other resources are properly released.
|
|
69
|
+
*/
|
|
70
|
+
close(): Promise<void>;
|
|
24
71
|
}
|
|
25
72
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,MAAM,MAAM,oBAAoB,GAAG,CACjC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,eAAe,CAAC,CAAC;AAC9B,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,KAAK,CAAC;AAG5C,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAGD,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AAErE,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,gBAAgB,GAAG,oBAAoB,GAAG,gBAAgB,CAAC;IACtE,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC;CACrC;AAGD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAE7D;;;;;;;;GAQG;AACH,qBAAa,SAAU,SAAQ,aAAa;IACnC,QAAQ,EAAE,OAAO,CAAS;IACjC,OAAO,CAAC,aAAa,CAAiC;IACtD,OAAO,CAAC,mBAAmB,CAAqC;IAChE,OAAO,CAAC,mBAAmB,CAGC;IAC5B,OAAO,CAAC,gBAAgB,CAAC,CAAkB;gBAGzC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrC,OAAO,CAAC,EAAE,gBAAgB;WAuCd,QAAQ,CACpB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxB,OAAO,CAAC,EAAE,gBAAgB,GACzB,SAAS;WAIE,cAAc,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,gBAAgB,GACzB,SAAS;IAIZ;;OAEG;IACI,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQzC;;;OAGG;IACH,SAAS,CAAC,yBAAyB,CACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAChC,aAAa;IAIhB,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,mBAAmB;IAmC3B;;OAEG;IACU,WAAW,CACtB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,eAAe,CAAC;IAc3B;;OAEG;IACU,WAAW,CACtB,KAAK,GAAE,MAAW,EAClB,WAAW,GAAE,OAAO,GAAG,cAAc,GAAG,MAAe,GACtD,OAAO,CAAC,OAAO,0BAA0B,EAAE,gBAAgB,EAAE,CAAC;IAUjE;;OAEG;IACI,cAAc,IAAI,MAAM,EAAE;IAOjC;;;OAGG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAUpC"}
|
package/dist/src/react/index.js
CHANGED
|
@@ -6,10 +6,11 @@ import {
|
|
|
6
6
|
useWidgetProps,
|
|
7
7
|
useWidgetState,
|
|
8
8
|
useWidgetTheme
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-RE7EYFDV.js";
|
|
10
10
|
import {
|
|
11
11
|
onMcpAuthorization
|
|
12
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-GRLCLVAK.js";
|
|
13
|
+
import "../../chunk-DSBKVAWD.js";
|
|
13
14
|
import "../../chunk-34R6SIER.js";
|
|
14
15
|
import "../../chunk-3GQAWCBQ.js";
|
|
15
16
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsup.config.d.ts","sourceRoot":"","sources":["../tsup.config.ts"],"names":[],"mappings":";AAEA,
|
|
1
|
+
{"version":3,"file":"tsup.config.d.ts","sourceRoot":"","sources":["../tsup.config.ts"],"names":[],"mappings":";AAEA,wBAsCG"}
|