@mcpc-tech/cli 0.1.25 → 0.1.26
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/bin/mcpc.cjs +126 -31
- package/bin/mcpc.mjs +126 -31
- package/package.json +1 -1
package/bin/mcpc.cjs
CHANGED
|
@@ -2372,19 +2372,9 @@ var Response2 = class _Response {
|
|
|
2372
2372
|
});
|
|
2373
2373
|
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
2374
2374
|
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
2375
|
-
var webFetch = global.fetch;
|
|
2376
2375
|
if (typeof global.crypto === "undefined") {
|
|
2377
2376
|
global.crypto = import_crypto.default;
|
|
2378
2377
|
}
|
|
2379
|
-
global.fetch = (info, init) => {
|
|
2380
|
-
init = {
|
|
2381
|
-
// Disable compression handling so people can return the result of a fetch
|
|
2382
|
-
// directly in the loader without messing with the Content-Encoding header.
|
|
2383
|
-
compress: false,
|
|
2384
|
-
...init
|
|
2385
|
-
};
|
|
2386
|
-
return webFetch(info, init);
|
|
2387
|
-
};
|
|
2388
2378
|
var outgoingEnded = Symbol("outgoingEnded");
|
|
2389
2379
|
|
|
2390
2380
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
@@ -10212,7 +10202,16 @@ var MCPSamplingLanguageModel = class {
|
|
|
10212
10202
|
* Generate a response using MCP's createMessage capability
|
|
10213
10203
|
*/
|
|
10214
10204
|
async doGenerate(options) {
|
|
10215
|
-
const
|
|
10205
|
+
const useNativeTools = this.supportsSamplingTools();
|
|
10206
|
+
this.server.sendLoggingMessage({
|
|
10207
|
+
level: "info",
|
|
10208
|
+
data: `Client supports native tools: ${useNativeTools}`
|
|
10209
|
+
});
|
|
10210
|
+
const messages = this.convertMessages(options.prompt, useNativeTools);
|
|
10211
|
+
this.server.sendLoggingMessage({
|
|
10212
|
+
level: "info",
|
|
10213
|
+
data: `Converted messages for MCP: ${JSON.stringify(messages)}`
|
|
10214
|
+
});
|
|
10216
10215
|
let systemPrompt;
|
|
10217
10216
|
for (const msg of options.prompt) {
|
|
10218
10217
|
if (msg.role === "system") {
|
|
@@ -10220,7 +10219,10 @@ var MCPSamplingLanguageModel = class {
|
|
|
10220
10219
|
break;
|
|
10221
10220
|
}
|
|
10222
10221
|
}
|
|
10223
|
-
|
|
10222
|
+
this.server.sendLoggingMessage({
|
|
10223
|
+
level: "info",
|
|
10224
|
+
data: `Client supports native tools: ${useNativeTools}`
|
|
10225
|
+
});
|
|
10224
10226
|
systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
|
|
10225
10227
|
systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
|
|
10226
10228
|
const createMessageParams = {
|
|
@@ -10234,8 +10236,34 @@ var MCPSamplingLanguageModel = class {
|
|
|
10234
10236
|
createMessageParams.toolChoice = {
|
|
10235
10237
|
mode: "auto"
|
|
10236
10238
|
};
|
|
10239
|
+
this.server.sendLoggingMessage({
|
|
10240
|
+
level: "info",
|
|
10241
|
+
data: `Converted ${options.tools.length} tools to MCP format: ${JSON.stringify(createMessageParams.tools?.map((t) => t.name))}`
|
|
10242
|
+
});
|
|
10243
|
+
} else if (options.tools && options.tools.length > 0) {
|
|
10244
|
+
this.server.sendLoggingMessage({
|
|
10245
|
+
level: "info",
|
|
10246
|
+
data: `Tools provided but not using native mode - injecting into system prompt instead`
|
|
10247
|
+
});
|
|
10237
10248
|
}
|
|
10249
|
+
this.server.sendLoggingMessage({
|
|
10250
|
+
level: "info",
|
|
10251
|
+
data: `Calling createMessage with params: ${JSON.stringify({
|
|
10252
|
+
hasSystemPrompt: !!systemPrompt,
|
|
10253
|
+
hasTools: !!createMessageParams.tools,
|
|
10254
|
+
toolCount: createMessageParams.tools?.length || 0,
|
|
10255
|
+
createMessageParams
|
|
10256
|
+
}, null, 2)}`
|
|
10257
|
+
});
|
|
10238
10258
|
const result = await this.server.createMessage(createMessageParams);
|
|
10259
|
+
this.server.sendLoggingMessage({
|
|
10260
|
+
level: "info",
|
|
10261
|
+
data: `createMessage result: ${JSON.stringify({
|
|
10262
|
+
contentType: result.content.type,
|
|
10263
|
+
stopReason: result.stopReason,
|
|
10264
|
+
text: result.content
|
|
10265
|
+
})}`
|
|
10266
|
+
});
|
|
10239
10267
|
const content = [];
|
|
10240
10268
|
if (useNativeTools) {
|
|
10241
10269
|
const contentArray = Array.isArray(result.content) ? result.content : [
|
|
@@ -10353,8 +10381,52 @@ var MCPSamplingLanguageModel = class {
|
|
|
10353
10381
|
/**
|
|
10354
10382
|
* Convert AI SDK messages to MCP sampling format
|
|
10355
10383
|
*/
|
|
10356
|
-
convertMessages(prompt) {
|
|
10357
|
-
|
|
10384
|
+
convertMessages(prompt, useNativeTools) {
|
|
10385
|
+
if (!useNativeTools) {
|
|
10386
|
+
return convertAISDKToMCPMessages(prompt);
|
|
10387
|
+
}
|
|
10388
|
+
const messages = [];
|
|
10389
|
+
for (const msg of prompt) {
|
|
10390
|
+
if (msg.role === "system") continue;
|
|
10391
|
+
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
10392
|
+
const contentBlocks = [];
|
|
10393
|
+
for (const part of msg.content) {
|
|
10394
|
+
if (part.type === "text") {
|
|
10395
|
+
contentBlocks.push({
|
|
10396
|
+
type: "text",
|
|
10397
|
+
text: part.text
|
|
10398
|
+
});
|
|
10399
|
+
} else if (part.type === "tool-call") {
|
|
10400
|
+
const call = part;
|
|
10401
|
+
contentBlocks.push({
|
|
10402
|
+
type: "tool_use",
|
|
10403
|
+
id: call.toolCallId,
|
|
10404
|
+
name: call.toolName,
|
|
10405
|
+
input: call.args ?? call.input ?? {}
|
|
10406
|
+
});
|
|
10407
|
+
} else if (part.type === "tool-result") {
|
|
10408
|
+
const result = part;
|
|
10409
|
+
contentBlocks.push({
|
|
10410
|
+
type: "tool_result",
|
|
10411
|
+
toolUseId: result.toolCallId,
|
|
10412
|
+
// TODO: Handle different result types properly
|
|
10413
|
+
content: [
|
|
10414
|
+
{
|
|
10415
|
+
type: "text",
|
|
10416
|
+
text: result.output.type === "text" ? result.output.value?.toString() : JSON.stringify(result.output)
|
|
10417
|
+
}
|
|
10418
|
+
]
|
|
10419
|
+
});
|
|
10420
|
+
}
|
|
10421
|
+
}
|
|
10422
|
+
if (contentBlocks.length > 0) {
|
|
10423
|
+
messages.push({
|
|
10424
|
+
role,
|
|
10425
|
+
content: contentBlocks
|
|
10426
|
+
});
|
|
10427
|
+
}
|
|
10428
|
+
}
|
|
10429
|
+
return messages;
|
|
10358
10430
|
}
|
|
10359
10431
|
/**
|
|
10360
10432
|
* Map MCP stop reason to AI SDK finish reason
|
|
@@ -10367,7 +10439,12 @@ var MCPSamplingLanguageModel = class {
|
|
|
10367
10439
|
*/
|
|
10368
10440
|
supportsSamplingTools() {
|
|
10369
10441
|
const capabilities = this.server.getClientCapabilities();
|
|
10370
|
-
|
|
10442
|
+
const supportsTools = !!capabilities?.sampling?.tools;
|
|
10443
|
+
this.server.sendLoggingMessage({
|
|
10444
|
+
level: "info",
|
|
10445
|
+
data: `Client capabilities check: sampling=${!!capabilities?.sampling}, tools=${supportsTools}`
|
|
10446
|
+
});
|
|
10447
|
+
return supportsTools;
|
|
10371
10448
|
}
|
|
10372
10449
|
/**
|
|
10373
10450
|
* Convert AI SDK tools to MCP Tool format
|
|
@@ -10433,8 +10510,16 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
10433
10510
|
return systemPrompt;
|
|
10434
10511
|
}
|
|
10435
10512
|
if (useNativeTools) {
|
|
10513
|
+
this.server.sendLoggingMessage({
|
|
10514
|
+
level: "info",
|
|
10515
|
+
data: `Using native tools mode - skipping XML tool injection`
|
|
10516
|
+
});
|
|
10436
10517
|
return systemPrompt;
|
|
10437
10518
|
}
|
|
10519
|
+
this.server.sendLoggingMessage({
|
|
10520
|
+
level: "info",
|
|
10521
|
+
data: `Injecting ${tools.length} tools into system prompt (fallback mode)`
|
|
10522
|
+
});
|
|
10438
10523
|
let enhanced = systemPrompt || "";
|
|
10439
10524
|
const toolsPrompt = `
|
|
10440
10525
|
|
|
@@ -10445,7 +10530,7 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
10445
10530
|
</use_tool>
|
|
10446
10531
|
|
|
10447
10532
|
Follow the JSON schema definition for each tool's parameters.
|
|
10448
|
-
You can use multiple tools in one response.
|
|
10533
|
+
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
10449
10534
|
|
|
10450
10535
|
Tools:`;
|
|
10451
10536
|
const toolDescriptions = tools.map((tool2) => {
|
|
@@ -12062,15 +12147,18 @@ function createSearchPlugin(options = {}) {
|
|
|
12062
12147
|
const allowedSearchDir = options.allowedDir || (0, import_node_os2.tmpdir)();
|
|
12063
12148
|
const timeoutMs = options.timeoutMs || 3e4;
|
|
12064
12149
|
const global2 = options.global ?? true;
|
|
12150
|
+
const agentName = options.agentName;
|
|
12151
|
+
const toolName = agentName ? `${agentName}__search-tool-result` : "search-tool-result";
|
|
12065
12152
|
const activeTimeouts = /* @__PURE__ */ new Set();
|
|
12066
12153
|
return {
|
|
12067
12154
|
name: "plugin-search",
|
|
12068
12155
|
version: "1.0.0",
|
|
12069
12156
|
configureServer: (server) => {
|
|
12070
|
-
const defaultDescription = `Search for text patterns in files
|
|
12157
|
+
const defaultDescription = agentName ? `Search for text patterns in files for the "${agentName}" agent. Use this to find specific content within large tool results. Provide a simple literal string or a regular expression.
|
|
12158
|
+
Only search within the allowed directory: ${allowedSearchDir}` : `Search for text patterns in files and directories. Use this to find specific content, code, or information within files. Provide a simple literal string or a regular expression. If your pattern is a regex, ensure it's valid; otherwise use quotes or escape special characters to treat it as a literal string.
|
|
12071
12159
|
Only search within the allowed directory: ${allowedSearchDir}`;
|
|
12072
12160
|
const toolDescription = options.toolDescription || defaultDescription;
|
|
12073
|
-
server.tool(
|
|
12161
|
+
server.tool(toolName, toolDescription, jsonSchema({
|
|
12074
12162
|
type: "object",
|
|
12075
12163
|
properties: {
|
|
12076
12164
|
pattern: {
|
|
@@ -12285,27 +12373,33 @@ function createLargeResultPlugin(options = {}) {
|
|
|
12285
12373
|
const maxSize = options.maxSize || 8e3;
|
|
12286
12374
|
const previewSize = options.previewSize || 4e3;
|
|
12287
12375
|
let tempDir = options.tempDir || null;
|
|
12288
|
-
|
|
12376
|
+
let serverRef = null;
|
|
12377
|
+
let agentName = null;
|
|
12289
12378
|
const defaultSearchDescription = `Search within large tool result files that were saved due to size limits. Use when: a tool result was saved to file because it exceeded the context limit. Do NOT use this tool before calling the actual tool first. Provide specific keywords or patterns related to the content you're looking for.`;
|
|
12290
|
-
const searchConfig = {
|
|
12291
|
-
maxResults: options.search?.maxResults || 15,
|
|
12292
|
-
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
12293
|
-
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
12294
|
-
global: true
|
|
12295
|
-
};
|
|
12296
12379
|
return {
|
|
12297
12380
|
name: "plugin-large-result-handler",
|
|
12298
12381
|
version: "1.0.0",
|
|
12299
12382
|
dependencies: [],
|
|
12300
|
-
configureServer:
|
|
12301
|
-
|
|
12383
|
+
configureServer: (server) => {
|
|
12384
|
+
serverRef = server;
|
|
12385
|
+
},
|
|
12386
|
+
composeStart: async (context2) => {
|
|
12387
|
+
agentName = context2.serverName;
|
|
12388
|
+
if (serverRef) {
|
|
12389
|
+
const searchConfig = {
|
|
12390
|
+
maxResults: options.search?.maxResults || 15,
|
|
12391
|
+
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
12392
|
+
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
12393
|
+
global: true,
|
|
12394
|
+
agentName
|
|
12395
|
+
};
|
|
12302
12396
|
const searchPlugin = createSearchPlugin(searchConfig);
|
|
12303
|
-
await
|
|
12304
|
-
configuredServers.set(server, true);
|
|
12397
|
+
await serverRef.addPlugin(searchPlugin);
|
|
12305
12398
|
}
|
|
12306
12399
|
},
|
|
12307
12400
|
transformTool: (tool2, context2) => {
|
|
12308
12401
|
const originalExecute = tool2.execute;
|
|
12402
|
+
const searchToolName = agentName ? `${agentName}__search-tool-result` : "search-tool-result";
|
|
12309
12403
|
tool2.execute = async (args) => {
|
|
12310
12404
|
try {
|
|
12311
12405
|
const result = await originalExecute(args);
|
|
@@ -12337,7 +12431,7 @@ ${preview}
|
|
|
12337
12431
|
\`\`\`
|
|
12338
12432
|
|
|
12339
12433
|
**To read/understand the full content:**
|
|
12340
|
-
- Use the \`
|
|
12434
|
+
- Use the \`${searchToolName}\` tool with pattern: \`${searchToolName} {"pattern": "your-search-term"}\`
|
|
12341
12435
|
- Search supports regex patterns for advanced queries`
|
|
12342
12436
|
}
|
|
12343
12437
|
]
|
|
@@ -12351,7 +12445,8 @@ ${preview}
|
|
|
12351
12445
|
return tool2;
|
|
12352
12446
|
},
|
|
12353
12447
|
dispose: () => {
|
|
12354
|
-
|
|
12448
|
+
serverRef = null;
|
|
12449
|
+
agentName = null;
|
|
12355
12450
|
tempDir = null;
|
|
12356
12451
|
}
|
|
12357
12452
|
};
|
package/bin/mcpc.mjs
CHANGED
|
@@ -2380,19 +2380,9 @@ var Response2 = class _Response {
|
|
|
2380
2380
|
});
|
|
2381
2381
|
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
2382
2382
|
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
2383
|
-
var webFetch = global.fetch;
|
|
2384
2383
|
if (typeof global.crypto === "undefined") {
|
|
2385
2384
|
global.crypto = crypto2;
|
|
2386
2385
|
}
|
|
2387
|
-
global.fetch = (info, init) => {
|
|
2388
|
-
init = {
|
|
2389
|
-
// Disable compression handling so people can return the result of a fetch
|
|
2390
|
-
// directly in the loader without messing with the Content-Encoding header.
|
|
2391
|
-
compress: false,
|
|
2392
|
-
...init
|
|
2393
|
-
};
|
|
2394
|
-
return webFetch(info, init);
|
|
2395
|
-
};
|
|
2396
2386
|
var outgoingEnded = Symbol("outgoingEnded");
|
|
2397
2387
|
|
|
2398
2388
|
// __mcpc__cli_latest/node_modules/@mcpc/cli/src/config/loader.js
|
|
@@ -10220,7 +10210,16 @@ var MCPSamplingLanguageModel = class {
|
|
|
10220
10210
|
* Generate a response using MCP's createMessage capability
|
|
10221
10211
|
*/
|
|
10222
10212
|
async doGenerate(options) {
|
|
10223
|
-
const
|
|
10213
|
+
const useNativeTools = this.supportsSamplingTools();
|
|
10214
|
+
this.server.sendLoggingMessage({
|
|
10215
|
+
level: "info",
|
|
10216
|
+
data: `Client supports native tools: ${useNativeTools}`
|
|
10217
|
+
});
|
|
10218
|
+
const messages = this.convertMessages(options.prompt, useNativeTools);
|
|
10219
|
+
this.server.sendLoggingMessage({
|
|
10220
|
+
level: "info",
|
|
10221
|
+
data: `Converted messages for MCP: ${JSON.stringify(messages)}`
|
|
10222
|
+
});
|
|
10224
10223
|
let systemPrompt;
|
|
10225
10224
|
for (const msg of options.prompt) {
|
|
10226
10225
|
if (msg.role === "system") {
|
|
@@ -10228,7 +10227,10 @@ var MCPSamplingLanguageModel = class {
|
|
|
10228
10227
|
break;
|
|
10229
10228
|
}
|
|
10230
10229
|
}
|
|
10231
|
-
|
|
10230
|
+
this.server.sendLoggingMessage({
|
|
10231
|
+
level: "info",
|
|
10232
|
+
data: `Client supports native tools: ${useNativeTools}`
|
|
10233
|
+
});
|
|
10232
10234
|
systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
|
|
10233
10235
|
systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
|
|
10234
10236
|
const createMessageParams = {
|
|
@@ -10242,8 +10244,34 @@ var MCPSamplingLanguageModel = class {
|
|
|
10242
10244
|
createMessageParams.toolChoice = {
|
|
10243
10245
|
mode: "auto"
|
|
10244
10246
|
};
|
|
10247
|
+
this.server.sendLoggingMessage({
|
|
10248
|
+
level: "info",
|
|
10249
|
+
data: `Converted ${options.tools.length} tools to MCP format: ${JSON.stringify(createMessageParams.tools?.map((t) => t.name))}`
|
|
10250
|
+
});
|
|
10251
|
+
} else if (options.tools && options.tools.length > 0) {
|
|
10252
|
+
this.server.sendLoggingMessage({
|
|
10253
|
+
level: "info",
|
|
10254
|
+
data: `Tools provided but not using native mode - injecting into system prompt instead`
|
|
10255
|
+
});
|
|
10245
10256
|
}
|
|
10257
|
+
this.server.sendLoggingMessage({
|
|
10258
|
+
level: "info",
|
|
10259
|
+
data: `Calling createMessage with params: ${JSON.stringify({
|
|
10260
|
+
hasSystemPrompt: !!systemPrompt,
|
|
10261
|
+
hasTools: !!createMessageParams.tools,
|
|
10262
|
+
toolCount: createMessageParams.tools?.length || 0,
|
|
10263
|
+
createMessageParams
|
|
10264
|
+
}, null, 2)}`
|
|
10265
|
+
});
|
|
10246
10266
|
const result = await this.server.createMessage(createMessageParams);
|
|
10267
|
+
this.server.sendLoggingMessage({
|
|
10268
|
+
level: "info",
|
|
10269
|
+
data: `createMessage result: ${JSON.stringify({
|
|
10270
|
+
contentType: result.content.type,
|
|
10271
|
+
stopReason: result.stopReason,
|
|
10272
|
+
text: result.content
|
|
10273
|
+
})}`
|
|
10274
|
+
});
|
|
10247
10275
|
const content = [];
|
|
10248
10276
|
if (useNativeTools) {
|
|
10249
10277
|
const contentArray = Array.isArray(result.content) ? result.content : [
|
|
@@ -10361,8 +10389,52 @@ var MCPSamplingLanguageModel = class {
|
|
|
10361
10389
|
/**
|
|
10362
10390
|
* Convert AI SDK messages to MCP sampling format
|
|
10363
10391
|
*/
|
|
10364
|
-
convertMessages(prompt) {
|
|
10365
|
-
|
|
10392
|
+
convertMessages(prompt, useNativeTools) {
|
|
10393
|
+
if (!useNativeTools) {
|
|
10394
|
+
return convertAISDKToMCPMessages(prompt);
|
|
10395
|
+
}
|
|
10396
|
+
const messages = [];
|
|
10397
|
+
for (const msg of prompt) {
|
|
10398
|
+
if (msg.role === "system") continue;
|
|
10399
|
+
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
10400
|
+
const contentBlocks = [];
|
|
10401
|
+
for (const part of msg.content) {
|
|
10402
|
+
if (part.type === "text") {
|
|
10403
|
+
contentBlocks.push({
|
|
10404
|
+
type: "text",
|
|
10405
|
+
text: part.text
|
|
10406
|
+
});
|
|
10407
|
+
} else if (part.type === "tool-call") {
|
|
10408
|
+
const call = part;
|
|
10409
|
+
contentBlocks.push({
|
|
10410
|
+
type: "tool_use",
|
|
10411
|
+
id: call.toolCallId,
|
|
10412
|
+
name: call.toolName,
|
|
10413
|
+
input: call.args ?? call.input ?? {}
|
|
10414
|
+
});
|
|
10415
|
+
} else if (part.type === "tool-result") {
|
|
10416
|
+
const result = part;
|
|
10417
|
+
contentBlocks.push({
|
|
10418
|
+
type: "tool_result",
|
|
10419
|
+
toolUseId: result.toolCallId,
|
|
10420
|
+
// TODO: Handle different result types properly
|
|
10421
|
+
content: [
|
|
10422
|
+
{
|
|
10423
|
+
type: "text",
|
|
10424
|
+
text: result.output.type === "text" ? result.output.value?.toString() : JSON.stringify(result.output)
|
|
10425
|
+
}
|
|
10426
|
+
]
|
|
10427
|
+
});
|
|
10428
|
+
}
|
|
10429
|
+
}
|
|
10430
|
+
if (contentBlocks.length > 0) {
|
|
10431
|
+
messages.push({
|
|
10432
|
+
role,
|
|
10433
|
+
content: contentBlocks
|
|
10434
|
+
});
|
|
10435
|
+
}
|
|
10436
|
+
}
|
|
10437
|
+
return messages;
|
|
10366
10438
|
}
|
|
10367
10439
|
/**
|
|
10368
10440
|
* Map MCP stop reason to AI SDK finish reason
|
|
@@ -10375,7 +10447,12 @@ var MCPSamplingLanguageModel = class {
|
|
|
10375
10447
|
*/
|
|
10376
10448
|
supportsSamplingTools() {
|
|
10377
10449
|
const capabilities = this.server.getClientCapabilities();
|
|
10378
|
-
|
|
10450
|
+
const supportsTools = !!capabilities?.sampling?.tools;
|
|
10451
|
+
this.server.sendLoggingMessage({
|
|
10452
|
+
level: "info",
|
|
10453
|
+
data: `Client capabilities check: sampling=${!!capabilities?.sampling}, tools=${supportsTools}`
|
|
10454
|
+
});
|
|
10455
|
+
return supportsTools;
|
|
10379
10456
|
}
|
|
10380
10457
|
/**
|
|
10381
10458
|
* Convert AI SDK tools to MCP Tool format
|
|
@@ -10441,8 +10518,16 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
10441
10518
|
return systemPrompt;
|
|
10442
10519
|
}
|
|
10443
10520
|
if (useNativeTools) {
|
|
10521
|
+
this.server.sendLoggingMessage({
|
|
10522
|
+
level: "info",
|
|
10523
|
+
data: `Using native tools mode - skipping XML tool injection`
|
|
10524
|
+
});
|
|
10444
10525
|
return systemPrompt;
|
|
10445
10526
|
}
|
|
10527
|
+
this.server.sendLoggingMessage({
|
|
10528
|
+
level: "info",
|
|
10529
|
+
data: `Injecting ${tools.length} tools into system prompt (fallback mode)`
|
|
10530
|
+
});
|
|
10446
10531
|
let enhanced = systemPrompt || "";
|
|
10447
10532
|
const toolsPrompt = `
|
|
10448
10533
|
|
|
@@ -10453,7 +10538,7 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
10453
10538
|
</use_tool>
|
|
10454
10539
|
|
|
10455
10540
|
Follow the JSON schema definition for each tool's parameters.
|
|
10456
|
-
You can use multiple tools in one response.
|
|
10541
|
+
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
10457
10542
|
|
|
10458
10543
|
Tools:`;
|
|
10459
10544
|
const toolDescriptions = tools.map((tool2) => {
|
|
@@ -12069,15 +12154,18 @@ function createSearchPlugin(options = {}) {
|
|
|
12069
12154
|
const allowedSearchDir = options.allowedDir || tmpdir();
|
|
12070
12155
|
const timeoutMs = options.timeoutMs || 3e4;
|
|
12071
12156
|
const global2 = options.global ?? true;
|
|
12157
|
+
const agentName = options.agentName;
|
|
12158
|
+
const toolName = agentName ? `${agentName}__search-tool-result` : "search-tool-result";
|
|
12072
12159
|
const activeTimeouts = /* @__PURE__ */ new Set();
|
|
12073
12160
|
return {
|
|
12074
12161
|
name: "plugin-search",
|
|
12075
12162
|
version: "1.0.0",
|
|
12076
12163
|
configureServer: (server) => {
|
|
12077
|
-
const defaultDescription = `Search for text patterns in files
|
|
12164
|
+
const defaultDescription = agentName ? `Search for text patterns in files for the "${agentName}" agent. Use this to find specific content within large tool results. Provide a simple literal string or a regular expression.
|
|
12165
|
+
Only search within the allowed directory: ${allowedSearchDir}` : `Search for text patterns in files and directories. Use this to find specific content, code, or information within files. Provide a simple literal string or a regular expression. If your pattern is a regex, ensure it's valid; otherwise use quotes or escape special characters to treat it as a literal string.
|
|
12078
12166
|
Only search within the allowed directory: ${allowedSearchDir}`;
|
|
12079
12167
|
const toolDescription = options.toolDescription || defaultDescription;
|
|
12080
|
-
server.tool(
|
|
12168
|
+
server.tool(toolName, toolDescription, jsonSchema({
|
|
12081
12169
|
type: "object",
|
|
12082
12170
|
properties: {
|
|
12083
12171
|
pattern: {
|
|
@@ -12292,27 +12380,33 @@ function createLargeResultPlugin(options = {}) {
|
|
|
12292
12380
|
const maxSize = options.maxSize || 8e3;
|
|
12293
12381
|
const previewSize = options.previewSize || 4e3;
|
|
12294
12382
|
let tempDir = options.tempDir || null;
|
|
12295
|
-
|
|
12383
|
+
let serverRef = null;
|
|
12384
|
+
let agentName = null;
|
|
12296
12385
|
const defaultSearchDescription = `Search within large tool result files that were saved due to size limits. Use when: a tool result was saved to file because it exceeded the context limit. Do NOT use this tool before calling the actual tool first. Provide specific keywords or patterns related to the content you're looking for.`;
|
|
12297
|
-
const searchConfig = {
|
|
12298
|
-
maxResults: options.search?.maxResults || 15,
|
|
12299
|
-
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
12300
|
-
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
12301
|
-
global: true
|
|
12302
|
-
};
|
|
12303
12386
|
return {
|
|
12304
12387
|
name: "plugin-large-result-handler",
|
|
12305
12388
|
version: "1.0.0",
|
|
12306
12389
|
dependencies: [],
|
|
12307
|
-
configureServer:
|
|
12308
|
-
|
|
12390
|
+
configureServer: (server) => {
|
|
12391
|
+
serverRef = server;
|
|
12392
|
+
},
|
|
12393
|
+
composeStart: async (context2) => {
|
|
12394
|
+
agentName = context2.serverName;
|
|
12395
|
+
if (serverRef) {
|
|
12396
|
+
const searchConfig = {
|
|
12397
|
+
maxResults: options.search?.maxResults || 15,
|
|
12398
|
+
maxOutputSize: options.search?.maxOutputSize || 4e3,
|
|
12399
|
+
toolDescription: options.search?.toolDescription || defaultSearchDescription,
|
|
12400
|
+
global: true,
|
|
12401
|
+
agentName
|
|
12402
|
+
};
|
|
12309
12403
|
const searchPlugin = createSearchPlugin(searchConfig);
|
|
12310
|
-
await
|
|
12311
|
-
configuredServers.set(server, true);
|
|
12404
|
+
await serverRef.addPlugin(searchPlugin);
|
|
12312
12405
|
}
|
|
12313
12406
|
},
|
|
12314
12407
|
transformTool: (tool2, context2) => {
|
|
12315
12408
|
const originalExecute = tool2.execute;
|
|
12409
|
+
const searchToolName = agentName ? `${agentName}__search-tool-result` : "search-tool-result";
|
|
12316
12410
|
tool2.execute = async (args) => {
|
|
12317
12411
|
try {
|
|
12318
12412
|
const result = await originalExecute(args);
|
|
@@ -12344,7 +12438,7 @@ ${preview}
|
|
|
12344
12438
|
\`\`\`
|
|
12345
12439
|
|
|
12346
12440
|
**To read/understand the full content:**
|
|
12347
|
-
- Use the \`
|
|
12441
|
+
- Use the \`${searchToolName}\` tool with pattern: \`${searchToolName} {"pattern": "your-search-term"}\`
|
|
12348
12442
|
- Search supports regex patterns for advanced queries`
|
|
12349
12443
|
}
|
|
12350
12444
|
]
|
|
@@ -12358,7 +12452,8 @@ ${preview}
|
|
|
12358
12452
|
return tool2;
|
|
12359
12453
|
},
|
|
12360
12454
|
dispose: () => {
|
|
12361
|
-
|
|
12455
|
+
serverRef = null;
|
|
12456
|
+
agentName = null;
|
|
12362
12457
|
tempDir = null;
|
|
12363
12458
|
}
|
|
12364
12459
|
};
|