@mcpc-tech/core 0.2.8 → 0.2.10
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.mjs
CHANGED
|
@@ -329,218 +329,6 @@ var init_built_in = __esm({
|
|
|
329
329
|
}
|
|
330
330
|
});
|
|
331
331
|
|
|
332
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugin-utils.js
|
|
333
|
-
var plugin_utils_exports = {};
|
|
334
|
-
__export(plugin_utils_exports, {
|
|
335
|
-
checkCircularDependencies: () => checkCircularDependencies,
|
|
336
|
-
clearPluginCache: () => clearPluginCache,
|
|
337
|
-
getPluginsWithHook: () => getPluginsWithHook,
|
|
338
|
-
isValidPlugin: () => isValidPlugin,
|
|
339
|
-
loadPlugin: () => loadPlugin,
|
|
340
|
-
shouldApplyPlugin: () => shouldApplyPlugin,
|
|
341
|
-
sortPluginsByOrder: () => sortPluginsByOrder,
|
|
342
|
-
validatePlugins: () => validatePlugins
|
|
343
|
-
});
|
|
344
|
-
function shouldApplyPlugin(plugin, mode) {
|
|
345
|
-
if (!plugin.apply) return true;
|
|
346
|
-
if (typeof plugin.apply === "string") {
|
|
347
|
-
return mode.includes(plugin.apply);
|
|
348
|
-
}
|
|
349
|
-
if (typeof plugin.apply === "function") {
|
|
350
|
-
try {
|
|
351
|
-
return plugin.apply(mode);
|
|
352
|
-
} catch (error) {
|
|
353
|
-
console.warn(`Plugin "${plugin.name}" apply function failed: ${error}. Defaulting to true.`);
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
function sortPluginsByOrder(plugins) {
|
|
360
|
-
const pluginMap = /* @__PURE__ */ new Map();
|
|
361
|
-
for (const plugin of plugins) {
|
|
362
|
-
pluginMap.set(plugin.name, plugin);
|
|
363
|
-
}
|
|
364
|
-
const visited = /* @__PURE__ */ new Set();
|
|
365
|
-
const sorted = [];
|
|
366
|
-
function visit(plugin) {
|
|
367
|
-
if (visited.has(plugin.name)) return;
|
|
368
|
-
visited.add(plugin.name);
|
|
369
|
-
if (plugin.dependencies) {
|
|
370
|
-
for (const depName of plugin.dependencies) {
|
|
371
|
-
const dep = pluginMap.get(depName);
|
|
372
|
-
if (dep) {
|
|
373
|
-
visit(dep);
|
|
374
|
-
} else {
|
|
375
|
-
console.warn(`Plugin "${plugin.name}" depends on "${depName}" which is not loaded`);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
sorted.push(plugin);
|
|
380
|
-
}
|
|
381
|
-
const prePlugins = plugins.filter((p2) => p2.enforce === "pre");
|
|
382
|
-
const normalPlugins = plugins.filter((p2) => !p2.enforce);
|
|
383
|
-
const postPlugins = plugins.filter((p2) => p2.enforce === "post");
|
|
384
|
-
[
|
|
385
|
-
...prePlugins,
|
|
386
|
-
...normalPlugins,
|
|
387
|
-
...postPlugins
|
|
388
|
-
].forEach(visit);
|
|
389
|
-
return sorted;
|
|
390
|
-
}
|
|
391
|
-
function getPluginsWithHook(plugins, hookName) {
|
|
392
|
-
return plugins.filter((p2) => typeof p2[hookName] === "function");
|
|
393
|
-
}
|
|
394
|
-
function isValidPlugin(plugin) {
|
|
395
|
-
if (!plugin || typeof plugin !== "object") return false;
|
|
396
|
-
const p2 = plugin;
|
|
397
|
-
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
398
|
-
return false;
|
|
399
|
-
}
|
|
400
|
-
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.dispose === "function";
|
|
401
|
-
if (!hasHook) return false;
|
|
402
|
-
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
403
|
-
return false;
|
|
404
|
-
}
|
|
405
|
-
if (p2.apply && typeof p2.apply !== "string" && typeof p2.apply !== "function") {
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
if (p2.dependencies && !Array.isArray(p2.dependencies)) {
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
return true;
|
|
412
|
-
}
|
|
413
|
-
function parseQueryParams(params) {
|
|
414
|
-
const typedParams = {};
|
|
415
|
-
for (const [key, value] of Object.entries(params)) {
|
|
416
|
-
const numValue = Number(value);
|
|
417
|
-
if (!isNaN(numValue) && value.trim() !== "") {
|
|
418
|
-
typedParams[key] = numValue;
|
|
419
|
-
continue;
|
|
420
|
-
}
|
|
421
|
-
if (value === "true") {
|
|
422
|
-
typedParams[key] = true;
|
|
423
|
-
continue;
|
|
424
|
-
}
|
|
425
|
-
if (value === "false") {
|
|
426
|
-
typedParams[key] = false;
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
if (value.includes(",")) {
|
|
430
|
-
typedParams[key] = value.split(",").map((v) => v.trim());
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
typedParams[key] = value;
|
|
434
|
-
}
|
|
435
|
-
return typedParams;
|
|
436
|
-
}
|
|
437
|
-
async function loadPlugin(pluginPath, options = {
|
|
438
|
-
cache: true
|
|
439
|
-
}) {
|
|
440
|
-
if (options.cache && pluginCache.has(pluginPath)) {
|
|
441
|
-
return pluginCache.get(pluginPath);
|
|
442
|
-
}
|
|
443
|
-
try {
|
|
444
|
-
const [rawPath, queryString] = pluginPath.split("?", 2);
|
|
445
|
-
const searchParams = new URLSearchParams(queryString || "");
|
|
446
|
-
const params = Object.fromEntries(searchParams.entries());
|
|
447
|
-
const importPath = rawPath;
|
|
448
|
-
const pluginModule = await import(importPath);
|
|
449
|
-
const pluginFactory = pluginModule.createPlugin;
|
|
450
|
-
const defaultPlugin = pluginModule.default;
|
|
451
|
-
let plugin;
|
|
452
|
-
if (Object.keys(params).length > 0) {
|
|
453
|
-
if (typeof pluginFactory !== "function") {
|
|
454
|
-
throw new Error(`Plugin "${rawPath}" has parameters but no createPlugin export function`);
|
|
455
|
-
}
|
|
456
|
-
const typedParams = parseQueryParams(params);
|
|
457
|
-
plugin = pluginFactory(typedParams);
|
|
458
|
-
} else {
|
|
459
|
-
if (defaultPlugin) {
|
|
460
|
-
plugin = defaultPlugin;
|
|
461
|
-
} else if (typeof pluginFactory === "function") {
|
|
462
|
-
plugin = pluginFactory();
|
|
463
|
-
} else {
|
|
464
|
-
throw new Error(`Plugin "${rawPath}" has no default export or createPlugin function`);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (!isValidPlugin(plugin)) {
|
|
468
|
-
throw new Error(`Invalid plugin format in "${rawPath}": must have a unique name and at least one lifecycle hook`);
|
|
469
|
-
}
|
|
470
|
-
if (options.cache) {
|
|
471
|
-
pluginCache.set(pluginPath, plugin);
|
|
472
|
-
}
|
|
473
|
-
return plugin;
|
|
474
|
-
} catch (error) {
|
|
475
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
476
|
-
throw new Error(`Failed to load plugin from "${pluginPath}": ${errorMsg}`);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
function clearPluginCache() {
|
|
480
|
-
pluginCache.clear();
|
|
481
|
-
}
|
|
482
|
-
function checkCircularDependencies(plugins) {
|
|
483
|
-
const errors = [];
|
|
484
|
-
const pluginMap = /* @__PURE__ */ new Map();
|
|
485
|
-
for (const plugin of plugins) {
|
|
486
|
-
pluginMap.set(plugin.name, plugin);
|
|
487
|
-
}
|
|
488
|
-
function checkCircular(pluginName, visited, path) {
|
|
489
|
-
if (visited.has(pluginName)) {
|
|
490
|
-
const cycle = [
|
|
491
|
-
...path,
|
|
492
|
-
pluginName
|
|
493
|
-
].join(" -> ");
|
|
494
|
-
errors.push(`Circular dependency detected: ${cycle}`);
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
const plugin = pluginMap.get(pluginName);
|
|
498
|
-
if (!plugin || !plugin.dependencies) return;
|
|
499
|
-
visited.add(pluginName);
|
|
500
|
-
path.push(pluginName);
|
|
501
|
-
for (const dep of plugin.dependencies) {
|
|
502
|
-
checkCircular(dep, new Set(visited), [
|
|
503
|
-
...path
|
|
504
|
-
]);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
for (const plugin of plugins) {
|
|
508
|
-
checkCircular(plugin.name, /* @__PURE__ */ new Set(), []);
|
|
509
|
-
}
|
|
510
|
-
return errors;
|
|
511
|
-
}
|
|
512
|
-
function validatePlugins(plugins) {
|
|
513
|
-
const errors = [];
|
|
514
|
-
const names = /* @__PURE__ */ new Map();
|
|
515
|
-
for (const plugin of plugins) {
|
|
516
|
-
const count = names.get(plugin.name) || 0;
|
|
517
|
-
names.set(plugin.name, count + 1);
|
|
518
|
-
}
|
|
519
|
-
for (const [name, count] of names.entries()) {
|
|
520
|
-
if (count > 1) {
|
|
521
|
-
errors.push(`Duplicate plugin name: "${name}" (${count} instances)`);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
const circularErrors = checkCircularDependencies(plugins);
|
|
525
|
-
errors.push(...circularErrors);
|
|
526
|
-
for (const plugin of plugins) {
|
|
527
|
-
if (!isValidPlugin(plugin)) {
|
|
528
|
-
const name = plugin.name || "unknown";
|
|
529
|
-
errors.push(`Invalid plugin: "${name}"`);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return {
|
|
533
|
-
valid: errors.length === 0,
|
|
534
|
-
errors
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
var pluginCache;
|
|
538
|
-
var init_plugin_utils = __esm({
|
|
539
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/plugin-utils.js"() {
|
|
540
|
-
pluginCache = /* @__PURE__ */ new Map();
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
|
|
544
332
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
545
333
|
import traverse from "json-schema-traverse";
|
|
546
334
|
function updateRefPaths(schema, wrapperPath) {
|
|
@@ -847,6 +635,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
847
635
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
848
636
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
849
637
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
638
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
850
639
|
|
|
851
640
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/registory.js
|
|
852
641
|
function connectToSmitheryServer(smitheryConfig) {
|
|
@@ -882,54 +671,75 @@ var mcpClientPool = /* @__PURE__ */ new Map();
|
|
|
882
671
|
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
883
672
|
var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
|
|
884
673
|
function defSignature(def) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
pooled.refCount += 1;
|
|
891
|
-
return pooled.client;
|
|
674
|
+
const defCopy = {
|
|
675
|
+
...def
|
|
676
|
+
};
|
|
677
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
678
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
892
679
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
680
|
+
return JSON.stringify(defCopy);
|
|
681
|
+
}
|
|
682
|
+
function createTransport(def) {
|
|
683
|
+
const defAny = def;
|
|
684
|
+
const explicitType = defAny.transportType || defAny.type;
|
|
685
|
+
if (explicitType === "memory") {
|
|
686
|
+
if (!defAny.server) {
|
|
687
|
+
throw new Error("In-memory transport requires a 'server' field with a Server instance");
|
|
688
|
+
}
|
|
689
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
690
|
+
defAny.server.connect(serverTransport).catch((err) => {
|
|
691
|
+
console.error("Error connecting in-memory server:", err);
|
|
692
|
+
});
|
|
693
|
+
return clientTransport;
|
|
899
694
|
}
|
|
900
|
-
|
|
901
|
-
if (typeof def.transportType === "string" && def.transportType === "sse") {
|
|
695
|
+
if (explicitType === "sse") {
|
|
902
696
|
const options = {};
|
|
903
|
-
if (
|
|
697
|
+
if (defAny.headers) {
|
|
904
698
|
options.requestInit = {
|
|
905
|
-
headers:
|
|
699
|
+
headers: defAny.headers
|
|
906
700
|
};
|
|
907
701
|
options.eventSourceInit = {
|
|
908
|
-
headers:
|
|
702
|
+
headers: defAny.headers
|
|
909
703
|
};
|
|
910
704
|
}
|
|
911
|
-
|
|
912
|
-
}
|
|
705
|
+
return new SSEClientTransport(new URL(defAny.url), options);
|
|
706
|
+
}
|
|
707
|
+
if (defAny.url && typeof defAny.url === "string") {
|
|
913
708
|
const options = {};
|
|
914
|
-
if (
|
|
709
|
+
if (defAny.headers) {
|
|
915
710
|
options.requestInit = {
|
|
916
|
-
headers:
|
|
711
|
+
headers: defAny.headers
|
|
917
712
|
};
|
|
918
713
|
}
|
|
919
|
-
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
714
|
+
return new StreamableHTTPClientTransport(new URL(defAny.url), options);
|
|
715
|
+
}
|
|
716
|
+
if (explicitType === "stdio" || defAny.command) {
|
|
717
|
+
return new StdioClientTransport({
|
|
718
|
+
command: defAny.command,
|
|
719
|
+
args: defAny.args,
|
|
924
720
|
env: {
|
|
925
721
|
...process3.env,
|
|
926
|
-
...
|
|
722
|
+
...defAny.env ?? {}
|
|
927
723
|
},
|
|
928
724
|
cwd: cwd()
|
|
929
725
|
});
|
|
930
|
-
} else {
|
|
931
|
-
throw new Error(`Unsupported transport type: ${JSON.stringify(def)}`);
|
|
932
726
|
}
|
|
727
|
+
throw new Error(`Unsupported transport configuration: ${JSON.stringify(def)}`);
|
|
728
|
+
}
|
|
729
|
+
async function getOrCreateMcpClient(defKey, def) {
|
|
730
|
+
const pooled = mcpClientPool.get(defKey);
|
|
731
|
+
if (pooled) {
|
|
732
|
+
pooled.refCount += 1;
|
|
733
|
+
return pooled.client;
|
|
734
|
+
}
|
|
735
|
+
const existingConnecting = mcpClientConnecting.get(defKey);
|
|
736
|
+
if (existingConnecting) {
|
|
737
|
+
const client = await existingConnecting;
|
|
738
|
+
const entry = mcpClientPool.get(defKey);
|
|
739
|
+
if (entry) entry.refCount += 1;
|
|
740
|
+
return client;
|
|
741
|
+
}
|
|
742
|
+
const transport = createTransport(def);
|
|
933
743
|
const connecting = (async () => {
|
|
934
744
|
const client = new Client({
|
|
935
745
|
name: `mcp_${shortHash(defSignature(def))}`,
|
|
@@ -3227,10 +3037,199 @@ function processToolTags({ description, tagToResults, $, tools, toolOverrides, t
|
|
|
3227
3037
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/compose.js
|
|
3228
3038
|
init_built_in();
|
|
3229
3039
|
init_logger();
|
|
3230
|
-
|
|
3040
|
+
|
|
3041
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugin-utils.js
|
|
3042
|
+
var pluginCache = /* @__PURE__ */ new Map();
|
|
3043
|
+
function shouldApplyPlugin(plugin, mode) {
|
|
3044
|
+
if (!plugin.apply) return true;
|
|
3045
|
+
if (typeof plugin.apply === "string") {
|
|
3046
|
+
return mode.includes(plugin.apply);
|
|
3047
|
+
}
|
|
3048
|
+
if (typeof plugin.apply === "function") {
|
|
3049
|
+
try {
|
|
3050
|
+
return plugin.apply(mode);
|
|
3051
|
+
} catch (error) {
|
|
3052
|
+
console.warn(`Plugin "${plugin.name}" apply function failed: ${error}. Defaulting to true.`);
|
|
3053
|
+
return true;
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
return true;
|
|
3057
|
+
}
|
|
3058
|
+
function sortPluginsByOrder(plugins) {
|
|
3059
|
+
const pluginMap = /* @__PURE__ */ new Map();
|
|
3060
|
+
for (const plugin of plugins) {
|
|
3061
|
+
pluginMap.set(plugin.name, plugin);
|
|
3062
|
+
}
|
|
3063
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3064
|
+
const sorted = [];
|
|
3065
|
+
function visit(plugin) {
|
|
3066
|
+
if (visited.has(plugin.name)) return;
|
|
3067
|
+
visited.add(plugin.name);
|
|
3068
|
+
if (plugin.dependencies) {
|
|
3069
|
+
for (const depName of plugin.dependencies) {
|
|
3070
|
+
const dep = pluginMap.get(depName);
|
|
3071
|
+
if (dep) {
|
|
3072
|
+
visit(dep);
|
|
3073
|
+
} else {
|
|
3074
|
+
console.warn(`Plugin "${plugin.name}" depends on "${depName}" which is not loaded`);
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
sorted.push(plugin);
|
|
3079
|
+
}
|
|
3080
|
+
const prePlugins = plugins.filter((p2) => p2.enforce === "pre");
|
|
3081
|
+
const normalPlugins = plugins.filter((p2) => !p2.enforce);
|
|
3082
|
+
const postPlugins = plugins.filter((p2) => p2.enforce === "post");
|
|
3083
|
+
[
|
|
3084
|
+
...prePlugins,
|
|
3085
|
+
...normalPlugins,
|
|
3086
|
+
...postPlugins
|
|
3087
|
+
].forEach(visit);
|
|
3088
|
+
return sorted;
|
|
3089
|
+
}
|
|
3090
|
+
function isValidPlugin(plugin) {
|
|
3091
|
+
if (!plugin || typeof plugin !== "object") return false;
|
|
3092
|
+
const p2 = plugin;
|
|
3093
|
+
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
3094
|
+
return false;
|
|
3095
|
+
}
|
|
3096
|
+
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.dispose === "function";
|
|
3097
|
+
if (!hasHook) return false;
|
|
3098
|
+
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
3099
|
+
return false;
|
|
3100
|
+
}
|
|
3101
|
+
if (p2.apply && typeof p2.apply !== "string" && typeof p2.apply !== "function") {
|
|
3102
|
+
return false;
|
|
3103
|
+
}
|
|
3104
|
+
if (p2.dependencies && !Array.isArray(p2.dependencies)) {
|
|
3105
|
+
return false;
|
|
3106
|
+
}
|
|
3107
|
+
return true;
|
|
3108
|
+
}
|
|
3109
|
+
function parseQueryParams(params) {
|
|
3110
|
+
const typedParams = {};
|
|
3111
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3112
|
+
const numValue = Number(value);
|
|
3113
|
+
if (!isNaN(numValue) && value.trim() !== "") {
|
|
3114
|
+
typedParams[key] = numValue;
|
|
3115
|
+
continue;
|
|
3116
|
+
}
|
|
3117
|
+
if (value === "true") {
|
|
3118
|
+
typedParams[key] = true;
|
|
3119
|
+
continue;
|
|
3120
|
+
}
|
|
3121
|
+
if (value === "false") {
|
|
3122
|
+
typedParams[key] = false;
|
|
3123
|
+
continue;
|
|
3124
|
+
}
|
|
3125
|
+
if (value.includes(",")) {
|
|
3126
|
+
typedParams[key] = value.split(",").map((v) => v.trim());
|
|
3127
|
+
continue;
|
|
3128
|
+
}
|
|
3129
|
+
typedParams[key] = value;
|
|
3130
|
+
}
|
|
3131
|
+
return typedParams;
|
|
3132
|
+
}
|
|
3133
|
+
async function loadPlugin(pluginPath, options = {
|
|
3134
|
+
cache: true
|
|
3135
|
+
}) {
|
|
3136
|
+
if (options.cache && pluginCache.has(pluginPath)) {
|
|
3137
|
+
return pluginCache.get(pluginPath);
|
|
3138
|
+
}
|
|
3139
|
+
try {
|
|
3140
|
+
const [rawPath, queryString] = pluginPath.split("?", 2);
|
|
3141
|
+
const searchParams = new URLSearchParams(queryString || "");
|
|
3142
|
+
const params = Object.fromEntries(searchParams.entries());
|
|
3143
|
+
const resolveFn = import.meta.resolve;
|
|
3144
|
+
const importPath = typeof resolveFn === "function" ? resolveFn(rawPath) : new URL(rawPath, import.meta.url).href;
|
|
3145
|
+
const pluginModule = await import(importPath);
|
|
3146
|
+
const pluginFactory = pluginModule.createPlugin;
|
|
3147
|
+
const defaultPlugin = pluginModule.default;
|
|
3148
|
+
let plugin;
|
|
3149
|
+
if (Object.keys(params).length > 0) {
|
|
3150
|
+
if (typeof pluginFactory !== "function") {
|
|
3151
|
+
throw new Error(`Plugin "${rawPath}" has parameters but no createPlugin export function`);
|
|
3152
|
+
}
|
|
3153
|
+
const typedParams = parseQueryParams(params);
|
|
3154
|
+
plugin = pluginFactory(typedParams);
|
|
3155
|
+
} else {
|
|
3156
|
+
if (defaultPlugin) {
|
|
3157
|
+
plugin = defaultPlugin;
|
|
3158
|
+
} else if (typeof pluginFactory === "function") {
|
|
3159
|
+
plugin = pluginFactory();
|
|
3160
|
+
} else {
|
|
3161
|
+
throw new Error(`Plugin "${rawPath}" has no default export or createPlugin function`);
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
if (!isValidPlugin(plugin)) {
|
|
3165
|
+
throw new Error(`Invalid plugin format in "${rawPath}": must have a unique name and at least one lifecycle hook`);
|
|
3166
|
+
}
|
|
3167
|
+
if (options.cache) {
|
|
3168
|
+
pluginCache.set(pluginPath, plugin);
|
|
3169
|
+
}
|
|
3170
|
+
return plugin;
|
|
3171
|
+
} catch (error) {
|
|
3172
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
3173
|
+
throw new Error(`Failed to load plugin from "${pluginPath}": ${errorMsg}`);
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
function checkCircularDependencies(plugins) {
|
|
3177
|
+
const errors = [];
|
|
3178
|
+
const pluginMap = /* @__PURE__ */ new Map();
|
|
3179
|
+
for (const plugin of plugins) {
|
|
3180
|
+
pluginMap.set(plugin.name, plugin);
|
|
3181
|
+
}
|
|
3182
|
+
function checkCircular(pluginName, visited, path) {
|
|
3183
|
+
if (visited.has(pluginName)) {
|
|
3184
|
+
const cycle = [
|
|
3185
|
+
...path,
|
|
3186
|
+
pluginName
|
|
3187
|
+
].join(" -> ");
|
|
3188
|
+
errors.push(`Circular dependency detected: ${cycle}`);
|
|
3189
|
+
return;
|
|
3190
|
+
}
|
|
3191
|
+
const plugin = pluginMap.get(pluginName);
|
|
3192
|
+
if (!plugin || !plugin.dependencies) return;
|
|
3193
|
+
visited.add(pluginName);
|
|
3194
|
+
path.push(pluginName);
|
|
3195
|
+
for (const dep of plugin.dependencies) {
|
|
3196
|
+
checkCircular(dep, new Set(visited), [
|
|
3197
|
+
...path
|
|
3198
|
+
]);
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
for (const plugin of plugins) {
|
|
3202
|
+
checkCircular(plugin.name, /* @__PURE__ */ new Set(), []);
|
|
3203
|
+
}
|
|
3204
|
+
return errors;
|
|
3205
|
+
}
|
|
3206
|
+
function validatePlugins(plugins) {
|
|
3207
|
+
const errors = [];
|
|
3208
|
+
const names = /* @__PURE__ */ new Map();
|
|
3209
|
+
for (const plugin of plugins) {
|
|
3210
|
+
const count = names.get(plugin.name) || 0;
|
|
3211
|
+
names.set(plugin.name, count + 1);
|
|
3212
|
+
}
|
|
3213
|
+
for (const [name, count] of names.entries()) {
|
|
3214
|
+
if (count > 1) {
|
|
3215
|
+
errors.push(`Duplicate plugin name: "${name}" (${count} instances)`);
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
const circularErrors = checkCircularDependencies(plugins);
|
|
3219
|
+
errors.push(...circularErrors);
|
|
3220
|
+
for (const plugin of plugins) {
|
|
3221
|
+
if (!isValidPlugin(plugin)) {
|
|
3222
|
+
const name = plugin.name || "unknown";
|
|
3223
|
+
errors.push(`Invalid plugin: "${name}"`);
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
return {
|
|
3227
|
+
valid: errors.length === 0,
|
|
3228
|
+
errors
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
3231
3231
|
|
|
3232
3232
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/plugin-manager.js
|
|
3233
|
-
init_plugin_utils();
|
|
3234
3233
|
init_logger();
|
|
3235
3234
|
var PluginManager = class {
|
|
3236
3235
|
server;
|
|
@@ -3636,8 +3635,7 @@ var ComposableMCPServer = class extends Server {
|
|
|
3636
3635
|
if (plugins.length === 0) {
|
|
3637
3636
|
return data;
|
|
3638
3637
|
}
|
|
3639
|
-
const
|
|
3640
|
-
const sortedPlugins = sortPluginsByOrder2(plugins);
|
|
3638
|
+
const sortedPlugins = sortPluginsByOrder(plugins);
|
|
3641
3639
|
let currentData = data;
|
|
3642
3640
|
const context2 = {
|
|
3643
3641
|
toolName,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sources":["../../src/compose.ts"],"names":[],"mappings":"AAAA,SAGE,KAAK,cAAc,EAGnB,KAAK,IAAI,6CAC6C;AACxD,SAAwC,KAAK,MAAM,4BAA4B;AAC/E,cAAc,iBAAiB,6BAA6B;AAC5D,SACE,MAAM,EACN,KAAK,aAAa,oDAC2C;AAC/D,YAAY,aAAyB;AAGrC,cAAc,iBAAiB,kCAAkC;AACjE,cAAc,UAAU,EAAE,YAAY,qBAAqB;AAQ3D,cAA4B,UAAU,EAAE,UAAU,4BAA4B;AAU9E,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;
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sources":["../../src/compose.ts"],"names":[],"mappings":"AAAA,SAGE,KAAK,cAAc,EAGnB,KAAK,IAAI,6CAC6C;AACxD,SAAwC,KAAK,MAAM,4BAA4B;AAC/E,cAAc,iBAAiB,6BAA6B;AAC5D,SACE,MAAM,EACN,KAAK,aAAa,oDAC2C;AAC/D,YAAY,aAAyB;AAGrC,cAAc,iBAAiB,kCAAkC;AACjE,cAAc,UAAU,EAAE,YAAY,qBAAqB;AAQ3D,cAA4B,UAAU,EAAE,UAAU,4BAA4B;AAU9E,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;UAwDN;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,UAAU;GAAmB;EAqE9D;;GAEC,GACD,gBAAgB,MAAM,MAAM,GAAG,eAAe,SAAS;EAIvD;;GAEC,GACD,eAAe,QAAQ,MAAM,GAAG,aAAa,SAAS;EAItD;;GAEC,GACD,AAAM,SAAS,MAAM,MAAM,EAAE,MAAM,OAAO,GAAG,QAAQ,OAAO;EAyB5D;;GAEC,GACD,sBAAsB,MAAM;EAI5B;;GAEC,GACD,kBAAkB;EAIlB;;GAEC,GACD,sBAAsB,MAAM;EAI5B;;GAEC,GACD,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;EAUd;;GAEC,GACD,AAAM,kBAAkB,QAAQ,IAAI;EAI9B,QACJ,MAAM,MAAM,GAAG,IAAI,EACnB,aAAa,MAAM,EACnB,aAAY,EAAE,aAAa,kBAAuC,EAClE,UAAS,kBAAkB,UAAgC;AA+P/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sources":["../../../src/service/tools.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC,cAA0B;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sources":["../../../src/service/tools.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC,cAA0B;AA+CpC,OAAO,cAAM,mBAAmB,EAAE,UAAU,OAAO,MAAM,EAAE,EAAE,aAGxD;AASL,YAAY,aACR,EAAE,aAAa,qBACf,EAAE,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sources":["../../../../src/utils/common/mcp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sources":["../../../../src/utils/common/mcp.ts"],"names":[],"mappings":"AAKA,cACE,iBAAiB,iCAEa;AAChC,YAAY,aAAyB;AA4LrC,OAAO,iBAAe,mBACpB,WACI,EAAE,aAAa,qBACf,EAAE,aAAa,kBAAkB,EACrC,YAAY;EACV,QAAQ,MAAM;EACd,MAAM,GAAG;EACT,SAAS,MAAM;EACf,mBAAmB,MAAM;EACzB,kBAAkB,MAAM;EACxB,QAAQ,MAAM;MACV,OAAO,GACZ,QAAQ,OAAO,MAAM,EAAE,GAAG"}
|