@mcpc-tech/core 0.3.23 → 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 +342 -14
- package/index.mjs +340 -14
- package/package.json +1 -1
- package/types/mod.d.ts +4 -2
- 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/types/src/set-up-mcp-compose.d.ts +59 -9
- package/types/src/set-up-mcp-compose.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -534,6 +534,7 @@ __export(mod_exports, {
|
|
|
534
534
|
composeMcpDepTools: () => composeMcpDepTools,
|
|
535
535
|
convertToAISDKTools: () => convertToAISDKTools,
|
|
536
536
|
extractJsonSchema: () => extractJsonSchema,
|
|
537
|
+
isMarkdownFile: () => isMarkdownFile,
|
|
537
538
|
isProdEnv: () => isProdEnv,
|
|
538
539
|
isSCF: () => isSCF,
|
|
539
540
|
isWrappedSchema: () => isWrappedSchema,
|
|
@@ -542,6 +543,7 @@ __export(mod_exports, {
|
|
|
542
543
|
optionalObject: () => optionalObject,
|
|
543
544
|
parseJSON: () => parseJSON,
|
|
544
545
|
parseMcpcConfigs: () => parseMcpcConfigs,
|
|
546
|
+
setMarkdownAgentLoader: () => setMarkdownAgentLoader,
|
|
545
547
|
truncateJSON: () => truncateJSON
|
|
546
548
|
});
|
|
547
549
|
module.exports = __toCommonJS(mod_exports);
|
|
@@ -14868,7 +14870,9 @@ var Client = class extends Protocol {
|
|
|
14868
14870
|
}
|
|
14869
14871
|
return taskValidationResult.data;
|
|
14870
14872
|
}
|
|
14871
|
-
const
|
|
14873
|
+
const hasTools = params.tools || params.toolChoice;
|
|
14874
|
+
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
|
14875
|
+
const validationResult = safeParse3(resultSchema, result);
|
|
14872
14876
|
if (!validationResult.success) {
|
|
14873
14877
|
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
14874
14878
|
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
@@ -18306,7 +18310,9 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
18306
18310
|
tool: tool2
|
|
18307
18311
|
});
|
|
18308
18312
|
try {
|
|
18309
|
-
const result = await this.server.callTool(tool2, toolArgs
|
|
18313
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
18314
|
+
agentName: this.name
|
|
18315
|
+
});
|
|
18310
18316
|
const callToolResult = result ?? {
|
|
18311
18317
|
content: []
|
|
18312
18318
|
};
|
|
@@ -19341,7 +19347,7 @@ function isValidPlugin(plugin) {
|
|
|
19341
19347
|
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
19342
19348
|
return false;
|
|
19343
19349
|
}
|
|
19344
|
-
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";
|
|
19345
19351
|
if (!hasHook) return false;
|
|
19346
19352
|
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
19347
19353
|
return false;
|
|
@@ -19648,6 +19654,113 @@ var PluginManager = class {
|
|
|
19648
19654
|
}
|
|
19649
19655
|
return false;
|
|
19650
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
|
+
}
|
|
19651
19764
|
/**
|
|
19652
19765
|
* Dispose all plugins and cleanup resources
|
|
19653
19766
|
*/
|
|
@@ -19878,6 +19991,24 @@ var ToolManager = class {
|
|
|
19878
19991
|
}
|
|
19879
19992
|
return composedTools;
|
|
19880
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
|
+
}
|
|
19881
20012
|
};
|
|
19882
20013
|
|
|
19883
20014
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
@@ -20078,9 +20209,81 @@ var ComposableMCPServer = class extends Server {
|
|
|
20078
20209
|
if (!handler) {
|
|
20079
20210
|
throw new Error(`Tool ${toolName} not found`);
|
|
20080
20211
|
}
|
|
20081
|
-
const
|
|
20082
|
-
const
|
|
20083
|
-
|
|
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;
|
|
20084
20287
|
});
|
|
20085
20288
|
this.setRequestHandler(SetLevelRequestSchema, (request) => {
|
|
20086
20289
|
const { level } = request.params;
|
|
@@ -20102,8 +20305,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
20102
20305
|
}
|
|
20103
20306
|
/**
|
|
20104
20307
|
* Call any registered tool directly, whether it's public or internal
|
|
20308
|
+
* Supports tool execution lifecycle hooks for dynamic context handoff
|
|
20105
20309
|
*/
|
|
20106
|
-
async callTool(name, args) {
|
|
20310
|
+
async callTool(name, args, options = {}) {
|
|
20107
20311
|
const resolvedName = this.resolveToolName(name);
|
|
20108
20312
|
if (!resolvedName) {
|
|
20109
20313
|
throw new Error(`Tool ${name} not found`);
|
|
@@ -20112,9 +20316,99 @@ var ComposableMCPServer = class extends Server {
|
|
|
20112
20316
|
if (!callback) {
|
|
20113
20317
|
throw new Error(`Tool ${name} not found`);
|
|
20114
20318
|
}
|
|
20115
|
-
const
|
|
20116
|
-
const
|
|
20117
|
-
|
|
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;
|
|
20118
20412
|
}
|
|
20119
20413
|
/**
|
|
20120
20414
|
* Get all public tool names (exposed to MCP clients)
|
|
@@ -20406,12 +20700,44 @@ function convertToAISDKTools(server, helpers) {
|
|
|
20406
20700
|
}
|
|
20407
20701
|
|
|
20408
20702
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/set-up-mcp-compose.js
|
|
20703
|
+
var markdownAgentLoader = null;
|
|
20704
|
+
function setMarkdownAgentLoader(loader) {
|
|
20705
|
+
markdownAgentLoader = loader;
|
|
20706
|
+
}
|
|
20707
|
+
function isMarkdownFile(path) {
|
|
20708
|
+
return path.endsWith(".md") || path.endsWith(".markdown");
|
|
20709
|
+
}
|
|
20710
|
+
async function resolveComposeInput(input) {
|
|
20711
|
+
if (typeof input !== "string") {
|
|
20712
|
+
return input;
|
|
20713
|
+
}
|
|
20714
|
+
if (!isMarkdownFile(input)) {
|
|
20715
|
+
throw new Error(`Invalid compose input: "${input}". Expected a Markdown file path (.md) or a ComposeDefinition object.`);
|
|
20716
|
+
}
|
|
20717
|
+
if (!markdownAgentLoader) {
|
|
20718
|
+
throw new Error(`Cannot load Markdown agent file "${input}": Markdown loader not available. Use markdownLoaderPlugin() from "@mcpc/plugin-markdown-loader", or use inline ComposeDefinition objects.`);
|
|
20719
|
+
}
|
|
20720
|
+
return await markdownAgentLoader(input);
|
|
20721
|
+
}
|
|
20409
20722
|
function parseMcpcConfigs(conf) {
|
|
20410
20723
|
return conf ?? [];
|
|
20411
20724
|
}
|
|
20412
|
-
async function mcpc(serverConf, composeConf,
|
|
20725
|
+
async function mcpc(serverConf, composeConf, optionsOrSetup) {
|
|
20413
20726
|
const server = new ComposableMCPServer(...serverConf);
|
|
20414
|
-
const
|
|
20727
|
+
const options = typeof optionsOrSetup === "function" ? {
|
|
20728
|
+
setup: optionsOrSetup
|
|
20729
|
+
} : optionsOrSetup ?? {};
|
|
20730
|
+
if (options.plugins) {
|
|
20731
|
+
for (const plugin of options.plugins) {
|
|
20732
|
+
if (typeof plugin === "string") {
|
|
20733
|
+
await server.loadPluginFromPath(plugin);
|
|
20734
|
+
} else {
|
|
20735
|
+
await server.addPlugin(plugin);
|
|
20736
|
+
}
|
|
20737
|
+
}
|
|
20738
|
+
}
|
|
20739
|
+
const resolvedConfigs = composeConf ? await Promise.all(composeConf.map(resolveComposeInput)) : [];
|
|
20740
|
+
const parsed = parseMcpcConfigs(resolvedConfigs);
|
|
20415
20741
|
await server.initBuiltInPlugins();
|
|
20416
20742
|
for (const mcpcConfig of parsed) {
|
|
20417
20743
|
if (mcpcConfig.plugins) {
|
|
@@ -20424,8 +20750,8 @@ async function mcpc(serverConf, composeConf, setupCallback) {
|
|
|
20424
20750
|
}
|
|
20425
20751
|
}
|
|
20426
20752
|
}
|
|
20427
|
-
if (
|
|
20428
|
-
await
|
|
20753
|
+
if (options.setup) {
|
|
20754
|
+
await options.setup(server);
|
|
20429
20755
|
}
|
|
20430
20756
|
for (const mcpcConfig of parsed) {
|
|
20431
20757
|
await server.compose(mcpcConfig.name, mcpcConfig.description ?? "", mcpcConfig.deps, mcpcConfig.options);
|
|
@@ -20438,6 +20764,7 @@ async function mcpc(serverConf, composeConf, setupCallback) {
|
|
|
20438
20764
|
composeMcpDepTools,
|
|
20439
20765
|
convertToAISDKTools,
|
|
20440
20766
|
extractJsonSchema,
|
|
20767
|
+
isMarkdownFile,
|
|
20441
20768
|
isProdEnv,
|
|
20442
20769
|
isSCF,
|
|
20443
20770
|
isWrappedSchema,
|
|
@@ -20446,5 +20773,6 @@ async function mcpc(serverConf, composeConf, setupCallback) {
|
|
|
20446
20773
|
optionalObject,
|
|
20447
20774
|
parseJSON,
|
|
20448
20775
|
parseMcpcConfigs,
|
|
20776
|
+
setMarkdownAgentLoader,
|
|
20449
20777
|
truncateJSON
|
|
20450
20778
|
});
|
package/index.mjs
CHANGED
|
@@ -14856,7 +14856,9 @@ var Client = class extends Protocol {
|
|
|
14856
14856
|
}
|
|
14857
14857
|
return taskValidationResult.data;
|
|
14858
14858
|
}
|
|
14859
|
-
const
|
|
14859
|
+
const hasTools = params.tools || params.toolChoice;
|
|
14860
|
+
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
|
14861
|
+
const validationResult = safeParse3(resultSchema, result);
|
|
14860
14862
|
if (!validationResult.success) {
|
|
14861
14863
|
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
14862
14864
|
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
@@ -18294,7 +18296,9 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
18294
18296
|
tool: tool2
|
|
18295
18297
|
});
|
|
18296
18298
|
try {
|
|
18297
|
-
const result = await this.server.callTool(tool2, toolArgs
|
|
18299
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
18300
|
+
agentName: this.name
|
|
18301
|
+
});
|
|
18298
18302
|
const callToolResult = result ?? {
|
|
18299
18303
|
content: []
|
|
18300
18304
|
};
|
|
@@ -19328,7 +19332,7 @@ function isValidPlugin(plugin) {
|
|
|
19328
19332
|
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
19329
19333
|
return false;
|
|
19330
19334
|
}
|
|
19331
|
-
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";
|
|
19332
19336
|
if (!hasHook) return false;
|
|
19333
19337
|
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
19334
19338
|
return false;
|
|
@@ -19635,6 +19639,113 @@ var PluginManager = class {
|
|
|
19635
19639
|
}
|
|
19636
19640
|
return false;
|
|
19637
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
|
+
}
|
|
19638
19749
|
/**
|
|
19639
19750
|
* Dispose all plugins and cleanup resources
|
|
19640
19751
|
*/
|
|
@@ -19865,6 +19976,24 @@ var ToolManager = class {
|
|
|
19865
19976
|
}
|
|
19866
19977
|
return composedTools;
|
|
19867
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
|
+
}
|
|
19868
19997
|
};
|
|
19869
19998
|
|
|
19870
19999
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
@@ -20065,9 +20194,81 @@ var ComposableMCPServer = class extends Server {
|
|
|
20065
20194
|
if (!handler) {
|
|
20066
20195
|
throw new Error(`Tool ${toolName} not found`);
|
|
20067
20196
|
}
|
|
20068
|
-
const
|
|
20069
|
-
const
|
|
20070
|
-
|
|
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;
|
|
20071
20272
|
});
|
|
20072
20273
|
this.setRequestHandler(SetLevelRequestSchema, (request) => {
|
|
20073
20274
|
const { level } = request.params;
|
|
@@ -20089,8 +20290,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
20089
20290
|
}
|
|
20090
20291
|
/**
|
|
20091
20292
|
* Call any registered tool directly, whether it's public or internal
|
|
20293
|
+
* Supports tool execution lifecycle hooks for dynamic context handoff
|
|
20092
20294
|
*/
|
|
20093
|
-
async callTool(name, args) {
|
|
20295
|
+
async callTool(name, args, options = {}) {
|
|
20094
20296
|
const resolvedName = this.resolveToolName(name);
|
|
20095
20297
|
if (!resolvedName) {
|
|
20096
20298
|
throw new Error(`Tool ${name} not found`);
|
|
@@ -20099,9 +20301,99 @@ var ComposableMCPServer = class extends Server {
|
|
|
20099
20301
|
if (!callback) {
|
|
20100
20302
|
throw new Error(`Tool ${name} not found`);
|
|
20101
20303
|
}
|
|
20102
|
-
const
|
|
20103
|
-
const
|
|
20104
|
-
|
|
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;
|
|
20105
20397
|
}
|
|
20106
20398
|
/**
|
|
20107
20399
|
* Get all public tool names (exposed to MCP clients)
|
|
@@ -20393,12 +20685,44 @@ function convertToAISDKTools(server, helpers) {
|
|
|
20393
20685
|
}
|
|
20394
20686
|
|
|
20395
20687
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/set-up-mcp-compose.js
|
|
20688
|
+
var markdownAgentLoader = null;
|
|
20689
|
+
function setMarkdownAgentLoader(loader) {
|
|
20690
|
+
markdownAgentLoader = loader;
|
|
20691
|
+
}
|
|
20692
|
+
function isMarkdownFile(path) {
|
|
20693
|
+
return path.endsWith(".md") || path.endsWith(".markdown");
|
|
20694
|
+
}
|
|
20695
|
+
async function resolveComposeInput(input) {
|
|
20696
|
+
if (typeof input !== "string") {
|
|
20697
|
+
return input;
|
|
20698
|
+
}
|
|
20699
|
+
if (!isMarkdownFile(input)) {
|
|
20700
|
+
throw new Error(`Invalid compose input: "${input}". Expected a Markdown file path (.md) or a ComposeDefinition object.`);
|
|
20701
|
+
}
|
|
20702
|
+
if (!markdownAgentLoader) {
|
|
20703
|
+
throw new Error(`Cannot load Markdown agent file "${input}": Markdown loader not available. Use markdownLoaderPlugin() from "@mcpc/plugin-markdown-loader", or use inline ComposeDefinition objects.`);
|
|
20704
|
+
}
|
|
20705
|
+
return await markdownAgentLoader(input);
|
|
20706
|
+
}
|
|
20396
20707
|
function parseMcpcConfigs(conf) {
|
|
20397
20708
|
return conf ?? [];
|
|
20398
20709
|
}
|
|
20399
|
-
async function mcpc(serverConf, composeConf,
|
|
20710
|
+
async function mcpc(serverConf, composeConf, optionsOrSetup) {
|
|
20400
20711
|
const server = new ComposableMCPServer(...serverConf);
|
|
20401
|
-
const
|
|
20712
|
+
const options = typeof optionsOrSetup === "function" ? {
|
|
20713
|
+
setup: optionsOrSetup
|
|
20714
|
+
} : optionsOrSetup ?? {};
|
|
20715
|
+
if (options.plugins) {
|
|
20716
|
+
for (const plugin of options.plugins) {
|
|
20717
|
+
if (typeof plugin === "string") {
|
|
20718
|
+
await server.loadPluginFromPath(plugin);
|
|
20719
|
+
} else {
|
|
20720
|
+
await server.addPlugin(plugin);
|
|
20721
|
+
}
|
|
20722
|
+
}
|
|
20723
|
+
}
|
|
20724
|
+
const resolvedConfigs = composeConf ? await Promise.all(composeConf.map(resolveComposeInput)) : [];
|
|
20725
|
+
const parsed = parseMcpcConfigs(resolvedConfigs);
|
|
20402
20726
|
await server.initBuiltInPlugins();
|
|
20403
20727
|
for (const mcpcConfig of parsed) {
|
|
20404
20728
|
if (mcpcConfig.plugins) {
|
|
@@ -20411,8 +20735,8 @@ async function mcpc(serverConf, composeConf, setupCallback) {
|
|
|
20411
20735
|
}
|
|
20412
20736
|
}
|
|
20413
20737
|
}
|
|
20414
|
-
if (
|
|
20415
|
-
await
|
|
20738
|
+
if (options.setup) {
|
|
20739
|
+
await options.setup(server);
|
|
20416
20740
|
}
|
|
20417
20741
|
for (const mcpcConfig of parsed) {
|
|
20418
20742
|
await server.compose(mcpcConfig.name, mcpcConfig.description ?? "", mcpcConfig.deps, mcpcConfig.options);
|
|
@@ -20424,6 +20748,7 @@ export {
|
|
|
20424
20748
|
composeMcpDepTools,
|
|
20425
20749
|
convertToAISDKTools,
|
|
20426
20750
|
extractJsonSchema,
|
|
20751
|
+
isMarkdownFile,
|
|
20427
20752
|
isProdEnv,
|
|
20428
20753
|
isSCF,
|
|
20429
20754
|
isWrappedSchema,
|
|
@@ -20432,5 +20757,6 @@ export {
|
|
|
20432
20757
|
optionalObject,
|
|
20433
20758
|
parseJSON,
|
|
20434
20759
|
parseMcpcConfigs,
|
|
20760
|
+
setMarkdownAgentLoader,
|
|
20435
20761
|
truncateJSON
|
|
20436
20762
|
};
|
package/package.json
CHANGED
package/types/mod.d.ts
CHANGED
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
*
|
|
48
48
|
* @module
|
|
49
49
|
*/ export * from "./src/compose.js";
|
|
50
|
-
export type {
|
|
50
|
+
export type { McpServerConfig, MCPSetting, SseServerConfig, StdioServerConfig, StreamableHTTPServerConfig } from "./src/service/tools.js";
|
|
51
|
+
export type { SamplingConfig, ToolRefXml } from "./src/types.js";
|
|
52
|
+
export type { AfterToolExecuteContext, AfterToolExecuteResult, AgentToolRegistrationContext, BeforeToolExecuteContext, BeforeToolExecuteResult, ComposedTool, ComposeEndContext, ComposeStartContext, FinalizeContext, RuntimeTransformContext, ToolConfig, ToolPlugin, TransformContext } from "./src/plugin-types.js";
|
|
51
53
|
export * from "./src/utils/common/env.js";
|
|
52
54
|
export * from "./src/utils/common/json.js";
|
|
53
55
|
export * from "./src/utils/common/mcp.js";
|
|
54
|
-
export
|
|
56
|
+
export { type ComposeDefinition, type ComposeInput, type ComposibleMCPConfig, isMarkdownFile, type MarkdownAgentLoader, mcpc, type McpcOptions, parseMcpcConfigs, setMarkdownAgentLoader } from "./src/set-up-mcp-compose.js";
|
|
55
57
|
export { extractJsonSchema, isWrappedSchema, jsonSchema, type Schema } from "./src/utils/schema.js";
|
|
56
58
|
export { convertToAISDKTools, type JsonSchemaHelper, type ToolHelper } from "./src/ai-sdk-adapter.js";
|
|
57
59
|
//# sourceMappingURL=mod.d.ts.map
|
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,4BAA4B,EAC5B,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,UAAU,EACV,gBAAgB,gCACa;AAE/B,0CAA0C;AAC1C,2CAA2C;AAC3C,0CAA0C;AAE1C,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDC,GAED,iCAAiC;AAGjC,cACE,eAAe,EACf,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,0BAA0B,iCACI;AAGhC,cAAc,cAAc,EAAE,UAAU,yBAAyB;AAGjE,cACE,uBAAuB,EACvB,sBAAsB,EACtB,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,EACvB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,uBAAuB,EACvB,UAAU,EACV,UAAU,EACV,gBAAgB,gCACa;AAE/B,0CAA0C;AAC1C,2CAA2C;AAC3C,0CAA0C;AAE1C,SACE,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,cAAc,EACd,KAAK,mBAAmB,EACxB,IAAI,EACJ,KAAK,WAAW,EAChB,gBAAgB,EAChB,sBAAsB,sCACa;AAGrC,SACE,iBAAiB,EACjB,eAAe,EACf,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,KAAK,OAAO,EACzC;IAAW,WAAW,OAAO;IAAE,SAAS,OAAO;IAAE,UAAU;GACvD;EA+
|
|
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,kCAA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AU,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;AAExD,iBAAiB,qBAAqB;EACpC,SAAS;;AAKX,iBAAiB;EACf,oDAAoD,GACpD,MAAM,MAAM;EAEZ,0DAA0D,GAC1D,UAAU,MAAM;EAEhB,kFAAkF,GAClF,UAAU,QAAQ;EAElB,6CAA6C,GAC7C,QAAQ,kBAAkB,MAAM,MAAM,KAAK,OAAO;EAElD,qEAAqE,GACrE,eAAe,MAAM;EAIrB,8DAA8D,GAC9D,mBAAmB,QAAQ,wBAAwB,IAAI,GAAG,QAAQ,IAAI;EAEtE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AO;EACjC,0CAA0C,GAC1C,gBAAgB,OAAO;EACvB,uDAAuD,GACvD,YAAY,MAAM;;AAGpB;;;CAGC,GACD,iBAAiB;EACf;;GAEC,GACD,iBAAiB,OAAO;EACxB;;GAEC,GACD,cAAc,OAAO;;AAevB,iBAAiB;EACf,oCAAoC,GACpC,cAAc,MAAM;EACpB,mEAAmE,GACnE;IACE;;;;KAIC,GACD,SAAS,OAAO;IAChB;;;;KAIC,GACD,SAAS,OAAO"}
|
|
@@ -95,10 +95,52 @@ export interface ComposeDefinition {
|
|
|
95
95
|
*/ refs?: Array<ToolRefXml>;
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Input type for mcpc() that supports both inline definitions and file paths.
|
|
100
|
+
* - ComposeDefinition: Inline agent definition object
|
|
101
|
+
* - string: Path to a Markdown agent file (.md)
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Mix of inline and file-based definitions
|
|
106
|
+
* await mcpc(serverConf, [
|
|
107
|
+
* './agents/coding-agent.md', // Load from file
|
|
108
|
+
* { name: 'inline-agent', description: '...' } // Inline definition
|
|
109
|
+
* ]);
|
|
110
|
+
* ```
|
|
111
|
+
*/ export type ComposeInput = ComposeDefinition | string;
|
|
98
112
|
export interface ComposibleMCPConfig {
|
|
99
113
|
[key: string]: ComposeDefinition[];
|
|
100
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Markdown agent file loader function type.
|
|
117
|
+
* This is registered by markdownLoaderPlugin() to avoid circular dependencies.
|
|
118
|
+
*/ export type MarkdownAgentLoader = (filePath: string) => Promise<ComposeDefinition>;
|
|
119
|
+
/**
|
|
120
|
+
* Register the Markdown agent loader (called by markdownLoaderPlugin())
|
|
121
|
+
*/ export declare function setMarkdownAgentLoader(loader: MarkdownAgentLoader): void;
|
|
122
|
+
/**
|
|
123
|
+
* Check if a path is a Markdown file (.md or .markdown)
|
|
124
|
+
*/ export declare function isMarkdownFile(path: string): boolean;
|
|
101
125
|
export declare function parseMcpcConfigs(conf?: ComposeDefinition[]): ComposeDefinition[];
|
|
126
|
+
/**
|
|
127
|
+
* Options for mcpc() function
|
|
128
|
+
*/ export interface McpcOptions {
|
|
129
|
+
/**
|
|
130
|
+
* Loader plugins to load BEFORE resolving compose inputs.
|
|
131
|
+
* These plugins register file loaders (e.g., markdown-loader) that are needed
|
|
132
|
+
* to parse file paths in composeConf.
|
|
133
|
+
*
|
|
134
|
+
* Supports both plugin objects and string paths (e.g., "@mcpc/plugin-markdown-loader").
|
|
135
|
+
*
|
|
136
|
+
* Note: This is different from ComposeDefinition.plugins which are runtime plugins
|
|
137
|
+
* that transform tool descriptions and results AFTER composition.
|
|
138
|
+
*/ plugins?: (ToolPlugin | string)[];
|
|
139
|
+
/**
|
|
140
|
+
* Callback to register custom tools or perform additional setup before composition.
|
|
141
|
+
* Useful for adding internal tools or custom configurations.
|
|
142
|
+
*/ setup?: (server: ComposableMCPServer) => void | Promise<void>;
|
|
143
|
+
}
|
|
102
144
|
/**
|
|
103
145
|
* Create and configure an agentic MCP server with composed tools.
|
|
104
146
|
*
|
|
@@ -110,6 +152,7 @@ export declare function parseMcpcConfigs(conf?: ComposeDefinition[]): ComposeDef
|
|
|
110
152
|
*
|
|
111
153
|
* @example
|
|
112
154
|
* ```typescript
|
|
155
|
+
* // Using inline definitions
|
|
113
156
|
* const server = await mcpc(
|
|
114
157
|
* [
|
|
115
158
|
* { name: "coding-agent", version: "1.0.0" },
|
|
@@ -139,6 +182,16 @@ export declare function parseMcpcConfigs(conf?: ComposeDefinition[]): ComposeDef
|
|
|
139
182
|
* options: { mode: "ai_sampling" }
|
|
140
183
|
* }]
|
|
141
184
|
* );
|
|
185
|
+
*
|
|
186
|
+
* // Using Markdown file paths with plugin
|
|
187
|
+
* import { markdownLoaderPlugin } from "@mcpc/plugin-markdown-loader";
|
|
188
|
+
*
|
|
189
|
+
* const server = await mcpc(
|
|
190
|
+
* [{ name: "my-server", version: "1.0.0" }, { capabilities: { tools: {} } }],
|
|
191
|
+
* ["./agents/coding-agent.md"],
|
|
192
|
+
* { plugins: [markdownLoaderPlugin()] }
|
|
193
|
+
* );
|
|
194
|
+
*
|
|
142
195
|
* await server.connect(new StdioServerTransport());
|
|
143
196
|
* ```
|
|
144
197
|
*
|
|
@@ -146,20 +199,17 @@ export declare function parseMcpcConfigs(conf?: ComposeDefinition[]): ComposeDef
|
|
|
146
199
|
* - First element: Server metadata (name, version)
|
|
147
200
|
* - Second element: Server capabilities (tools, sampling, etc.)
|
|
148
201
|
*
|
|
149
|
-
* @param composeConf - Array of agent composition definitions
|
|
150
|
-
* -
|
|
151
|
-
* -
|
|
152
|
-
* - deps: MCP server dependencies with transport configurations (stdio, sse, streamable-http)
|
|
153
|
-
* - plugins: Global plugins to transform/extend tool behavior (objects or file paths)
|
|
154
|
-
* - options: Execution mode settings (agentic, ai_sampling, ai_acp)
|
|
202
|
+
* @param composeConf - Array of agent composition definitions or Markdown file paths.
|
|
203
|
+
* - ComposeDefinition: Inline agent definition object
|
|
204
|
+
* - string: Path to a Markdown agent file (.md) - requires markdown-loader plugin
|
|
155
205
|
*
|
|
156
|
-
* @param
|
|
157
|
-
*
|
|
206
|
+
* @param options - Optional configuration for mcpc()
|
|
207
|
+
* - plugins: Plugins to load before resolving compose inputs (e.g., markdown-loader)
|
|
158
208
|
*
|
|
159
209
|
* @returns A configured MCP Server instance ready to connect to a transport
|
|
160
210
|
*
|
|
161
211
|
* @see {@link ComposeDefinition} for detailed composition configuration options
|
|
162
212
|
* @see {@link ToolPlugin} for plugin development guide
|
|
163
213
|
* @see https://github.com/mcpc-tech/mcpc/tree/main/docs for complete documentation
|
|
164
|
-
*/ export declare function mcpc(serverConf: ConstructorParameters<typeof ComposableMCPServer>, composeConf?:
|
|
214
|
+
*/ export declare function mcpc(serverConf: ConstructorParameters<typeof ComposableMCPServer>, composeConf?: ComposeInput[], optionsOrSetup?: McpcOptions | ((server: ComposableMCPServer) => void | Promise<void>)): Promise<InstanceType<typeof ComposableMCPServer>>;
|
|
165
215
|
//# sourceMappingURL=set-up-mcp-compose.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-up-mcp-compose.d.ts","sources":["../../src/set-up-mcp-compose.ts"],"names":[],"mappings":"AAAA,SAAS,mBAAmB,oBAAoB;AAChD,cAAc,UAAU,6BAA6B;AACrD,cAAc,cAAc,qBAAqB;AACjD,cAAc,UAAU,4BAA4B;AACpD,cAAc,UAAU,qBAAqB;AAC7C,cAAc,aAAa,6BAA6B;AAExD,iBAAiB;EACf;;;GAGC,GACD,MAAM,MAAM,GAAG,IAAI;EACnB;;GAEC,GACD,cAAc,MAAM;EACpB,OAAO;EAEP;;;;;;;;;;;GAWC,GACD,WAAW,aAAa,MAAM;EAE9B;IACE;;;;;;KAMC,GACD,OAAO;IAEP;;KAEC,GACD,iBAAiB;IAEjB;;;;KAIC,GACD;MACE;QACE,QAAQ;UAAQ,OAAO,MAAM;;QAC7B,eAAe,MAAM;QACrB,gBAAgB,MAAM;QACtB,uBAAuB,MAAM;;;IAIjC;;;;KAIC,GACD;MACE,SAAS,MAAM;MACf,OAAO,MAAM;MACb,MAAM,OAAO,MAAM,EAAE,MAAM;MAC3B;QACE,MAAM,MAAM;QACZ,aAAa;UACX,MAAM,MAAM;UACZ,SAAS,MAAM;UACf,OAAO,MAAM;UACb,MAAM,OAAO,MAAM,EAAE,MAAM;;;MAG/B,iBAAiB,OAAO;;IAG1B;;;;KAIC,GACD,WAAW,MAAM;IAEjB;;;;KAIC,GACD,YAAY,MAAM;IAElB;;;;KAIC,GACD,iBAAiB,OAAO;IAExB;;;;;KAKC,GACD;;;KAGC,GACD,OAAO,MAAM;;;
|
|
1
|
+
{"version":3,"file":"set-up-mcp-compose.d.ts","sources":["../../src/set-up-mcp-compose.ts"],"names":[],"mappings":"AAAA,SAAS,mBAAmB,oBAAoB;AAChD,cAAc,UAAU,6BAA6B;AACrD,cAAc,cAAc,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