@mcpc-tech/core 0.3.24 → 0.3.25
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/index.cjs +299 -9
- package/index.mjs +299 -9
- package/package.json +1 -1
- package/types/mod.d.ts +1 -1
- package/types/mod.d.ts.map +1 -1
- package/types/src/compose.d.ts +5 -1
- package/types/src/compose.d.ts.map +1 -1
- package/types/src/plugin-types.d.ts +64 -0
- package/types/src/plugin-types.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -18310,7 +18310,9 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
18310
18310
|
tool: tool2
|
|
18311
18311
|
});
|
|
18312
18312
|
try {
|
|
18313
|
-
const result = await this.server.callTool(tool2, toolArgs
|
|
18313
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
18314
|
+
agentName: this.name
|
|
18315
|
+
});
|
|
18314
18316
|
const callToolResult = result ?? {
|
|
18315
18317
|
content: []
|
|
18316
18318
|
};
|
|
@@ -19345,7 +19347,7 @@ function isValidPlugin(plugin) {
|
|
|
19345
19347
|
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
19346
19348
|
return false;
|
|
19347
19349
|
}
|
|
19348
|
-
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.registerAgentTool === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.dispose === "function";
|
|
19350
|
+
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.registerAgentTool === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.beforeToolExecute === "function" || typeof p2.afterToolExecute === "function" || typeof p2.dispose === "function";
|
|
19349
19351
|
if (!hasHook) return false;
|
|
19350
19352
|
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
19351
19353
|
return false;
|
|
@@ -19652,6 +19654,113 @@ var PluginManager = class {
|
|
|
19652
19654
|
}
|
|
19653
19655
|
return false;
|
|
19654
19656
|
}
|
|
19657
|
+
// === Tool Execution Lifecycle Hooks ===
|
|
19658
|
+
/**
|
|
19659
|
+
* Trigger beforeToolExecute hooks for all applicable plugins
|
|
19660
|
+
* Returns the combined result from all plugins
|
|
19661
|
+
*
|
|
19662
|
+
* Hook execution order:
|
|
19663
|
+
* 1. 'pre' enforced plugins first
|
|
19664
|
+
* 2. Normal plugins (no enforce)
|
|
19665
|
+
* 3. 'post' enforced plugins last
|
|
19666
|
+
*
|
|
19667
|
+
* If any plugin returns skipExecution=true, execution is skipped
|
|
19668
|
+
* and the result from that plugin is used.
|
|
19669
|
+
*/
|
|
19670
|
+
async triggerBeforeToolExecute(context2) {
|
|
19671
|
+
const beforePlugins = this.plugins.filter((p2) => p2.beforeToolExecute);
|
|
19672
|
+
if (beforePlugins.length === 0) {
|
|
19673
|
+
return void 0;
|
|
19674
|
+
}
|
|
19675
|
+
const sortedPlugins = sortPluginsByOrder(beforePlugins);
|
|
19676
|
+
let currentArgs = context2.args;
|
|
19677
|
+
let combinedMetadata = {};
|
|
19678
|
+
for (const plugin of sortedPlugins) {
|
|
19679
|
+
if (plugin.beforeToolExecute) {
|
|
19680
|
+
try {
|
|
19681
|
+
const result = await plugin.beforeToolExecute({
|
|
19682
|
+
...context2,
|
|
19683
|
+
args: currentArgs
|
|
19684
|
+
});
|
|
19685
|
+
if (result) {
|
|
19686
|
+
if (result.metadata) {
|
|
19687
|
+
combinedMetadata = {
|
|
19688
|
+
...combinedMetadata,
|
|
19689
|
+
...result.metadata
|
|
19690
|
+
};
|
|
19691
|
+
}
|
|
19692
|
+
if (result.skipExecution) {
|
|
19693
|
+
return {
|
|
19694
|
+
skipExecution: true,
|
|
19695
|
+
result: result.result,
|
|
19696
|
+
metadata: combinedMetadata
|
|
19697
|
+
};
|
|
19698
|
+
}
|
|
19699
|
+
if (result.modifiedArgs !== void 0) {
|
|
19700
|
+
currentArgs = result.modifiedArgs;
|
|
19701
|
+
}
|
|
19702
|
+
}
|
|
19703
|
+
} catch (error2) {
|
|
19704
|
+
const errorMsg = error2 instanceof Error ? error2.message : String(error2);
|
|
19705
|
+
await this.logger.error(`Plugin "${plugin.name}" beforeToolExecute failed for "${context2.toolName}": ${errorMsg}`);
|
|
19706
|
+
}
|
|
19707
|
+
}
|
|
19708
|
+
}
|
|
19709
|
+
if (currentArgs !== context2.args) {
|
|
19710
|
+
return {
|
|
19711
|
+
modifiedArgs: currentArgs,
|
|
19712
|
+
metadata: Object.keys(combinedMetadata).length > 0 ? combinedMetadata : void 0
|
|
19713
|
+
};
|
|
19714
|
+
}
|
|
19715
|
+
if (Object.keys(combinedMetadata).length > 0) {
|
|
19716
|
+
return {
|
|
19717
|
+
metadata: combinedMetadata
|
|
19718
|
+
};
|
|
19719
|
+
}
|
|
19720
|
+
return void 0;
|
|
19721
|
+
}
|
|
19722
|
+
/**
|
|
19723
|
+
* Trigger afterToolExecute hooks for all applicable plugins
|
|
19724
|
+
* Returns the final result after all plugins have processed it
|
|
19725
|
+
*/
|
|
19726
|
+
async triggerAfterToolExecute(context2) {
|
|
19727
|
+
const afterPlugins = this.plugins.filter((p2) => p2.afterToolExecute);
|
|
19728
|
+
if (afterPlugins.length === 0) {
|
|
19729
|
+
return void 0;
|
|
19730
|
+
}
|
|
19731
|
+
const sortedPlugins = sortPluginsByOrder(afterPlugins);
|
|
19732
|
+
let currentResult = context2.result;
|
|
19733
|
+
let markAsError = context2.isError;
|
|
19734
|
+
for (const plugin of sortedPlugins) {
|
|
19735
|
+
if (plugin.afterToolExecute) {
|
|
19736
|
+
try {
|
|
19737
|
+
const result = await plugin.afterToolExecute({
|
|
19738
|
+
...context2,
|
|
19739
|
+
result: currentResult,
|
|
19740
|
+
isError: markAsError
|
|
19741
|
+
});
|
|
19742
|
+
if (result) {
|
|
19743
|
+
if (result.modifiedResult !== void 0) {
|
|
19744
|
+
currentResult = result.modifiedResult;
|
|
19745
|
+
}
|
|
19746
|
+
if (result.markAsError !== void 0) {
|
|
19747
|
+
markAsError = result.markAsError;
|
|
19748
|
+
}
|
|
19749
|
+
}
|
|
19750
|
+
} catch (error2) {
|
|
19751
|
+
const errorMsg = error2 instanceof Error ? error2.message : String(error2);
|
|
19752
|
+
await this.logger.error(`Plugin "${plugin.name}" afterToolExecute failed for "${context2.toolName}": ${errorMsg}`);
|
|
19753
|
+
}
|
|
19754
|
+
}
|
|
19755
|
+
}
|
|
19756
|
+
if (currentResult !== context2.result || markAsError !== context2.isError) {
|
|
19757
|
+
return {
|
|
19758
|
+
modifiedResult: currentResult,
|
|
19759
|
+
markAsError
|
|
19760
|
+
};
|
|
19761
|
+
}
|
|
19762
|
+
return void 0;
|
|
19763
|
+
}
|
|
19655
19764
|
/**
|
|
19656
19765
|
* Dispose all plugins and cleanup resources
|
|
19657
19766
|
*/
|
|
@@ -19882,6 +19991,24 @@ var ToolManager = class {
|
|
|
19882
19991
|
}
|
|
19883
19992
|
return composedTools;
|
|
19884
19993
|
}
|
|
19994
|
+
/**
|
|
19995
|
+
* Get a single tool as ComposedTool object by name
|
|
19996
|
+
*/
|
|
19997
|
+
getComposedTool(name) {
|
|
19998
|
+
const tool2 = this.toolRegistry.get(name);
|
|
19999
|
+
if (!tool2) {
|
|
20000
|
+
return void 0;
|
|
20001
|
+
}
|
|
20002
|
+
return {
|
|
20003
|
+
name,
|
|
20004
|
+
description: tool2.description,
|
|
20005
|
+
inputSchema: tool2.schema ?? {
|
|
20006
|
+
type: "object",
|
|
20007
|
+
properties: {}
|
|
20008
|
+
},
|
|
20009
|
+
execute: tool2.callback
|
|
20010
|
+
};
|
|
20011
|
+
}
|
|
19885
20012
|
};
|
|
19886
20013
|
|
|
19887
20014
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
@@ -20082,9 +20209,81 @@ var ComposableMCPServer = class extends Server {
|
|
|
20082
20209
|
if (!handler) {
|
|
20083
20210
|
throw new Error(`Tool ${toolName} not found`);
|
|
20084
20211
|
}
|
|
20085
|
-
const
|
|
20086
|
-
const
|
|
20087
|
-
|
|
20212
|
+
const toolDefinition = this.toolManager.getComposedTool(toolName);
|
|
20213
|
+
const startTime = Date.now();
|
|
20214
|
+
const beforeContext = {
|
|
20215
|
+
toolName,
|
|
20216
|
+
args,
|
|
20217
|
+
server: this,
|
|
20218
|
+
toolDefinition,
|
|
20219
|
+
isInternalCall: false
|
|
20220
|
+
};
|
|
20221
|
+
const beforeResult = await this.pluginManager.triggerBeforeToolExecute(beforeContext);
|
|
20222
|
+
if (beforeResult?.skipExecution) {
|
|
20223
|
+
const executionTimeMs2 = Date.now() - startTime;
|
|
20224
|
+
const afterContext2 = {
|
|
20225
|
+
toolName,
|
|
20226
|
+
args,
|
|
20227
|
+
result: beforeResult.result,
|
|
20228
|
+
server: this,
|
|
20229
|
+
wasSkipped: true,
|
|
20230
|
+
executionTimeMs: executionTimeMs2,
|
|
20231
|
+
isError: false,
|
|
20232
|
+
metadata: beforeResult.metadata,
|
|
20233
|
+
isInternalCall: false
|
|
20234
|
+
};
|
|
20235
|
+
const afterResult2 = await this.pluginManager.triggerAfterToolExecute(afterContext2);
|
|
20236
|
+
let finalResult = afterResult2?.modifiedResult ?? beforeResult.result;
|
|
20237
|
+
if (afterResult2?.markAsError && finalResult) {
|
|
20238
|
+
finalResult = {
|
|
20239
|
+
...finalResult,
|
|
20240
|
+
isError: true
|
|
20241
|
+
};
|
|
20242
|
+
}
|
|
20243
|
+
return finalResult;
|
|
20244
|
+
}
|
|
20245
|
+
const effectiveArgs = beforeResult?.modifiedArgs ?? args;
|
|
20246
|
+
const processedArgs = await this.applyPluginTransforms(toolName, effectiveArgs, "input");
|
|
20247
|
+
let result = await handler(processedArgs, extra);
|
|
20248
|
+
const isError = !!result?.isError;
|
|
20249
|
+
result = await this.applyPluginTransforms(toolName, result, "output", args);
|
|
20250
|
+
if (isError && result && !("isError" in result)) {
|
|
20251
|
+
result = {
|
|
20252
|
+
...result,
|
|
20253
|
+
isError: true
|
|
20254
|
+
};
|
|
20255
|
+
}
|
|
20256
|
+
const executionTimeMs = Date.now() - startTime;
|
|
20257
|
+
const afterContext = {
|
|
20258
|
+
toolName,
|
|
20259
|
+
args,
|
|
20260
|
+
result,
|
|
20261
|
+
server: this,
|
|
20262
|
+
wasSkipped: false,
|
|
20263
|
+
executionTimeMs,
|
|
20264
|
+
isError,
|
|
20265
|
+
metadata: beforeResult?.metadata,
|
|
20266
|
+
isInternalCall: false
|
|
20267
|
+
};
|
|
20268
|
+
const afterResult = await this.pluginManager.triggerAfterToolExecute(afterContext);
|
|
20269
|
+
if (afterResult?.modifiedResult !== void 0) {
|
|
20270
|
+
let finalResult = afterResult.modifiedResult;
|
|
20271
|
+
const hasExplicitIsError = finalResult && "isError" in finalResult;
|
|
20272
|
+
if (!hasExplicitIsError && afterResult.markAsError && finalResult) {
|
|
20273
|
+
finalResult = {
|
|
20274
|
+
...finalResult,
|
|
20275
|
+
isError: true
|
|
20276
|
+
};
|
|
20277
|
+
}
|
|
20278
|
+
return finalResult;
|
|
20279
|
+
}
|
|
20280
|
+
if (afterResult?.markAsError && result) {
|
|
20281
|
+
return {
|
|
20282
|
+
...result,
|
|
20283
|
+
isError: true
|
|
20284
|
+
};
|
|
20285
|
+
}
|
|
20286
|
+
return result;
|
|
20088
20287
|
});
|
|
20089
20288
|
this.setRequestHandler(SetLevelRequestSchema, (request) => {
|
|
20090
20289
|
const { level } = request.params;
|
|
@@ -20106,8 +20305,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
20106
20305
|
}
|
|
20107
20306
|
/**
|
|
20108
20307
|
* Call any registered tool directly, whether it's public or internal
|
|
20308
|
+
* Supports tool execution lifecycle hooks for dynamic context handoff
|
|
20109
20309
|
*/
|
|
20110
|
-
async callTool(name, args) {
|
|
20310
|
+
async callTool(name, args, options = {}) {
|
|
20111
20311
|
const resolvedName = this.resolveToolName(name);
|
|
20112
20312
|
if (!resolvedName) {
|
|
20113
20313
|
throw new Error(`Tool ${name} not found`);
|
|
@@ -20116,9 +20316,99 @@ var ComposableMCPServer = class extends Server {
|
|
|
20116
20316
|
if (!callback) {
|
|
20117
20317
|
throw new Error(`Tool ${name} not found`);
|
|
20118
20318
|
}
|
|
20119
|
-
const
|
|
20120
|
-
const
|
|
20121
|
-
|
|
20319
|
+
const toolDefinition = this.toolManager.getComposedTool(resolvedName);
|
|
20320
|
+
const startTime = Date.now();
|
|
20321
|
+
const beforeContext = {
|
|
20322
|
+
toolName: resolvedName,
|
|
20323
|
+
args,
|
|
20324
|
+
server: this,
|
|
20325
|
+
toolDefinition,
|
|
20326
|
+
isInternalCall: true,
|
|
20327
|
+
agentName: options.agentName,
|
|
20328
|
+
executionChain: options.executionChain
|
|
20329
|
+
};
|
|
20330
|
+
const beforeResult = await this.pluginManager.triggerBeforeToolExecute(beforeContext);
|
|
20331
|
+
if (beforeResult?.skipExecution) {
|
|
20332
|
+
const executionTimeMs2 = Date.now() - startTime;
|
|
20333
|
+
const afterContext2 = {
|
|
20334
|
+
toolName: resolvedName,
|
|
20335
|
+
args,
|
|
20336
|
+
result: beforeResult.result,
|
|
20337
|
+
server: this,
|
|
20338
|
+
wasSkipped: true,
|
|
20339
|
+
executionTimeMs: executionTimeMs2,
|
|
20340
|
+
isError: false,
|
|
20341
|
+
metadata: beforeResult.metadata,
|
|
20342
|
+
isInternalCall: true,
|
|
20343
|
+
agentName: options.agentName
|
|
20344
|
+
};
|
|
20345
|
+
const afterResult2 = await this.pluginManager.triggerAfterToolExecute(afterContext2);
|
|
20346
|
+
let finalResult = afterResult2?.modifiedResult ?? beforeResult.result;
|
|
20347
|
+
if (afterResult2?.markAsError && finalResult && typeof finalResult === "object") {
|
|
20348
|
+
finalResult = {
|
|
20349
|
+
...finalResult,
|
|
20350
|
+
isError: true
|
|
20351
|
+
};
|
|
20352
|
+
}
|
|
20353
|
+
return finalResult;
|
|
20354
|
+
}
|
|
20355
|
+
const effectiveArgs = beforeResult?.modifiedArgs ?? args;
|
|
20356
|
+
const processedArgs = await this.applyPluginTransforms(resolvedName, effectiveArgs, "input");
|
|
20357
|
+
let result;
|
|
20358
|
+
let isError = false;
|
|
20359
|
+
try {
|
|
20360
|
+
result = await callback(processedArgs);
|
|
20361
|
+
} catch (error2) {
|
|
20362
|
+
isError = true;
|
|
20363
|
+
result = {
|
|
20364
|
+
content: [
|
|
20365
|
+
{
|
|
20366
|
+
type: "text",
|
|
20367
|
+
text: `Error: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
20368
|
+
}
|
|
20369
|
+
],
|
|
20370
|
+
isError: true
|
|
20371
|
+
};
|
|
20372
|
+
}
|
|
20373
|
+
result = await this.applyPluginTransforms(resolvedName, result, "output", args);
|
|
20374
|
+
if (isError && result && typeof result === "object" && !("isError" in result)) {
|
|
20375
|
+
result = {
|
|
20376
|
+
...result,
|
|
20377
|
+
isError: true
|
|
20378
|
+
};
|
|
20379
|
+
}
|
|
20380
|
+
const executionTimeMs = Date.now() - startTime;
|
|
20381
|
+
const afterContext = {
|
|
20382
|
+
toolName: resolvedName,
|
|
20383
|
+
args,
|
|
20384
|
+
result,
|
|
20385
|
+
server: this,
|
|
20386
|
+
wasSkipped: false,
|
|
20387
|
+
executionTimeMs,
|
|
20388
|
+
isError,
|
|
20389
|
+
metadata: beforeResult?.metadata,
|
|
20390
|
+
isInternalCall: true,
|
|
20391
|
+
agentName: options.agentName
|
|
20392
|
+
};
|
|
20393
|
+
const afterResult = await this.pluginManager.triggerAfterToolExecute(afterContext);
|
|
20394
|
+
if (afterResult?.modifiedResult !== void 0) {
|
|
20395
|
+
let finalResult = afterResult.modifiedResult;
|
|
20396
|
+
const hasExplicitIsError = finalResult && typeof finalResult === "object" && "isError" in finalResult;
|
|
20397
|
+
if (!hasExplicitIsError && afterResult.markAsError && finalResult && typeof finalResult === "object") {
|
|
20398
|
+
finalResult = {
|
|
20399
|
+
...finalResult,
|
|
20400
|
+
isError: true
|
|
20401
|
+
};
|
|
20402
|
+
}
|
|
20403
|
+
return finalResult;
|
|
20404
|
+
}
|
|
20405
|
+
if (afterResult?.markAsError && result && typeof result === "object") {
|
|
20406
|
+
return {
|
|
20407
|
+
...result,
|
|
20408
|
+
isError: true
|
|
20409
|
+
};
|
|
20410
|
+
}
|
|
20411
|
+
return result;
|
|
20122
20412
|
}
|
|
20123
20413
|
/**
|
|
20124
20414
|
* Get all public tool names (exposed to MCP clients)
|
package/index.mjs
CHANGED
|
@@ -18296,7 +18296,9 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
18296
18296
|
tool: tool2
|
|
18297
18297
|
});
|
|
18298
18298
|
try {
|
|
18299
|
-
const result = await this.server.callTool(tool2, toolArgs
|
|
18299
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
18300
|
+
agentName: this.name
|
|
18301
|
+
});
|
|
18300
18302
|
const callToolResult = result ?? {
|
|
18301
18303
|
content: []
|
|
18302
18304
|
};
|
|
@@ -19330,7 +19332,7 @@ function isValidPlugin(plugin) {
|
|
|
19330
19332
|
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
19331
19333
|
return false;
|
|
19332
19334
|
}
|
|
19333
|
-
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.registerAgentTool === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.dispose === "function";
|
|
19335
|
+
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.registerAgentTool === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.beforeToolExecute === "function" || typeof p2.afterToolExecute === "function" || typeof p2.dispose === "function";
|
|
19334
19336
|
if (!hasHook) return false;
|
|
19335
19337
|
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
19336
19338
|
return false;
|
|
@@ -19637,6 +19639,113 @@ var PluginManager = class {
|
|
|
19637
19639
|
}
|
|
19638
19640
|
return false;
|
|
19639
19641
|
}
|
|
19642
|
+
// === Tool Execution Lifecycle Hooks ===
|
|
19643
|
+
/**
|
|
19644
|
+
* Trigger beforeToolExecute hooks for all applicable plugins
|
|
19645
|
+
* Returns the combined result from all plugins
|
|
19646
|
+
*
|
|
19647
|
+
* Hook execution order:
|
|
19648
|
+
* 1. 'pre' enforced plugins first
|
|
19649
|
+
* 2. Normal plugins (no enforce)
|
|
19650
|
+
* 3. 'post' enforced plugins last
|
|
19651
|
+
*
|
|
19652
|
+
* If any plugin returns skipExecution=true, execution is skipped
|
|
19653
|
+
* and the result from that plugin is used.
|
|
19654
|
+
*/
|
|
19655
|
+
async triggerBeforeToolExecute(context2) {
|
|
19656
|
+
const beforePlugins = this.plugins.filter((p2) => p2.beforeToolExecute);
|
|
19657
|
+
if (beforePlugins.length === 0) {
|
|
19658
|
+
return void 0;
|
|
19659
|
+
}
|
|
19660
|
+
const sortedPlugins = sortPluginsByOrder(beforePlugins);
|
|
19661
|
+
let currentArgs = context2.args;
|
|
19662
|
+
let combinedMetadata = {};
|
|
19663
|
+
for (const plugin of sortedPlugins) {
|
|
19664
|
+
if (plugin.beforeToolExecute) {
|
|
19665
|
+
try {
|
|
19666
|
+
const result = await plugin.beforeToolExecute({
|
|
19667
|
+
...context2,
|
|
19668
|
+
args: currentArgs
|
|
19669
|
+
});
|
|
19670
|
+
if (result) {
|
|
19671
|
+
if (result.metadata) {
|
|
19672
|
+
combinedMetadata = {
|
|
19673
|
+
...combinedMetadata,
|
|
19674
|
+
...result.metadata
|
|
19675
|
+
};
|
|
19676
|
+
}
|
|
19677
|
+
if (result.skipExecution) {
|
|
19678
|
+
return {
|
|
19679
|
+
skipExecution: true,
|
|
19680
|
+
result: result.result,
|
|
19681
|
+
metadata: combinedMetadata
|
|
19682
|
+
};
|
|
19683
|
+
}
|
|
19684
|
+
if (result.modifiedArgs !== void 0) {
|
|
19685
|
+
currentArgs = result.modifiedArgs;
|
|
19686
|
+
}
|
|
19687
|
+
}
|
|
19688
|
+
} catch (error2) {
|
|
19689
|
+
const errorMsg = error2 instanceof Error ? error2.message : String(error2);
|
|
19690
|
+
await this.logger.error(`Plugin "${plugin.name}" beforeToolExecute failed for "${context2.toolName}": ${errorMsg}`);
|
|
19691
|
+
}
|
|
19692
|
+
}
|
|
19693
|
+
}
|
|
19694
|
+
if (currentArgs !== context2.args) {
|
|
19695
|
+
return {
|
|
19696
|
+
modifiedArgs: currentArgs,
|
|
19697
|
+
metadata: Object.keys(combinedMetadata).length > 0 ? combinedMetadata : void 0
|
|
19698
|
+
};
|
|
19699
|
+
}
|
|
19700
|
+
if (Object.keys(combinedMetadata).length > 0) {
|
|
19701
|
+
return {
|
|
19702
|
+
metadata: combinedMetadata
|
|
19703
|
+
};
|
|
19704
|
+
}
|
|
19705
|
+
return void 0;
|
|
19706
|
+
}
|
|
19707
|
+
/**
|
|
19708
|
+
* Trigger afterToolExecute hooks for all applicable plugins
|
|
19709
|
+
* Returns the final result after all plugins have processed it
|
|
19710
|
+
*/
|
|
19711
|
+
async triggerAfterToolExecute(context2) {
|
|
19712
|
+
const afterPlugins = this.plugins.filter((p2) => p2.afterToolExecute);
|
|
19713
|
+
if (afterPlugins.length === 0) {
|
|
19714
|
+
return void 0;
|
|
19715
|
+
}
|
|
19716
|
+
const sortedPlugins = sortPluginsByOrder(afterPlugins);
|
|
19717
|
+
let currentResult = context2.result;
|
|
19718
|
+
let markAsError = context2.isError;
|
|
19719
|
+
for (const plugin of sortedPlugins) {
|
|
19720
|
+
if (plugin.afterToolExecute) {
|
|
19721
|
+
try {
|
|
19722
|
+
const result = await plugin.afterToolExecute({
|
|
19723
|
+
...context2,
|
|
19724
|
+
result: currentResult,
|
|
19725
|
+
isError: markAsError
|
|
19726
|
+
});
|
|
19727
|
+
if (result) {
|
|
19728
|
+
if (result.modifiedResult !== void 0) {
|
|
19729
|
+
currentResult = result.modifiedResult;
|
|
19730
|
+
}
|
|
19731
|
+
if (result.markAsError !== void 0) {
|
|
19732
|
+
markAsError = result.markAsError;
|
|
19733
|
+
}
|
|
19734
|
+
}
|
|
19735
|
+
} catch (error2) {
|
|
19736
|
+
const errorMsg = error2 instanceof Error ? error2.message : String(error2);
|
|
19737
|
+
await this.logger.error(`Plugin "${plugin.name}" afterToolExecute failed for "${context2.toolName}": ${errorMsg}`);
|
|
19738
|
+
}
|
|
19739
|
+
}
|
|
19740
|
+
}
|
|
19741
|
+
if (currentResult !== context2.result || markAsError !== context2.isError) {
|
|
19742
|
+
return {
|
|
19743
|
+
modifiedResult: currentResult,
|
|
19744
|
+
markAsError
|
|
19745
|
+
};
|
|
19746
|
+
}
|
|
19747
|
+
return void 0;
|
|
19748
|
+
}
|
|
19640
19749
|
/**
|
|
19641
19750
|
* Dispose all plugins and cleanup resources
|
|
19642
19751
|
*/
|
|
@@ -19867,6 +19976,24 @@ var ToolManager = class {
|
|
|
19867
19976
|
}
|
|
19868
19977
|
return composedTools;
|
|
19869
19978
|
}
|
|
19979
|
+
/**
|
|
19980
|
+
* Get a single tool as ComposedTool object by name
|
|
19981
|
+
*/
|
|
19982
|
+
getComposedTool(name) {
|
|
19983
|
+
const tool2 = this.toolRegistry.get(name);
|
|
19984
|
+
if (!tool2) {
|
|
19985
|
+
return void 0;
|
|
19986
|
+
}
|
|
19987
|
+
return {
|
|
19988
|
+
name,
|
|
19989
|
+
description: tool2.description,
|
|
19990
|
+
inputSchema: tool2.schema ?? {
|
|
19991
|
+
type: "object",
|
|
19992
|
+
properties: {}
|
|
19993
|
+
},
|
|
19994
|
+
execute: tool2.callback
|
|
19995
|
+
};
|
|
19996
|
+
}
|
|
19870
19997
|
};
|
|
19871
19998
|
|
|
19872
19999
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
@@ -20067,9 +20194,81 @@ var ComposableMCPServer = class extends Server {
|
|
|
20067
20194
|
if (!handler) {
|
|
20068
20195
|
throw new Error(`Tool ${toolName} not found`);
|
|
20069
20196
|
}
|
|
20070
|
-
const
|
|
20071
|
-
const
|
|
20072
|
-
|
|
20197
|
+
const toolDefinition = this.toolManager.getComposedTool(toolName);
|
|
20198
|
+
const startTime = Date.now();
|
|
20199
|
+
const beforeContext = {
|
|
20200
|
+
toolName,
|
|
20201
|
+
args,
|
|
20202
|
+
server: this,
|
|
20203
|
+
toolDefinition,
|
|
20204
|
+
isInternalCall: false
|
|
20205
|
+
};
|
|
20206
|
+
const beforeResult = await this.pluginManager.triggerBeforeToolExecute(beforeContext);
|
|
20207
|
+
if (beforeResult?.skipExecution) {
|
|
20208
|
+
const executionTimeMs2 = Date.now() - startTime;
|
|
20209
|
+
const afterContext2 = {
|
|
20210
|
+
toolName,
|
|
20211
|
+
args,
|
|
20212
|
+
result: beforeResult.result,
|
|
20213
|
+
server: this,
|
|
20214
|
+
wasSkipped: true,
|
|
20215
|
+
executionTimeMs: executionTimeMs2,
|
|
20216
|
+
isError: false,
|
|
20217
|
+
metadata: beforeResult.metadata,
|
|
20218
|
+
isInternalCall: false
|
|
20219
|
+
};
|
|
20220
|
+
const afterResult2 = await this.pluginManager.triggerAfterToolExecute(afterContext2);
|
|
20221
|
+
let finalResult = afterResult2?.modifiedResult ?? beforeResult.result;
|
|
20222
|
+
if (afterResult2?.markAsError && finalResult) {
|
|
20223
|
+
finalResult = {
|
|
20224
|
+
...finalResult,
|
|
20225
|
+
isError: true
|
|
20226
|
+
};
|
|
20227
|
+
}
|
|
20228
|
+
return finalResult;
|
|
20229
|
+
}
|
|
20230
|
+
const effectiveArgs = beforeResult?.modifiedArgs ?? args;
|
|
20231
|
+
const processedArgs = await this.applyPluginTransforms(toolName, effectiveArgs, "input");
|
|
20232
|
+
let result = await handler(processedArgs, extra);
|
|
20233
|
+
const isError = !!result?.isError;
|
|
20234
|
+
result = await this.applyPluginTransforms(toolName, result, "output", args);
|
|
20235
|
+
if (isError && result && !("isError" in result)) {
|
|
20236
|
+
result = {
|
|
20237
|
+
...result,
|
|
20238
|
+
isError: true
|
|
20239
|
+
};
|
|
20240
|
+
}
|
|
20241
|
+
const executionTimeMs = Date.now() - startTime;
|
|
20242
|
+
const afterContext = {
|
|
20243
|
+
toolName,
|
|
20244
|
+
args,
|
|
20245
|
+
result,
|
|
20246
|
+
server: this,
|
|
20247
|
+
wasSkipped: false,
|
|
20248
|
+
executionTimeMs,
|
|
20249
|
+
isError,
|
|
20250
|
+
metadata: beforeResult?.metadata,
|
|
20251
|
+
isInternalCall: false
|
|
20252
|
+
};
|
|
20253
|
+
const afterResult = await this.pluginManager.triggerAfterToolExecute(afterContext);
|
|
20254
|
+
if (afterResult?.modifiedResult !== void 0) {
|
|
20255
|
+
let finalResult = afterResult.modifiedResult;
|
|
20256
|
+
const hasExplicitIsError = finalResult && "isError" in finalResult;
|
|
20257
|
+
if (!hasExplicitIsError && afterResult.markAsError && finalResult) {
|
|
20258
|
+
finalResult = {
|
|
20259
|
+
...finalResult,
|
|
20260
|
+
isError: true
|
|
20261
|
+
};
|
|
20262
|
+
}
|
|
20263
|
+
return finalResult;
|
|
20264
|
+
}
|
|
20265
|
+
if (afterResult?.markAsError && result) {
|
|
20266
|
+
return {
|
|
20267
|
+
...result,
|
|
20268
|
+
isError: true
|
|
20269
|
+
};
|
|
20270
|
+
}
|
|
20271
|
+
return result;
|
|
20073
20272
|
});
|
|
20074
20273
|
this.setRequestHandler(SetLevelRequestSchema, (request) => {
|
|
20075
20274
|
const { level } = request.params;
|
|
@@ -20091,8 +20290,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
20091
20290
|
}
|
|
20092
20291
|
/**
|
|
20093
20292
|
* Call any registered tool directly, whether it's public or internal
|
|
20293
|
+
* Supports tool execution lifecycle hooks for dynamic context handoff
|
|
20094
20294
|
*/
|
|
20095
|
-
async callTool(name, args) {
|
|
20295
|
+
async callTool(name, args, options = {}) {
|
|
20096
20296
|
const resolvedName = this.resolveToolName(name);
|
|
20097
20297
|
if (!resolvedName) {
|
|
20098
20298
|
throw new Error(`Tool ${name} not found`);
|
|
@@ -20101,9 +20301,99 @@ var ComposableMCPServer = class extends Server {
|
|
|
20101
20301
|
if (!callback) {
|
|
20102
20302
|
throw new Error(`Tool ${name} not found`);
|
|
20103
20303
|
}
|
|
20104
|
-
const
|
|
20105
|
-
const
|
|
20106
|
-
|
|
20304
|
+
const toolDefinition = this.toolManager.getComposedTool(resolvedName);
|
|
20305
|
+
const startTime = Date.now();
|
|
20306
|
+
const beforeContext = {
|
|
20307
|
+
toolName: resolvedName,
|
|
20308
|
+
args,
|
|
20309
|
+
server: this,
|
|
20310
|
+
toolDefinition,
|
|
20311
|
+
isInternalCall: true,
|
|
20312
|
+
agentName: options.agentName,
|
|
20313
|
+
executionChain: options.executionChain
|
|
20314
|
+
};
|
|
20315
|
+
const beforeResult = await this.pluginManager.triggerBeforeToolExecute(beforeContext);
|
|
20316
|
+
if (beforeResult?.skipExecution) {
|
|
20317
|
+
const executionTimeMs2 = Date.now() - startTime;
|
|
20318
|
+
const afterContext2 = {
|
|
20319
|
+
toolName: resolvedName,
|
|
20320
|
+
args,
|
|
20321
|
+
result: beforeResult.result,
|
|
20322
|
+
server: this,
|
|
20323
|
+
wasSkipped: true,
|
|
20324
|
+
executionTimeMs: executionTimeMs2,
|
|
20325
|
+
isError: false,
|
|
20326
|
+
metadata: beforeResult.metadata,
|
|
20327
|
+
isInternalCall: true,
|
|
20328
|
+
agentName: options.agentName
|
|
20329
|
+
};
|
|
20330
|
+
const afterResult2 = await this.pluginManager.triggerAfterToolExecute(afterContext2);
|
|
20331
|
+
let finalResult = afterResult2?.modifiedResult ?? beforeResult.result;
|
|
20332
|
+
if (afterResult2?.markAsError && finalResult && typeof finalResult === "object") {
|
|
20333
|
+
finalResult = {
|
|
20334
|
+
...finalResult,
|
|
20335
|
+
isError: true
|
|
20336
|
+
};
|
|
20337
|
+
}
|
|
20338
|
+
return finalResult;
|
|
20339
|
+
}
|
|
20340
|
+
const effectiveArgs = beforeResult?.modifiedArgs ?? args;
|
|
20341
|
+
const processedArgs = await this.applyPluginTransforms(resolvedName, effectiveArgs, "input");
|
|
20342
|
+
let result;
|
|
20343
|
+
let isError = false;
|
|
20344
|
+
try {
|
|
20345
|
+
result = await callback(processedArgs);
|
|
20346
|
+
} catch (error2) {
|
|
20347
|
+
isError = true;
|
|
20348
|
+
result = {
|
|
20349
|
+
content: [
|
|
20350
|
+
{
|
|
20351
|
+
type: "text",
|
|
20352
|
+
text: `Error: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
20353
|
+
}
|
|
20354
|
+
],
|
|
20355
|
+
isError: true
|
|
20356
|
+
};
|
|
20357
|
+
}
|
|
20358
|
+
result = await this.applyPluginTransforms(resolvedName, result, "output", args);
|
|
20359
|
+
if (isError && result && typeof result === "object" && !("isError" in result)) {
|
|
20360
|
+
result = {
|
|
20361
|
+
...result,
|
|
20362
|
+
isError: true
|
|
20363
|
+
};
|
|
20364
|
+
}
|
|
20365
|
+
const executionTimeMs = Date.now() - startTime;
|
|
20366
|
+
const afterContext = {
|
|
20367
|
+
toolName: resolvedName,
|
|
20368
|
+
args,
|
|
20369
|
+
result,
|
|
20370
|
+
server: this,
|
|
20371
|
+
wasSkipped: false,
|
|
20372
|
+
executionTimeMs,
|
|
20373
|
+
isError,
|
|
20374
|
+
metadata: beforeResult?.metadata,
|
|
20375
|
+
isInternalCall: true,
|
|
20376
|
+
agentName: options.agentName
|
|
20377
|
+
};
|
|
20378
|
+
const afterResult = await this.pluginManager.triggerAfterToolExecute(afterContext);
|
|
20379
|
+
if (afterResult?.modifiedResult !== void 0) {
|
|
20380
|
+
let finalResult = afterResult.modifiedResult;
|
|
20381
|
+
const hasExplicitIsError = finalResult && typeof finalResult === "object" && "isError" in finalResult;
|
|
20382
|
+
if (!hasExplicitIsError && afterResult.markAsError && finalResult && typeof finalResult === "object") {
|
|
20383
|
+
finalResult = {
|
|
20384
|
+
...finalResult,
|
|
20385
|
+
isError: true
|
|
20386
|
+
};
|
|
20387
|
+
}
|
|
20388
|
+
return finalResult;
|
|
20389
|
+
}
|
|
20390
|
+
if (afterResult?.markAsError && result && typeof result === "object") {
|
|
20391
|
+
return {
|
|
20392
|
+
...result,
|
|
20393
|
+
isError: true
|
|
20394
|
+
};
|
|
20395
|
+
}
|
|
20396
|
+
return result;
|
|
20107
20397
|
}
|
|
20108
20398
|
/**
|
|
20109
20399
|
* Get all public tool names (exposed to MCP clients)
|
package/package.json
CHANGED
package/types/mod.d.ts
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
*/ export * from "./src/compose.js";
|
|
50
50
|
export type { McpServerConfig, MCPSetting, SseServerConfig, StdioServerConfig, StreamableHTTPServerConfig } from "./src/service/tools.js";
|
|
51
51
|
export type { SamplingConfig, ToolRefXml } from "./src/types.js";
|
|
52
|
-
export type { AgentToolRegistrationContext, ComposedTool, ComposeEndContext, ComposeStartContext, FinalizeContext, ToolConfig, ToolPlugin, TransformContext } from "./src/plugin-types.js";
|
|
52
|
+
export type { AfterToolExecuteContext, AfterToolExecuteResult, AgentToolRegistrationContext, BeforeToolExecuteContext, BeforeToolExecuteResult, ComposedTool, ComposeEndContext, ComposeStartContext, FinalizeContext, RuntimeTransformContext, ToolConfig, ToolPlugin, TransformContext } from "./src/plugin-types.js";
|
|
53
53
|
export * from "./src/utils/common/env.js";
|
|
54
54
|
export * from "./src/utils/common/json.js";
|
|
55
55
|
export * from "./src/utils/common/mcp.js";
|
package/types/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDC,GAED,iCAAiC;AAGjC,cACE,eAAe,EACf,UAAU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ACf,UAAU,EACV,KAAK,MAAM,gCACkB;AAG/B,SACE,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,kCACgB"}
|
package/types/src/compose.d.ts
CHANGED
|
@@ -29,7 +29,11 @@ export declare class ComposableMCPServer extends Server {
|
|
|
29
29
|
*/ findToolConfig(toolId: string): ToolConfig | undefined;
|
|
30
30
|
/**
|
|
31
31
|
* Call any registered tool directly, whether it's public or internal
|
|
32
|
-
|
|
32
|
+
* Supports tool execution lifecycle hooks for dynamic context handoff
|
|
33
|
+
*/ callTool(name: string, args: unknown, options?: {
|
|
34
|
+
agentName?: string;
|
|
35
|
+
executionChain?: string[];
|
|
36
|
+
}): Promise<unknown>;
|
|
33
37
|
/**
|
|
34
38
|
* Get all public tool names (exposed to MCP clients)
|
|
35
39
|
*/ getPublicToolNames(): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sources":["../../src/compose.ts"],"names":[],"mappings":"AAAA,SAGE,KAAK,cAAc,EAGnB,KAAK,IAAI,6CAC8C;AACzD,SAAwC,KAAK,MAAM,4BAA4B;AAC/E,cAAc,UAAU,6BAA6B;AACrD,SACE,MAAM,EACN,KAAK,aAAa,oDAC4C;AAGhE,cAAc,iBAAiB,kCAAkC;AACjE,cAAc,UAAU,EAAE,YAAY,qBAAqB;AAM3D,cAA4B,UAAU,EAAE,UAAU,4BAA4B;AAe9E,OAAO,cAAM,4BAA4B;EACvC,QAAQ,mBAA6B;EACrC,QAAQ,iBAAyB;EACjC,QAAQ,YAAsC;EAG9C,IAAI,mBAAmB,IAAI,MAAM,EAAE,MAAM;EAIzC,YAAY,aAAa,cAAc,EAAE,SAAS,aAAa;EAiB/D;;GAEC,GACD,AAAM,sBAAsB,QAAQ,IAAI;UAqB1B;UAsDN;EAIR,KAAK,GACH,MAAM,MAAM,EACZ,aAAa,MAAM,EACnB,cAAc,OAAO,KAAK,UAAU,EACpC,KAAK,MAAM,GAAG,QAAQ,OAAO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,oBACE,MAAM,MAAM;IACT,aAAa,MAAM;IAAE,QAAQ;MAAe,SAAS;EAI1D;;GAEC,GACD,aAAa,MAAM,MAAM,GAAG,OAAO;EAInC;;GAEC,GACD,WAAW,UAAU,MAAM,EAAE,QAAQ,UAAU,GAAG,IAAI;EAItD;;GAEC,GACD,cAAc,UAAU,MAAM,GAAG,aAAa,SAAS;EAIvD;;GAEC,GACD,iBAAiB,UAAU,MAAM,GAAG,OAAO;EAI3C;;GAEC,GACD,AAAM,UAAU,QAAQ,UAAU,GAAG,QAAQ,IAAI;EAIjD;;GAEC,GACD,AAAM,mBACJ,YAAY,MAAM,EAClB;IAAW,QAAQ,OAAO;GAAoB,GAC7C,QAAQ,IAAI;UAOD;EAOd;;GAEC,GACD,AAAM,kBAAkB,QAAQ,IAAI;EAIpC;;GAEC,GACD,SAAe,SAAS,QAAQ,IAAI;EAK9B,QACJ,MAAM,MAAM,GAAG,IAAI,EACnB,aAAa,MAAM,EACnB,aAAY,UAA+B,EAC3C,UAAS,kBAAkB,UAAgC;AAiR/D"}
|
|
@@ -26,6 +26,19 @@ export interface ToolPlugin {
|
|
|
26
26
|
/** Called after composition is complete - for logging and cleanup */ composeEnd?: (result: ComposeEndContext) => void | Promise<void>;
|
|
27
27
|
/** Called before tool execution - transform input arguments */ transformInput?: (args: unknown, context: RuntimeTransformContext) => unknown | Promise<unknown>;
|
|
28
28
|
/** Called after tool execution - transform output result */ transformOutput?: (result: unknown, context: RuntimeTransformContext) => unknown | Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Called before a tool is executed
|
|
31
|
+
* Use this to intercept tool calls, modify arguments, or skip execution entirely.
|
|
32
|
+
* This enables dynamic tool context handoff to AI agents.
|
|
33
|
+
*
|
|
34
|
+
* @returns BeforeToolExecuteResult to modify behavior, or void/undefined to continue normally
|
|
35
|
+
*/ beforeToolExecute?: (context: BeforeToolExecuteContext) => BeforeToolExecuteResult | void | Promise<BeforeToolExecuteResult | void>;
|
|
36
|
+
/**
|
|
37
|
+
* Called after a tool is executed (or skipped)
|
|
38
|
+
* Use this to modify results, log execution, or trigger follow-up actions.
|
|
39
|
+
*
|
|
40
|
+
* @returns AfterToolExecuteResult to modify the result, or void/undefined to keep original
|
|
41
|
+
*/ afterToolExecute?: (context: AfterToolExecuteContext) => AfterToolExecuteResult | void | Promise<AfterToolExecuteResult | void>;
|
|
29
42
|
/** Called when plugin is removed or server is disposed - for cleanup */ dispose?: () => void | Promise<void>;
|
|
30
43
|
}
|
|
31
44
|
/** Context for composeStart hook */ export interface ComposeStartContext {
|
|
@@ -90,6 +103,57 @@ export interface ToolPlugin {
|
|
|
90
103
|
/** Original input arguments (available in transformOutput) */ originalArgs?: unknown;
|
|
91
104
|
/** Transformation direction */ direction: "input" | "output";
|
|
92
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Result of beforeToolExecute hook
|
|
108
|
+
* Allows plugins to modify execution or skip it entirely
|
|
109
|
+
*/ export interface BeforeToolExecuteResult {
|
|
110
|
+
/**
|
|
111
|
+
* If true, skip the actual tool execution and use the provided result
|
|
112
|
+
* This enables dynamic handoff to AI agents
|
|
113
|
+
*/ skipExecution?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Modified arguments to pass to the tool (if not skipping)
|
|
116
|
+
*/ modifiedArgs?: unknown;
|
|
117
|
+
/**
|
|
118
|
+
* Result to return if skipping execution
|
|
119
|
+
* Required when skipExecution is true
|
|
120
|
+
*/ result?: unknown;
|
|
121
|
+
/**
|
|
122
|
+
* Optional metadata to pass to afterToolExecute
|
|
123
|
+
*/ metadata?: Record<string, unknown>;
|
|
124
|
+
}
|
|
125
|
+
/** Context for beforeToolExecute hook */ export interface BeforeToolExecuteContext {
|
|
126
|
+
/** Name of the tool being executed */ toolName: string;
|
|
127
|
+
/** Arguments passed to the tool */ args: unknown;
|
|
128
|
+
/** The MCP server instance */ server: ComposableMCPServer;
|
|
129
|
+
/** Tool definition (if available) */ toolDefinition?: ComposedTool;
|
|
130
|
+
/** Whether this is an internal tool call (within agent) vs external (from MCP client) */ isInternalCall: boolean;
|
|
131
|
+
/** Parent agent name (if called from within an agent) */ agentName?: string;
|
|
132
|
+
/** Execution context chain (for nested agent calls) */ executionChain?: string[];
|
|
133
|
+
}
|
|
134
|
+
/** Context for afterToolExecute hook */ export interface AfterToolExecuteContext {
|
|
135
|
+
/** Name of the tool that was executed */ toolName: string;
|
|
136
|
+
/** Original arguments passed to the tool */ args: unknown;
|
|
137
|
+
/** Result from tool execution */ result: unknown;
|
|
138
|
+
/** The MCP server instance */ server: ComposableMCPServer;
|
|
139
|
+
/** Whether execution was skipped by beforeToolExecute */ wasSkipped: boolean;
|
|
140
|
+
/** Time taken for execution in milliseconds */ executionTimeMs: number;
|
|
141
|
+
/** Whether the result indicates an error */ isError: boolean;
|
|
142
|
+
/** Metadata from beforeToolExecute */ metadata?: Record<string, unknown>;
|
|
143
|
+
/** Whether this is an internal tool call */ isInternalCall: boolean;
|
|
144
|
+
/** Parent agent name (if called from within an agent) */ agentName?: string;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Result of afterToolExecute hook
|
|
148
|
+
* Allows plugins to modify the final result
|
|
149
|
+
*/ export interface AfterToolExecuteResult {
|
|
150
|
+
/**
|
|
151
|
+
* Modified result to return
|
|
152
|
+
*/ modifiedResult?: unknown;
|
|
153
|
+
/**
|
|
154
|
+
* If true, mark the result as an error
|
|
155
|
+
*/ markAsError?: boolean;
|
|
156
|
+
}
|
|
93
157
|
export interface ToolConfig {
|
|
94
158
|
/** Override the tool's description */ description?: string;
|
|
95
159
|
/** Tool visibility settings - simplified to two independent flags */ visibility?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-types.d.ts","sources":["../../src/plugin-types.ts"],"names":[],"mappings":"AAAA;;;CAGC,GAED,cAAc,IAAI,6CAA0D;AAC5E,cAAc,YAAY,qBAAqB;AAC/C,cAAc,mBAAmB,uBAAuB;AACxD,cAAc,aAAa,6BAA6B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