mcp-use 1.11.0-canary.13 → 1.11.0-canary.14
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-LHNWYWSI.js → chunk-2IMIUODV.js} +482 -5
- package/dist/{chunk-TZKOAITC.js → chunk-7TS5EJ4T.js} +1 -1
- package/dist/{chunk-5OHAUR7E.js → chunk-AEHNVFZG.js} +1 -1
- package/dist/{chunk-T7V3VOS2.js → chunk-JYFYHDYK.js} +4 -4
- package/dist/{chunk-P4TBZOPX.js → chunk-MIKDMUFS.js} +2 -2
- package/dist/{chunk-C5YF5MPR.js → chunk-PO6UGK4I.js} +2 -2
- package/dist/{chunk-ZFZPZ4GE.js → chunk-SBMQ4QZJ.js} +9 -0
- package/dist/{chunk-HPAS2BOZ.js → chunk-U7JXQZVH.js} +197 -8
- package/dist/index.cjs +2 -2
- package/dist/index.js +26 -30
- package/dist/src/agents/index.cjs +2 -2
- package/dist/src/agents/index.d.ts +1 -1
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/index.js +7 -11
- package/dist/src/{client/prompts.d.ts → agents/prompts/index.d.ts} +3 -3
- package/dist/src/agents/prompts/index.d.ts.map +1 -0
- package/dist/src/browser.cjs +1 -1
- package/dist/src/browser.js +13 -16
- package/dist/src/client.cjs +1 -1
- package/dist/src/client.js +3 -5
- package/dist/src/react/index.cjs +1 -1
- package/dist/src/react/index.js +7 -8
- package/dist/src/server/index.cjs +1 -1
- package/dist/src/server/index.js +10 -10
- package/dist/src/version.d.ts +1 -1
- package/dist/{tool-execution-helpers-CBMJLW7M.js → tool-execution-helpers-RRECKMIN.js} +2 -2
- package/package.json +31 -31
- package/dist/chunk-2RSYU23F.js +0 -12
- package/dist/chunk-6I4P5WXY.js +0 -491
- package/dist/chunk-AQVGN2CI.js +0 -204
- package/dist/src/client/prompts.cjs +0 -407
- package/dist/src/client/prompts.d.ts.map +0 -1
- package/dist/src/client/prompts.js +0 -11
package/dist/chunk-AQVGN2CI.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseConnector
|
|
3
|
-
} from "./chunk-6I4P5WXY.js";
|
|
4
|
-
import {
|
|
5
|
-
__name
|
|
6
|
-
} from "./chunk-3GQAWCBQ.js";
|
|
7
|
-
|
|
8
|
-
// src/client/connectors/codeMode.ts
|
|
9
|
-
var CODE_MODE_AGENT_PROMPT = `
|
|
10
|
-
## MCP Code Mode Tool Usage Guide
|
|
11
|
-
|
|
12
|
-
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:
|
|
13
|
-
|
|
14
|
-
### 1. Tool Discovery Phase
|
|
15
|
-
**Always start by discovering available tools:**
|
|
16
|
-
- Tools are organized by server namespace (e.g., \`server_name.tool_name\`)
|
|
17
|
-
- Use the \`search_tools(query, detail_level)\` function to find available tools
|
|
18
|
-
- You can access \`__tool_namespaces\` to see all available server namespaces
|
|
19
|
-
|
|
20
|
-
\`\`\`javascript
|
|
21
|
-
// Find all GitHub-related tools
|
|
22
|
-
const tools = await search_tools("github");
|
|
23
|
-
for (const tool of tools) {
|
|
24
|
-
console.log(\`\${tool.server}.\${tool.name}: \${tool.description}\`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Get only tool names for quick overview
|
|
28
|
-
const tools = await search_tools("", "names");
|
|
29
|
-
\`\`\`
|
|
30
|
-
|
|
31
|
-
### 2. Interface Introspection
|
|
32
|
-
**Understand tool contracts before using them:**
|
|
33
|
-
- Use \`search_tools\` to get tool descriptions and input schemas
|
|
34
|
-
- Look for "Access as: server.tool(args)" patterns in descriptions
|
|
35
|
-
|
|
36
|
-
### 3. Code Execution Guidelines
|
|
37
|
-
**When writing code:**
|
|
38
|
-
- Use \`await server.tool({ param: value })\` syntax for all tool calls
|
|
39
|
-
- Tools are async functions that return promises
|
|
40
|
-
- You have access to standard JavaScript globals: \`console\`, \`JSON\`, \`Math\`, \`Date\`, etc.
|
|
41
|
-
- All console output (\`console.log\`, \`console.error\`, etc.) is automatically captured and returned
|
|
42
|
-
- Build properly structured input objects based on interface definitions
|
|
43
|
-
- Handle errors appropriately with try/catch blocks
|
|
44
|
-
- Chain tool calls by using results from previous calls
|
|
45
|
-
|
|
46
|
-
### 4. Best Practices
|
|
47
|
-
- **Discover first, code second**: Always explore available tools before writing execution code
|
|
48
|
-
- **Respect namespaces**: Use full \`server.tool\` names to avoid conflicts
|
|
49
|
-
- **Minimize Context**: Process large data in code, return only essential results
|
|
50
|
-
- **Error handling**: Wrap tool calls in try/catch for robustness
|
|
51
|
-
- **Data flow**: Chain tools by passing outputs as inputs to subsequent tools
|
|
52
|
-
|
|
53
|
-
### 5. Available Runtime Context
|
|
54
|
-
- \`search_tools(query, detail_level)\`: Function to discover tools
|
|
55
|
-
- \`__tool_namespaces\`: Array of available server namespaces
|
|
56
|
-
- All registered tools as \`server.tool\` functions
|
|
57
|
-
- Standard JavaScript built-ins for data processing
|
|
58
|
-
|
|
59
|
-
### Example Workflow
|
|
60
|
-
|
|
61
|
-
\`\`\`javascript
|
|
62
|
-
// 1. Discover available tools
|
|
63
|
-
const github_tools = await search_tools("github pull request");
|
|
64
|
-
console.log(\`Available GitHub PR tools: \${github_tools.map(t => t.name)}\`);
|
|
65
|
-
|
|
66
|
-
// 2. Call tools with proper parameters
|
|
67
|
-
const pr = await github.get_pull_request({
|
|
68
|
-
owner: "facebook",
|
|
69
|
-
repo: "react",
|
|
70
|
-
number: 12345
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// 3. Process results
|
|
74
|
-
let result;
|
|
75
|
-
if (pr.state === 'open' && pr.labels.some(l => l.name === 'bug')) {
|
|
76
|
-
// 4. Chain with other tools
|
|
77
|
-
await slack.post_message({
|
|
78
|
-
channel: "#bugs",
|
|
79
|
-
text: \`\u{1F41B} Bug PR needs review: \${pr.title}\`
|
|
80
|
-
});
|
|
81
|
-
result = "Notification sent";
|
|
82
|
-
} else {
|
|
83
|
-
result = "No action needed";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// 5. Return structured results
|
|
87
|
-
return {
|
|
88
|
-
pr_number: pr.number,
|
|
89
|
-
pr_title: pr.title,
|
|
90
|
-
action_taken: result
|
|
91
|
-
};
|
|
92
|
-
\`\`\`
|
|
93
|
-
|
|
94
|
-
Remember: Always discover and understand available tools before attempting to use them in code execution.
|
|
95
|
-
`;
|
|
96
|
-
var CodeModeConnector = class extends BaseConnector {
|
|
97
|
-
static {
|
|
98
|
-
__name(this, "CodeModeConnector");
|
|
99
|
-
}
|
|
100
|
-
mcpClient;
|
|
101
|
-
_tools;
|
|
102
|
-
constructor(client) {
|
|
103
|
-
super();
|
|
104
|
-
this.mcpClient = client;
|
|
105
|
-
this.connected = true;
|
|
106
|
-
this._tools = this._createToolsList();
|
|
107
|
-
}
|
|
108
|
-
async connect() {
|
|
109
|
-
this.connected = true;
|
|
110
|
-
}
|
|
111
|
-
async disconnect() {
|
|
112
|
-
this.connected = false;
|
|
113
|
-
}
|
|
114
|
-
get publicIdentifier() {
|
|
115
|
-
return { name: "code_mode", version: "1.0.0" };
|
|
116
|
-
}
|
|
117
|
-
_createToolsList() {
|
|
118
|
-
return [
|
|
119
|
-
{
|
|
120
|
-
name: "execute_code",
|
|
121
|
-
description: "Execute JavaScript/TypeScript code with access to MCP tools. This is the PRIMARY way to interact with MCP servers in code mode. Write code that discovers tools using search_tools(), calls tools as async functions (e.g., await github.get_pull_request(...)), processes data efficiently, and returns results. Use 'await' for async operations and 'return' to return values. Available in code: search_tools(), __tool_namespaces, and server.tool_name() functions.",
|
|
122
|
-
inputSchema: {
|
|
123
|
-
type: "object",
|
|
124
|
-
properties: {
|
|
125
|
-
code: {
|
|
126
|
-
type: "string",
|
|
127
|
-
description: "JavaScript/TypeScript code to execute. Use 'await' for async operations. Use 'return' to return a value. Available: search_tools(), server.tool_name(), __tool_namespaces"
|
|
128
|
-
},
|
|
129
|
-
timeout: {
|
|
130
|
-
type: "number",
|
|
131
|
-
description: "Execution timeout in milliseconds",
|
|
132
|
-
default: 3e4
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
required: ["code"]
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: "search_tools",
|
|
140
|
-
description: "Search and discover available MCP tools across all servers. Use this to find out what tools are available before writing code. Returns tool information including names, descriptions, and schemas. Can filter by query and control detail level.",
|
|
141
|
-
inputSchema: {
|
|
142
|
-
type: "object",
|
|
143
|
-
properties: {
|
|
144
|
-
query: {
|
|
145
|
-
type: "string",
|
|
146
|
-
description: "Search query to filter tools by name or description",
|
|
147
|
-
default: ""
|
|
148
|
-
},
|
|
149
|
-
detail_level: {
|
|
150
|
-
type: "string",
|
|
151
|
-
description: "Detail level: 'names', 'descriptions', or 'full'",
|
|
152
|
-
enum: ["names", "descriptions", "full"],
|
|
153
|
-
default: "full"
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
];
|
|
159
|
-
}
|
|
160
|
-
// Override tools getter to return static list immediately
|
|
161
|
-
get tools() {
|
|
162
|
-
return this._tools;
|
|
163
|
-
}
|
|
164
|
-
async initialize() {
|
|
165
|
-
this.toolsCache = this._tools;
|
|
166
|
-
return { capabilities: {}, version: "1.0.0" };
|
|
167
|
-
}
|
|
168
|
-
async callTool(name, args) {
|
|
169
|
-
if (name === "execute_code") {
|
|
170
|
-
const code = args.code;
|
|
171
|
-
const timeout = args.timeout || 3e4;
|
|
172
|
-
const result = await this.mcpClient.executeCode(code, timeout);
|
|
173
|
-
return {
|
|
174
|
-
content: [
|
|
175
|
-
{
|
|
176
|
-
type: "text",
|
|
177
|
-
text: JSON.stringify(result)
|
|
178
|
-
}
|
|
179
|
-
]
|
|
180
|
-
};
|
|
181
|
-
} else if (name === "search_tools") {
|
|
182
|
-
const query = args.query || "";
|
|
183
|
-
const detailLevel = args.detail_level;
|
|
184
|
-
const result = await this.mcpClient.searchTools(
|
|
185
|
-
query,
|
|
186
|
-
detailLevel && detailLevel in ["names", "descriptions", "full"] ? detailLevel : "full"
|
|
187
|
-
);
|
|
188
|
-
return {
|
|
189
|
-
content: [
|
|
190
|
-
{
|
|
191
|
-
type: "text",
|
|
192
|
-
text: JSON.stringify(result)
|
|
193
|
-
}
|
|
194
|
-
]
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
export {
|
|
202
|
-
CODE_MODE_AGENT_PROMPT,
|
|
203
|
-
CodeModeConnector
|
|
204
|
-
};
|
|
@@ -1,407 +0,0 @@
|
|
|
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/connectors/base.ts
|
|
39
|
-
var import_types = require("@mcp-use/modelcontextprotocol-sdk/types.js");
|
|
40
|
-
|
|
41
|
-
// src/logging.ts
|
|
42
|
-
async function getNodeModules() {
|
|
43
|
-
if (typeof process !== "undefined" && process.platform) {
|
|
44
|
-
try {
|
|
45
|
-
const fs = await import("fs");
|
|
46
|
-
const path = await import("path");
|
|
47
|
-
return { fs: fs.default, path: path.default };
|
|
48
|
-
} catch {
|
|
49
|
-
return { fs: null, path: null };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return { fs: null, path: null };
|
|
53
|
-
}
|
|
54
|
-
__name(getNodeModules, "getNodeModules");
|
|
55
|
-
var winston = null;
|
|
56
|
-
function loadWinstonSync() {
|
|
57
|
-
if (typeof require !== "undefined") {
|
|
58
|
-
try {
|
|
59
|
-
winston = require("winston");
|
|
60
|
-
} catch {
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
__name(loadWinstonSync, "loadWinstonSync");
|
|
65
|
-
async function getWinston() {
|
|
66
|
-
if (!winston) {
|
|
67
|
-
winston = await import("winston");
|
|
68
|
-
}
|
|
69
|
-
return winston;
|
|
70
|
-
}
|
|
71
|
-
__name(getWinston, "getWinston");
|
|
72
|
-
var DEFAULT_LOGGER_NAME = "mcp-use";
|
|
73
|
-
function isNodeJSEnvironment() {
|
|
74
|
-
try {
|
|
75
|
-
if (typeof navigator !== "undefined" && navigator.userAgent?.includes("Cloudflare-Workers")) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
if (typeof globalThis.EdgeRuntime !== "undefined" || typeof globalThis.Deno !== "undefined") {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const hasNodeGlobals = typeof process !== "undefined" && typeof process.platform !== "undefined" && typeof __dirname !== "undefined";
|
|
82
|
-
return hasNodeGlobals;
|
|
83
|
-
} catch {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
__name(isNodeJSEnvironment, "isNodeJSEnvironment");
|
|
88
|
-
var SimpleConsoleLogger = class {
|
|
89
|
-
static {
|
|
90
|
-
__name(this, "SimpleConsoleLogger");
|
|
91
|
-
}
|
|
92
|
-
_level;
|
|
93
|
-
name;
|
|
94
|
-
constructor(name = DEFAULT_LOGGER_NAME, level = "info") {
|
|
95
|
-
this.name = name;
|
|
96
|
-
this._level = level;
|
|
97
|
-
}
|
|
98
|
-
shouldLog(level) {
|
|
99
|
-
const levels = [
|
|
100
|
-
"error",
|
|
101
|
-
"warn",
|
|
102
|
-
"info",
|
|
103
|
-
"http",
|
|
104
|
-
"verbose",
|
|
105
|
-
"debug",
|
|
106
|
-
"silly"
|
|
107
|
-
];
|
|
108
|
-
const currentIndex = levels.indexOf(this._level);
|
|
109
|
-
const messageIndex = levels.indexOf(level);
|
|
110
|
-
return messageIndex <= currentIndex;
|
|
111
|
-
}
|
|
112
|
-
formatMessage(level, message) {
|
|
113
|
-
const timestamp = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false });
|
|
114
|
-
return `${timestamp} [${this.name}] ${level}: ${message}`;
|
|
115
|
-
}
|
|
116
|
-
error(message) {
|
|
117
|
-
if (this.shouldLog("error")) {
|
|
118
|
-
console.error(this.formatMessage("error", message));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
warn(message) {
|
|
122
|
-
if (this.shouldLog("warn")) {
|
|
123
|
-
console.warn(this.formatMessage("warn", message));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
info(message) {
|
|
127
|
-
if (this.shouldLog("info")) {
|
|
128
|
-
console.info(this.formatMessage("info", message));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
debug(message) {
|
|
132
|
-
if (this.shouldLog("debug")) {
|
|
133
|
-
console.debug(this.formatMessage("debug", message));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
http(message) {
|
|
137
|
-
if (this.shouldLog("http")) {
|
|
138
|
-
console.log(this.formatMessage("http", message));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
verbose(message) {
|
|
142
|
-
if (this.shouldLog("verbose")) {
|
|
143
|
-
console.log(this.formatMessage("verbose", message));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
silly(message) {
|
|
147
|
-
if (this.shouldLog("silly")) {
|
|
148
|
-
console.log(this.formatMessage("silly", message));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// Make it compatible with Winston interface
|
|
152
|
-
get level() {
|
|
153
|
-
return this._level;
|
|
154
|
-
}
|
|
155
|
-
set level(newLevel) {
|
|
156
|
-
this._level = newLevel;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
function resolveLevel(env) {
|
|
160
|
-
const envValue = typeof process !== "undefined" && process.env ? env : void 0;
|
|
161
|
-
switch (envValue?.trim()) {
|
|
162
|
-
case "2":
|
|
163
|
-
return "debug";
|
|
164
|
-
case "1":
|
|
165
|
-
return "info";
|
|
166
|
-
default:
|
|
167
|
-
return "info";
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
__name(resolveLevel, "resolveLevel");
|
|
171
|
-
var Logger = class {
|
|
172
|
-
static {
|
|
173
|
-
__name(this, "Logger");
|
|
174
|
-
}
|
|
175
|
-
static instances = {};
|
|
176
|
-
static simpleInstances = {};
|
|
177
|
-
static currentFormat = "minimal";
|
|
178
|
-
static get(name = DEFAULT_LOGGER_NAME) {
|
|
179
|
-
if (!isNodeJSEnvironment()) {
|
|
180
|
-
if (!this.simpleInstances[name]) {
|
|
181
|
-
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
182
|
-
this.simpleInstances[name] = new SimpleConsoleLogger(
|
|
183
|
-
name,
|
|
184
|
-
resolveLevel(debugEnv)
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
return this.simpleInstances[name];
|
|
188
|
-
}
|
|
189
|
-
if (!this.instances[name]) {
|
|
190
|
-
if (!winston) {
|
|
191
|
-
throw new Error("Winston not loaded - call Logger.configure() first");
|
|
192
|
-
}
|
|
193
|
-
const { createLogger, format } = winston;
|
|
194
|
-
const { combine, timestamp, label, colorize, splat } = format;
|
|
195
|
-
this.instances[name] = createLogger({
|
|
196
|
-
level: resolveLevel(process.env.DEBUG),
|
|
197
|
-
format: combine(
|
|
198
|
-
colorize(),
|
|
199
|
-
splat(),
|
|
200
|
-
label({ label: name }),
|
|
201
|
-
timestamp({ format: "HH:mm:ss" }),
|
|
202
|
-
this.getFormatter()
|
|
203
|
-
),
|
|
204
|
-
transports: [new winston.transports.Console()]
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
return this.instances[name];
|
|
208
|
-
}
|
|
209
|
-
static getFormatter() {
|
|
210
|
-
if (!winston) {
|
|
211
|
-
throw new Error("Winston not loaded");
|
|
212
|
-
}
|
|
213
|
-
const { format } = winston;
|
|
214
|
-
const { printf } = format;
|
|
215
|
-
const minimalFormatter = printf(({ level, message, label, timestamp }) => {
|
|
216
|
-
return `${timestamp} [${label}] ${level}: ${message}`;
|
|
217
|
-
});
|
|
218
|
-
const detailedFormatter = printf(({ level, message, label, timestamp }) => {
|
|
219
|
-
return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
|
|
220
|
-
});
|
|
221
|
-
const emojiFormatter = printf(({ level, message, label, timestamp }) => {
|
|
222
|
-
return `${timestamp} [${label}] ${level.toUpperCase()}: ${message}`;
|
|
223
|
-
});
|
|
224
|
-
switch (this.currentFormat) {
|
|
225
|
-
case "minimal":
|
|
226
|
-
return minimalFormatter;
|
|
227
|
-
case "detailed":
|
|
228
|
-
return detailedFormatter;
|
|
229
|
-
case "emoji":
|
|
230
|
-
return emojiFormatter;
|
|
231
|
-
default:
|
|
232
|
-
return minimalFormatter;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
static async configure(options = {}) {
|
|
236
|
-
const { level, console: console2 = true, file, format = "minimal" } = options;
|
|
237
|
-
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
238
|
-
const resolvedLevel = level ?? resolveLevel(debugEnv);
|
|
239
|
-
this.currentFormat = format;
|
|
240
|
-
if (!isNodeJSEnvironment()) {
|
|
241
|
-
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
242
|
-
logger2.level = resolvedLevel;
|
|
243
|
-
});
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
await getWinston();
|
|
247
|
-
if (!winston) {
|
|
248
|
-
throw new Error("Failed to load winston");
|
|
249
|
-
}
|
|
250
|
-
const root = this.get();
|
|
251
|
-
root.level = resolvedLevel;
|
|
252
|
-
const winstonRoot = root;
|
|
253
|
-
winstonRoot.clear();
|
|
254
|
-
if (console2) {
|
|
255
|
-
winstonRoot.add(new winston.transports.Console());
|
|
256
|
-
}
|
|
257
|
-
if (file) {
|
|
258
|
-
const { fs: nodeFs, path: nodePath } = await getNodeModules();
|
|
259
|
-
if (nodeFs && nodePath) {
|
|
260
|
-
const dir = nodePath.dirname(nodePath.resolve(file));
|
|
261
|
-
if (!nodeFs.existsSync(dir)) {
|
|
262
|
-
nodeFs.mkdirSync(dir, { recursive: true });
|
|
263
|
-
}
|
|
264
|
-
winstonRoot.add(new winston.transports.File({ filename: file }));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const { format: winstonFormat } = winston;
|
|
268
|
-
const { combine, timestamp, label, colorize, splat } = winstonFormat;
|
|
269
|
-
Object.values(this.instances).forEach((logger2) => {
|
|
270
|
-
if (logger2 && "format" in logger2) {
|
|
271
|
-
logger2.level = resolvedLevel;
|
|
272
|
-
logger2.format = combine(
|
|
273
|
-
colorize(),
|
|
274
|
-
splat(),
|
|
275
|
-
label({ label: DEFAULT_LOGGER_NAME }),
|
|
276
|
-
timestamp({ format: "HH:mm:ss" }),
|
|
277
|
-
this.getFormatter()
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
static setDebug(enabled) {
|
|
283
|
-
let level;
|
|
284
|
-
if (enabled === 2 || enabled === true) level = "debug";
|
|
285
|
-
else if (enabled === 1) level = "info";
|
|
286
|
-
else level = "info";
|
|
287
|
-
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
288
|
-
logger2.level = level;
|
|
289
|
-
});
|
|
290
|
-
Object.values(this.instances).forEach((logger2) => {
|
|
291
|
-
if (logger2) {
|
|
292
|
-
logger2.level = level;
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
if (typeof process !== "undefined" && process.env) {
|
|
296
|
-
process.env.DEBUG = enabled ? enabled === true ? "2" : String(enabled) : "0";
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
static setFormat(format) {
|
|
300
|
-
this.currentFormat = format;
|
|
301
|
-
this.configure({ format });
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
if (isNodeJSEnvironment()) {
|
|
305
|
-
loadWinstonSync();
|
|
306
|
-
if (winston) {
|
|
307
|
-
Logger.configure();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
var logger = Logger.get();
|
|
311
|
-
|
|
312
|
-
// src/server/utils/runtime.ts
|
|
313
|
-
var isDeno = typeof globalThis.Deno !== "undefined";
|
|
314
|
-
|
|
315
|
-
// src/client/connectors/codeMode.ts
|
|
316
|
-
var CODE_MODE_AGENT_PROMPT = `
|
|
317
|
-
## MCP Code Mode Tool Usage Guide
|
|
318
|
-
|
|
319
|
-
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:
|
|
320
|
-
|
|
321
|
-
### 1. Tool Discovery Phase
|
|
322
|
-
**Always start by discovering available tools:**
|
|
323
|
-
- Tools are organized by server namespace (e.g., \`server_name.tool_name\`)
|
|
324
|
-
- Use the \`search_tools(query, detail_level)\` function to find available tools
|
|
325
|
-
- You can access \`__tool_namespaces\` to see all available server namespaces
|
|
326
|
-
|
|
327
|
-
\`\`\`javascript
|
|
328
|
-
// Find all GitHub-related tools
|
|
329
|
-
const tools = await search_tools("github");
|
|
330
|
-
for (const tool of tools) {
|
|
331
|
-
console.log(\`\${tool.server}.\${tool.name}: \${tool.description}\`);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Get only tool names for quick overview
|
|
335
|
-
const tools = await search_tools("", "names");
|
|
336
|
-
\`\`\`
|
|
337
|
-
|
|
338
|
-
### 2. Interface Introspection
|
|
339
|
-
**Understand tool contracts before using them:**
|
|
340
|
-
- Use \`search_tools\` to get tool descriptions and input schemas
|
|
341
|
-
- Look for "Access as: server.tool(args)" patterns in descriptions
|
|
342
|
-
|
|
343
|
-
### 3. Code Execution Guidelines
|
|
344
|
-
**When writing code:**
|
|
345
|
-
- Use \`await server.tool({ param: value })\` syntax for all tool calls
|
|
346
|
-
- Tools are async functions that return promises
|
|
347
|
-
- You have access to standard JavaScript globals: \`console\`, \`JSON\`, \`Math\`, \`Date\`, etc.
|
|
348
|
-
- All console output (\`console.log\`, \`console.error\`, etc.) is automatically captured and returned
|
|
349
|
-
- Build properly structured input objects based on interface definitions
|
|
350
|
-
- Handle errors appropriately with try/catch blocks
|
|
351
|
-
- Chain tool calls by using results from previous calls
|
|
352
|
-
|
|
353
|
-
### 4. Best Practices
|
|
354
|
-
- **Discover first, code second**: Always explore available tools before writing execution code
|
|
355
|
-
- **Respect namespaces**: Use full \`server.tool\` names to avoid conflicts
|
|
356
|
-
- **Minimize Context**: Process large data in code, return only essential results
|
|
357
|
-
- **Error handling**: Wrap tool calls in try/catch for robustness
|
|
358
|
-
- **Data flow**: Chain tools by passing outputs as inputs to subsequent tools
|
|
359
|
-
|
|
360
|
-
### 5. Available Runtime Context
|
|
361
|
-
- \`search_tools(query, detail_level)\`: Function to discover tools
|
|
362
|
-
- \`__tool_namespaces\`: Array of available server namespaces
|
|
363
|
-
- All registered tools as \`server.tool\` functions
|
|
364
|
-
- Standard JavaScript built-ins for data processing
|
|
365
|
-
|
|
366
|
-
### Example Workflow
|
|
367
|
-
|
|
368
|
-
\`\`\`javascript
|
|
369
|
-
// 1. Discover available tools
|
|
370
|
-
const github_tools = await search_tools("github pull request");
|
|
371
|
-
console.log(\`Available GitHub PR tools: \${github_tools.map(t => t.name)}\`);
|
|
372
|
-
|
|
373
|
-
// 2. Call tools with proper parameters
|
|
374
|
-
const pr = await github.get_pull_request({
|
|
375
|
-
owner: "facebook",
|
|
376
|
-
repo: "react",
|
|
377
|
-
number: 12345
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
// 3. Process results
|
|
381
|
-
let result;
|
|
382
|
-
if (pr.state === 'open' && pr.labels.some(l => l.name === 'bug')) {
|
|
383
|
-
// 4. Chain with other tools
|
|
384
|
-
await slack.post_message({
|
|
385
|
-
channel: "#bugs",
|
|
386
|
-
text: \`\u{1F41B} Bug PR needs review: \${pr.title}\`
|
|
387
|
-
});
|
|
388
|
-
result = "Notification sent";
|
|
389
|
-
} else {
|
|
390
|
-
result = "No action needed";
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// 5. Return structured results
|
|
394
|
-
return {
|
|
395
|
-
pr_number: pr.number,
|
|
396
|
-
pr_title: pr.title,
|
|
397
|
-
action_taken: result
|
|
398
|
-
};
|
|
399
|
-
\`\`\`
|
|
400
|
-
|
|
401
|
-
Remember: Always discover and understand available tools before attempting to use them in code execution.
|
|
402
|
-
`;
|
|
403
|
-
|
|
404
|
-
// src/client/prompts.ts
|
|
405
|
-
var PROMPTS = {
|
|
406
|
-
CODE_MODE: CODE_MODE_AGENT_PROMPT
|
|
407
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PROMPTS
|
|
3
|
-
} from "../../chunk-2RSYU23F.js";
|
|
4
|
-
import "../../chunk-AQVGN2CI.js";
|
|
5
|
-
import "../../chunk-6I4P5WXY.js";
|
|
6
|
-
import "../../chunk-TZKOAITC.js";
|
|
7
|
-
import "../../chunk-FRUZDWXH.js";
|
|
8
|
-
import "../../chunk-3GQAWCBQ.js";
|
|
9
|
-
export {
|
|
10
|
-
PROMPTS
|
|
11
|
-
};
|