@mcpc-tech/plugin-markdown-loader 0.0.4 → 0.0.6
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 +263 -99
- package/index.mjs +262 -100
- package/package.json +1 -1
- package/types/mod.d.ts +1 -1
- package/types/mod.d.ts.map +1 -1
- package/types/src/markdown-loader.d.ts +29 -1
- package/types/src/markdown-loader.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -32,7 +32,9 @@ var mod_exports = {};
|
|
|
32
32
|
__export(mod_exports, {
|
|
33
33
|
createPlugin: () => createPlugin,
|
|
34
34
|
default: () => mod_default,
|
|
35
|
+
isDirectory: () => isDirectory,
|
|
35
36
|
isMarkdownAgentFile: () => isMarkdownFile,
|
|
37
|
+
loadMarkdownAgentDirectory: () => loadMarkdownAgentDirectory,
|
|
36
38
|
loadMarkdownAgentFile: () => loadMarkdownAgentFile,
|
|
37
39
|
markdownAgentToComposeDefinition: () => markdownAgentToComposeDefinition,
|
|
38
40
|
markdownLoaderPlugin: () => markdownLoaderPlugin,
|
|
@@ -467,6 +469,23 @@ Execute a tool:
|
|
|
467
469
|
"args": { /* tool parameters */ }
|
|
468
470
|
}
|
|
469
471
|
\`\`\`
|
|
472
|
+
</format>`,
|
|
473
|
+
/**
|
|
474
|
+
* Compact system prompt for autonomous MCP execution (when manual is provided)
|
|
475
|
+
*
|
|
476
|
+
* Uses simplified description with progressive disclosure:
|
|
477
|
+
* - Short description shown by default
|
|
478
|
+
* - Use `man` command with args `{ manual: true }` to get full manual
|
|
479
|
+
*/
|
|
480
|
+
AUTONOMOUS_EXECUTION_COMPACT: `Agentic tool \`{toolName}\`: {description}
|
|
481
|
+
|
|
482
|
+
Use \`man\` command with args \`{ tools: [], manual: true }\` to get the full manual, or \`{ tools: ["tool1"] }\` to get tool schemas.
|
|
483
|
+
|
|
484
|
+
<format>
|
|
485
|
+
Get full manual: \`{ "tool": "man", "args": { "tools": [], "manual": true } }\`
|
|
486
|
+
Get tool schemas: \`{ "tool": "man", "args": { "tools": ["tool1", "tool2"] } }\`
|
|
487
|
+
Get both: \`{ "tool": "man", "args": { "tools": ["tool1"], "manual": true } }\`
|
|
488
|
+
Execute a tool: \`{ "tool": "tool_name", "args": { /* parameters */ } }\`
|
|
470
489
|
</format>`,
|
|
471
490
|
/**
|
|
472
491
|
* Tool description for sampling tools (shown in MCP tools list)
|
|
@@ -544,6 +563,7 @@ Adjust parameters and retry.`,
|
|
|
544
563
|
};
|
|
545
564
|
var CompiledPrompts = {
|
|
546
565
|
autonomousExecution: p(SystemPrompts.AUTONOMOUS_EXECUTION),
|
|
566
|
+
autonomousExecutionCompact: p(SystemPrompts.AUTONOMOUS_EXECUTION_COMPACT),
|
|
547
567
|
samplingToolDescription: p(SystemPrompts.SAMPLING_TOOL_DESCRIPTION),
|
|
548
568
|
aiLoopSystem: p(SystemPrompts.AI_LOOP_SYSTEM),
|
|
549
569
|
actionSuccess: p(ResponseTemplates.ACTION_SUCCESS),
|
|
@@ -610,7 +630,7 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
|
|
|
610
630
|
},
|
|
611
631
|
args: {
|
|
612
632
|
type: "object",
|
|
613
|
-
description: `For "man": { tools: ["tool1", "tool2"] }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
|
|
633
|
+
description: `For "man": { tools: ["tool1", "tool2"], manual?: true }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
|
|
614
634
|
}
|
|
615
635
|
},
|
|
616
636
|
required: [
|
|
@@ -621,7 +641,10 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
|
|
|
621
641
|
},
|
|
622
642
|
/**
|
|
623
643
|
* Schema for "man" command args validation
|
|
624
|
-
* Expected format: { tools: ["tool1", "tool2"] }
|
|
644
|
+
* Expected format: { tools: ["tool1", "tool2"], manual?: true }
|
|
645
|
+
*
|
|
646
|
+
* - Always require `tools`
|
|
647
|
+
* - Allow empty tools only when `manual: true`
|
|
625
648
|
*/
|
|
626
649
|
forMan: function(allToolNames) {
|
|
627
650
|
return {
|
|
@@ -635,16 +658,50 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
|
|
|
635
658
|
errorMessage: {
|
|
636
659
|
enum: `Invalid tool name. Available: ${allToolNames.join(", ")}`
|
|
637
660
|
}
|
|
638
|
-
},
|
|
639
|
-
minItems: 1,
|
|
640
|
-
errorMessage: {
|
|
641
|
-
minItems: "At least one tool name is required"
|
|
642
661
|
}
|
|
662
|
+
},
|
|
663
|
+
manual: {
|
|
664
|
+
type: "boolean",
|
|
665
|
+
description: "Set to true to get the full manual for this agent (progressive disclosure)."
|
|
643
666
|
}
|
|
644
667
|
},
|
|
645
668
|
required: [
|
|
646
669
|
"tools"
|
|
647
670
|
],
|
|
671
|
+
additionalProperties: false,
|
|
672
|
+
anyOf: [
|
|
673
|
+
// manual-only (tools can be empty)
|
|
674
|
+
{
|
|
675
|
+
properties: {
|
|
676
|
+
manual: {
|
|
677
|
+
enum: [
|
|
678
|
+
true
|
|
679
|
+
]
|
|
680
|
+
},
|
|
681
|
+
tools: {
|
|
682
|
+
minItems: 0
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
required: [
|
|
686
|
+
"tools",
|
|
687
|
+
"manual"
|
|
688
|
+
]
|
|
689
|
+
},
|
|
690
|
+
// tool schemas (require at least one tool)
|
|
691
|
+
{
|
|
692
|
+
properties: {
|
|
693
|
+
tools: {
|
|
694
|
+
minItems: 1,
|
|
695
|
+
errorMessage: {
|
|
696
|
+
minItems: "At least one tool name is required"
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
},
|
|
700
|
+
required: [
|
|
701
|
+
"tools"
|
|
702
|
+
]
|
|
703
|
+
}
|
|
704
|
+
],
|
|
648
705
|
errorMessage: {
|
|
649
706
|
required: {
|
|
650
707
|
tools: 'Missing "tools" field. Expected: { tools: ["tool1", "tool2"] }'
|
|
@@ -766,14 +823,16 @@ var AgenticExecutor = class {
|
|
|
766
823
|
allToolNames;
|
|
767
824
|
toolNameToDetailList;
|
|
768
825
|
server;
|
|
826
|
+
manual;
|
|
769
827
|
logger;
|
|
770
828
|
tracingEnabled;
|
|
771
829
|
toolSchemaMap;
|
|
772
|
-
constructor(name, allToolNames, toolNameToDetailList, server) {
|
|
830
|
+
constructor(name, allToolNames, toolNameToDetailList, server, manual) {
|
|
773
831
|
this.name = name;
|
|
774
832
|
this.allToolNames = allToolNames;
|
|
775
833
|
this.toolNameToDetailList = toolNameToDetailList;
|
|
776
834
|
this.server = server;
|
|
835
|
+
this.manual = manual;
|
|
777
836
|
this.tracingEnabled = false;
|
|
778
837
|
this.logger = createLogger(`mcpc.agentic.${name}`, server);
|
|
779
838
|
this.toolSchemaMap = new Map(toolNameToDetailList);
|
|
@@ -841,7 +900,34 @@ var AgenticExecutor = class {
|
|
|
841
900
|
};
|
|
842
901
|
}
|
|
843
902
|
const argsObj = args.args;
|
|
844
|
-
|
|
903
|
+
const tools = argsObj.tools ?? [];
|
|
904
|
+
const wantManual = argsObj.manual === true;
|
|
905
|
+
const wantTools = tools.length > 0;
|
|
906
|
+
if (wantTools && wantManual) {
|
|
907
|
+
const toolSchemas = this.handleManCommand(tools, null);
|
|
908
|
+
const manualResult = this.handleManualRequest(null);
|
|
909
|
+
if (executeSpan) {
|
|
910
|
+
executeSpan.setAttributes({
|
|
911
|
+
toolType: "man",
|
|
912
|
+
requestType: "tools+manual"
|
|
913
|
+
});
|
|
914
|
+
endSpan(executeSpan);
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
content: [
|
|
918
|
+
...toolSchemas.content,
|
|
919
|
+
{
|
|
920
|
+
type: "text",
|
|
921
|
+
text: "\n---\n"
|
|
922
|
+
},
|
|
923
|
+
...manualResult.content
|
|
924
|
+
]
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
if (wantManual) {
|
|
928
|
+
return this.handleManualRequest(executeSpan);
|
|
929
|
+
}
|
|
930
|
+
return this.handleManCommand(tools, executeSpan);
|
|
845
931
|
}
|
|
846
932
|
const toolArgs = args.args || {};
|
|
847
933
|
return await this.executeTool(tool2, toolArgs, executeSpan);
|
|
@@ -864,6 +950,44 @@ var AgenticExecutor = class {
|
|
|
864
950
|
};
|
|
865
951
|
}
|
|
866
952
|
}
|
|
953
|
+
/**
|
|
954
|
+
* Handle `man { manual: true }` - return full manual for progressive disclosure
|
|
955
|
+
*/
|
|
956
|
+
handleManualRequest(executeSpan) {
|
|
957
|
+
if (executeSpan) {
|
|
958
|
+
executeSpan.setAttributes({
|
|
959
|
+
toolType: "man",
|
|
960
|
+
requestType: "manual"
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
if (!this.manual) {
|
|
964
|
+
if (executeSpan) {
|
|
965
|
+
endSpan(executeSpan);
|
|
966
|
+
}
|
|
967
|
+
return {
|
|
968
|
+
content: [
|
|
969
|
+
{
|
|
970
|
+
type: "text",
|
|
971
|
+
text: "No manual available for this agent."
|
|
972
|
+
}
|
|
973
|
+
]
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
if (executeSpan) {
|
|
977
|
+
executeSpan.setAttributes({
|
|
978
|
+
success: true
|
|
979
|
+
});
|
|
980
|
+
endSpan(executeSpan);
|
|
981
|
+
}
|
|
982
|
+
return {
|
|
983
|
+
content: [
|
|
984
|
+
{
|
|
985
|
+
type: "text",
|
|
986
|
+
text: this.manual
|
|
987
|
+
}
|
|
988
|
+
]
|
|
989
|
+
};
|
|
990
|
+
}
|
|
867
991
|
/**
|
|
868
992
|
* Handle `man` command - return schemas for requested tools
|
|
869
993
|
* @param requestedTools - Array of tool names (already validated via JSON Schema)
|
|
@@ -905,15 +1029,29 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
905
1029
|
* Execute a tool with runtime validation
|
|
906
1030
|
*/
|
|
907
1031
|
async executeTool(tool2, toolArgs, executeSpan) {
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
1032
|
+
const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
|
|
1033
|
+
const isInternalTool = this.allToolNames.includes(tool2);
|
|
1034
|
+
if (!isExternalTool && !isInternalTool) {
|
|
911
1035
|
if (executeSpan) {
|
|
912
1036
|
executeSpan.setAttributes({
|
|
913
|
-
toolType: "
|
|
914
|
-
|
|
1037
|
+
toolType: "not_found",
|
|
1038
|
+
tool: tool2
|
|
915
1039
|
});
|
|
1040
|
+
endSpan(executeSpan);
|
|
916
1041
|
}
|
|
1042
|
+
return {
|
|
1043
|
+
content: [
|
|
1044
|
+
{
|
|
1045
|
+
type: "text",
|
|
1046
|
+
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
1047
|
+
}
|
|
1048
|
+
],
|
|
1049
|
+
isError: true
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
if (isExternalTool) {
|
|
1053
|
+
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
1054
|
+
const [, toolDetail] = externalTool;
|
|
917
1055
|
if (toolDetail.inputSchema) {
|
|
918
1056
|
const rawSchema = extractJsonSchema(toolDetail.inputSchema);
|
|
919
1057
|
const validation = validateSchema(toolArgs, rawSchema);
|
|
@@ -936,84 +1074,53 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
936
1074
|
};
|
|
937
1075
|
}
|
|
938
1076
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1077
|
+
}
|
|
1078
|
+
const toolType = isExternalTool ? "external" : "internal";
|
|
1079
|
+
if (executeSpan) {
|
|
1080
|
+
executeSpan.setAttributes({
|
|
1081
|
+
toolType,
|
|
1082
|
+
selectedTool: tool2
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
this.logger.debug({
|
|
1086
|
+
message: `Executing ${toolType} tool`,
|
|
1087
|
+
tool: tool2
|
|
1088
|
+
});
|
|
1089
|
+
try {
|
|
1090
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
1091
|
+
agentName: this.name
|
|
942
1092
|
});
|
|
943
|
-
const
|
|
1093
|
+
const callToolResult = result ?? {
|
|
1094
|
+
content: []
|
|
1095
|
+
};
|
|
944
1096
|
if (executeSpan) {
|
|
945
1097
|
executeSpan.setAttributes({
|
|
946
1098
|
success: true,
|
|
947
|
-
isError: !!
|
|
948
|
-
resultContentLength:
|
|
1099
|
+
isError: !!callToolResult.isError,
|
|
1100
|
+
resultContentLength: callToolResult.content?.length || 0
|
|
949
1101
|
});
|
|
950
1102
|
endSpan(executeSpan);
|
|
951
1103
|
}
|
|
952
|
-
return
|
|
953
|
-
}
|
|
954
|
-
if (this.allToolNames.includes(tool2)) {
|
|
1104
|
+
return callToolResult;
|
|
1105
|
+
} catch (error) {
|
|
955
1106
|
if (executeSpan) {
|
|
956
|
-
executeSpan
|
|
957
|
-
toolType: "internal",
|
|
958
|
-
selectedTool: tool2
|
|
959
|
-
});
|
|
960
|
-
}
|
|
961
|
-
this.logger.debug({
|
|
962
|
-
message: "Executing internal tool",
|
|
963
|
-
tool: tool2
|
|
964
|
-
});
|
|
965
|
-
try {
|
|
966
|
-
const result = await this.server.callTool(tool2, toolArgs, {
|
|
967
|
-
agentName: this.name
|
|
968
|
-
});
|
|
969
|
-
const callToolResult = result ?? {
|
|
970
|
-
content: []
|
|
971
|
-
};
|
|
972
|
-
if (executeSpan) {
|
|
973
|
-
executeSpan.setAttributes({
|
|
974
|
-
success: true,
|
|
975
|
-
isError: !!callToolResult.isError,
|
|
976
|
-
resultContentLength: callToolResult.content?.length || 0
|
|
977
|
-
});
|
|
978
|
-
endSpan(executeSpan);
|
|
979
|
-
}
|
|
980
|
-
return callToolResult;
|
|
981
|
-
} catch (error) {
|
|
982
|
-
if (executeSpan) {
|
|
983
|
-
endSpan(executeSpan, error);
|
|
984
|
-
}
|
|
985
|
-
this.logger.error({
|
|
986
|
-
message: "Error executing internal tool",
|
|
987
|
-
tool: tool2,
|
|
988
|
-
error: String(error)
|
|
989
|
-
});
|
|
990
|
-
return {
|
|
991
|
-
content: [
|
|
992
|
-
{
|
|
993
|
-
type: "text",
|
|
994
|
-
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
995
|
-
}
|
|
996
|
-
],
|
|
997
|
-
isError: true
|
|
998
|
-
};
|
|
1107
|
+
endSpan(executeSpan, error);
|
|
999
1108
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
tool: tool2
|
|
1109
|
+
this.logger.error({
|
|
1110
|
+
message: `Error executing ${toolType} tool`,
|
|
1111
|
+
tool: tool2,
|
|
1112
|
+
error: String(error)
|
|
1005
1113
|
});
|
|
1006
|
-
|
|
1114
|
+
return {
|
|
1115
|
+
content: [
|
|
1116
|
+
{
|
|
1117
|
+
type: "text",
|
|
1118
|
+
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
1119
|
+
}
|
|
1120
|
+
],
|
|
1121
|
+
isError: true
|
|
1122
|
+
};
|
|
1007
1123
|
}
|
|
1008
|
-
return {
|
|
1009
|
-
content: [
|
|
1010
|
-
{
|
|
1011
|
-
type: "text",
|
|
1012
|
-
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
1013
|
-
}
|
|
1014
|
-
],
|
|
1015
|
-
isError: true
|
|
1016
|
-
};
|
|
1017
1124
|
}
|
|
1018
1125
|
validate(args, schema) {
|
|
1019
1126
|
return validateSchema(args, schema);
|
|
@@ -1021,19 +1128,18 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
1021
1128
|
};
|
|
1022
1129
|
|
|
1023
1130
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-tool-registrar.js
|
|
1024
|
-
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList }) {
|
|
1131
|
+
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, manual }) {
|
|
1025
1132
|
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
1026
|
-
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
1027
|
-
description = CompiledPrompts.
|
|
1133
|
+
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server, manual);
|
|
1134
|
+
description = manual ? CompiledPrompts.autonomousExecutionCompact({
|
|
1135
|
+
toolName: name,
|
|
1136
|
+
description
|
|
1137
|
+
}) : CompiledPrompts.autonomousExecution({
|
|
1028
1138
|
toolName: name,
|
|
1029
1139
|
description
|
|
1030
1140
|
});
|
|
1031
1141
|
const agenticArgsDef = createArgsDef.forAgentic(allToolNames);
|
|
1032
|
-
const
|
|
1033
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
1034
|
-
type: "object",
|
|
1035
|
-
properties: {}
|
|
1036
|
-
};
|
|
1142
|
+
const schema = agenticArgsDef;
|
|
1037
1143
|
server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
|
|
1038
1144
|
return await agenticExecutor.execute(args, schema);
|
|
1039
1145
|
});
|
|
@@ -1052,7 +1158,8 @@ var createAgenticModePlugin = () => ({
|
|
|
1052
1158
|
name: context2.name,
|
|
1053
1159
|
allToolNames: context2.allToolNames,
|
|
1054
1160
|
depGroups: context2.depGroups,
|
|
1055
|
-
toolNameToDetailList: context2.toolNameToDetailList
|
|
1161
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
1162
|
+
manual: context2.manual
|
|
1056
1163
|
});
|
|
1057
1164
|
}
|
|
1058
1165
|
});
|
|
@@ -1454,7 +1561,7 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
1454
1561
|
let enhanced = systemPrompt || "";
|
|
1455
1562
|
const toolsPrompt = `
|
|
1456
1563
|
|
|
1457
|
-
|
|
1564
|
+
<available_tools>
|
|
1458
1565
|
You have access to the following tools. To use a tool, respond with this XML format:
|
|
1459
1566
|
<use_tool tool="tool_name">
|
|
1460
1567
|
{"param1": "value1", "param2": "value2"}
|
|
@@ -1463,23 +1570,34 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
1463
1570
|
Follow the JSON schema definition for each tool's parameters.
|
|
1464
1571
|
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
1465
1572
|
|
|
1466
|
-
|
|
1573
|
+
<tools>`;
|
|
1467
1574
|
const toolDescriptions = tools.map((tool2) => {
|
|
1468
1575
|
if (tool2.type === "function") {
|
|
1469
1576
|
const toolAny = tool2;
|
|
1470
1577
|
const description = toolAny.description || "No description provided";
|
|
1471
1578
|
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1579
|
+
const schemaStr = schema ? `
|
|
1580
|
+
<schema>
|
|
1581
|
+
${JSON.stringify(schema, null, 2)}
|
|
1582
|
+
</schema>` : "";
|
|
1474
1583
|
return `
|
|
1475
|
-
|
|
1584
|
+
<tool name="${tool2.name}">
|
|
1585
|
+
<description>
|
|
1586
|
+
${description}
|
|
1587
|
+
</description>${schemaStr}
|
|
1588
|
+
</tool>`;
|
|
1476
1589
|
} else if (tool2.type === "provider-defined") {
|
|
1477
1590
|
return `
|
|
1478
|
-
|
|
1591
|
+
<tool name="${tool2.name}">
|
|
1592
|
+
<description>${tool2.id || "No description provided"}</description>
|
|
1593
|
+
</tool>`;
|
|
1479
1594
|
}
|
|
1480
1595
|
return "";
|
|
1481
1596
|
}).filter(Boolean).join("");
|
|
1482
|
-
|
|
1597
|
+
const toolsEnd = `
|
|
1598
|
+
</tools>
|
|
1599
|
+
</available_tools>`;
|
|
1600
|
+
enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
|
|
1483
1601
|
return enhanced || void 0;
|
|
1484
1602
|
}
|
|
1485
1603
|
/**
|
|
@@ -3897,6 +4015,7 @@ function parse(content, options = {}) {
|
|
|
3897
4015
|
}
|
|
3898
4016
|
|
|
3899
4017
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
|
|
4018
|
+
var import_node_path = require("node:path");
|
|
3900
4019
|
var import_node_process5 = __toESM(require("node:process"), 1);
|
|
3901
4020
|
function replaceEnvVars(str2) {
|
|
3902
4021
|
return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, varName) => {
|
|
@@ -3937,7 +4056,7 @@ function parseMarkdownAgent(content) {
|
|
|
3937
4056
|
}
|
|
3938
4057
|
return {
|
|
3939
4058
|
frontMatter,
|
|
3940
|
-
|
|
4059
|
+
body: markdownContent.trim()
|
|
3941
4060
|
};
|
|
3942
4061
|
}
|
|
3943
4062
|
var OPTION_KEYS = [
|
|
@@ -3952,16 +4071,20 @@ var OPTION_KEYS = [
|
|
|
3952
4071
|
];
|
|
3953
4072
|
function markdownAgentToComposeDefinition(parsed) {
|
|
3954
4073
|
const frontMatter = replaceEnvVarsInObject(parsed.frontMatter);
|
|
3955
|
-
const
|
|
4074
|
+
const body = replaceEnvVars(parsed.body);
|
|
3956
4075
|
const options = {};
|
|
3957
4076
|
for (const key of OPTION_KEYS) {
|
|
3958
4077
|
if (frontMatter[key] !== void 0) {
|
|
3959
4078
|
options[key] = frontMatter[key];
|
|
3960
4079
|
}
|
|
3961
4080
|
}
|
|
4081
|
+
const hasDescription = frontMatter.description !== void 0 && frontMatter.description !== "";
|
|
3962
4082
|
return {
|
|
3963
4083
|
name: frontMatter.name,
|
|
3964
|
-
description,
|
|
4084
|
+
description: hasDescription ? frontMatter.description : body,
|
|
4085
|
+
...hasDescription && body ? {
|
|
4086
|
+
manual: body
|
|
4087
|
+
} : {},
|
|
3965
4088
|
deps: frontMatter.deps,
|
|
3966
4089
|
plugins: frontMatter.plugins,
|
|
3967
4090
|
...Object.keys(options).length > 0 ? {
|
|
@@ -3974,6 +4097,45 @@ async function loadMarkdownAgentFile(filePath) {
|
|
|
3974
4097
|
const parsed = parseMarkdownAgent(content);
|
|
3975
4098
|
return markdownAgentToComposeDefinition(parsed);
|
|
3976
4099
|
}
|
|
4100
|
+
async function loadMarkdownAgentDirectory(dirPath, options = {}) {
|
|
4101
|
+
const { recursive = false } = options;
|
|
4102
|
+
const definitions = [];
|
|
4103
|
+
const errors = [];
|
|
4104
|
+
async function processDirectory(dir) {
|
|
4105
|
+
const entries = await (0, import_promises.readdir)(dir, {
|
|
4106
|
+
withFileTypes: true
|
|
4107
|
+
});
|
|
4108
|
+
for (const entry of entries) {
|
|
4109
|
+
const fullPath = (0, import_node_path.join)(dir, entry.name);
|
|
4110
|
+
if (entry.isDirectory() && recursive) {
|
|
4111
|
+
await processDirectory(fullPath);
|
|
4112
|
+
} else if (entry.isFile() && isMarkdownFile(entry.name)) {
|
|
4113
|
+
try {
|
|
4114
|
+
const definition = await loadMarkdownAgentFile(fullPath);
|
|
4115
|
+
definitions.push(definition);
|
|
4116
|
+
} catch (error) {
|
|
4117
|
+
errors.push({
|
|
4118
|
+
path: fullPath,
|
|
4119
|
+
error: error instanceof Error ? error.message : String(error)
|
|
4120
|
+
});
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
await processDirectory(dirPath);
|
|
4126
|
+
return {
|
|
4127
|
+
definitions,
|
|
4128
|
+
errors
|
|
4129
|
+
};
|
|
4130
|
+
}
|
|
4131
|
+
async function isDirectory(path) {
|
|
4132
|
+
try {
|
|
4133
|
+
const stats = await (0, import_promises.stat)(path);
|
|
4134
|
+
return stats.isDirectory();
|
|
4135
|
+
} catch {
|
|
4136
|
+
return false;
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
3977
4139
|
|
|
3978
4140
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/mod.ts
|
|
3979
4141
|
function markdownLoaderPlugin() {
|
|
@@ -3993,7 +4155,9 @@ var mod_default = defaultPlugin;
|
|
|
3993
4155
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3994
4156
|
0 && (module.exports = {
|
|
3995
4157
|
createPlugin,
|
|
4158
|
+
isDirectory,
|
|
3996
4159
|
isMarkdownAgentFile,
|
|
4160
|
+
loadMarkdownAgentDirectory,
|
|
3997
4161
|
loadMarkdownAgentFile,
|
|
3998
4162
|
markdownAgentToComposeDefinition,
|
|
3999
4163
|
markdownLoaderPlugin,
|
package/index.mjs
CHANGED
|
@@ -428,6 +428,23 @@ Execute a tool:
|
|
|
428
428
|
"args": { /* tool parameters */ }
|
|
429
429
|
}
|
|
430
430
|
\`\`\`
|
|
431
|
+
</format>`,
|
|
432
|
+
/**
|
|
433
|
+
* Compact system prompt for autonomous MCP execution (when manual is provided)
|
|
434
|
+
*
|
|
435
|
+
* Uses simplified description with progressive disclosure:
|
|
436
|
+
* - Short description shown by default
|
|
437
|
+
* - Use `man` command with args `{ manual: true }` to get full manual
|
|
438
|
+
*/
|
|
439
|
+
AUTONOMOUS_EXECUTION_COMPACT: `Agentic tool \`{toolName}\`: {description}
|
|
440
|
+
|
|
441
|
+
Use \`man\` command with args \`{ tools: [], manual: true }\` to get the full manual, or \`{ tools: ["tool1"] }\` to get tool schemas.
|
|
442
|
+
|
|
443
|
+
<format>
|
|
444
|
+
Get full manual: \`{ "tool": "man", "args": { "tools": [], "manual": true } }\`
|
|
445
|
+
Get tool schemas: \`{ "tool": "man", "args": { "tools": ["tool1", "tool2"] } }\`
|
|
446
|
+
Get both: \`{ "tool": "man", "args": { "tools": ["tool1"], "manual": true } }\`
|
|
447
|
+
Execute a tool: \`{ "tool": "tool_name", "args": { /* parameters */ } }\`
|
|
431
448
|
</format>`,
|
|
432
449
|
/**
|
|
433
450
|
* Tool description for sampling tools (shown in MCP tools list)
|
|
@@ -505,6 +522,7 @@ Adjust parameters and retry.`,
|
|
|
505
522
|
};
|
|
506
523
|
var CompiledPrompts = {
|
|
507
524
|
autonomousExecution: p(SystemPrompts.AUTONOMOUS_EXECUTION),
|
|
525
|
+
autonomousExecutionCompact: p(SystemPrompts.AUTONOMOUS_EXECUTION_COMPACT),
|
|
508
526
|
samplingToolDescription: p(SystemPrompts.SAMPLING_TOOL_DESCRIPTION),
|
|
509
527
|
aiLoopSystem: p(SystemPrompts.AI_LOOP_SYSTEM),
|
|
510
528
|
actionSuccess: p(ResponseTemplates.ACTION_SUCCESS),
|
|
@@ -571,7 +589,7 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
|
|
|
571
589
|
},
|
|
572
590
|
args: {
|
|
573
591
|
type: "object",
|
|
574
|
-
description: `For "man": { tools: ["tool1", "tool2"] }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
|
|
592
|
+
description: `For "man": { tools: ["tool1", "tool2"], manual?: true }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
|
|
575
593
|
}
|
|
576
594
|
},
|
|
577
595
|
required: [
|
|
@@ -582,7 +600,10 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
|
|
|
582
600
|
},
|
|
583
601
|
/**
|
|
584
602
|
* Schema for "man" command args validation
|
|
585
|
-
* Expected format: { tools: ["tool1", "tool2"] }
|
|
603
|
+
* Expected format: { tools: ["tool1", "tool2"], manual?: true }
|
|
604
|
+
*
|
|
605
|
+
* - Always require `tools`
|
|
606
|
+
* - Allow empty tools only when `manual: true`
|
|
586
607
|
*/
|
|
587
608
|
forMan: function(allToolNames) {
|
|
588
609
|
return {
|
|
@@ -596,16 +617,50 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
|
|
|
596
617
|
errorMessage: {
|
|
597
618
|
enum: `Invalid tool name. Available: ${allToolNames.join(", ")}`
|
|
598
619
|
}
|
|
599
|
-
},
|
|
600
|
-
minItems: 1,
|
|
601
|
-
errorMessage: {
|
|
602
|
-
minItems: "At least one tool name is required"
|
|
603
620
|
}
|
|
621
|
+
},
|
|
622
|
+
manual: {
|
|
623
|
+
type: "boolean",
|
|
624
|
+
description: "Set to true to get the full manual for this agent (progressive disclosure)."
|
|
604
625
|
}
|
|
605
626
|
},
|
|
606
627
|
required: [
|
|
607
628
|
"tools"
|
|
608
629
|
],
|
|
630
|
+
additionalProperties: false,
|
|
631
|
+
anyOf: [
|
|
632
|
+
// manual-only (tools can be empty)
|
|
633
|
+
{
|
|
634
|
+
properties: {
|
|
635
|
+
manual: {
|
|
636
|
+
enum: [
|
|
637
|
+
true
|
|
638
|
+
]
|
|
639
|
+
},
|
|
640
|
+
tools: {
|
|
641
|
+
minItems: 0
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
required: [
|
|
645
|
+
"tools",
|
|
646
|
+
"manual"
|
|
647
|
+
]
|
|
648
|
+
},
|
|
649
|
+
// tool schemas (require at least one tool)
|
|
650
|
+
{
|
|
651
|
+
properties: {
|
|
652
|
+
tools: {
|
|
653
|
+
minItems: 1,
|
|
654
|
+
errorMessage: {
|
|
655
|
+
minItems: "At least one tool name is required"
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
required: [
|
|
660
|
+
"tools"
|
|
661
|
+
]
|
|
662
|
+
}
|
|
663
|
+
],
|
|
609
664
|
errorMessage: {
|
|
610
665
|
required: {
|
|
611
666
|
tools: 'Missing "tools" field. Expected: { tools: ["tool1", "tool2"] }'
|
|
@@ -727,14 +782,16 @@ var AgenticExecutor = class {
|
|
|
727
782
|
allToolNames;
|
|
728
783
|
toolNameToDetailList;
|
|
729
784
|
server;
|
|
785
|
+
manual;
|
|
730
786
|
logger;
|
|
731
787
|
tracingEnabled;
|
|
732
788
|
toolSchemaMap;
|
|
733
|
-
constructor(name, allToolNames, toolNameToDetailList, server) {
|
|
789
|
+
constructor(name, allToolNames, toolNameToDetailList, server, manual) {
|
|
734
790
|
this.name = name;
|
|
735
791
|
this.allToolNames = allToolNames;
|
|
736
792
|
this.toolNameToDetailList = toolNameToDetailList;
|
|
737
793
|
this.server = server;
|
|
794
|
+
this.manual = manual;
|
|
738
795
|
this.tracingEnabled = false;
|
|
739
796
|
this.logger = createLogger(`mcpc.agentic.${name}`, server);
|
|
740
797
|
this.toolSchemaMap = new Map(toolNameToDetailList);
|
|
@@ -802,7 +859,34 @@ var AgenticExecutor = class {
|
|
|
802
859
|
};
|
|
803
860
|
}
|
|
804
861
|
const argsObj = args.args;
|
|
805
|
-
|
|
862
|
+
const tools = argsObj.tools ?? [];
|
|
863
|
+
const wantManual = argsObj.manual === true;
|
|
864
|
+
const wantTools = tools.length > 0;
|
|
865
|
+
if (wantTools && wantManual) {
|
|
866
|
+
const toolSchemas = this.handleManCommand(tools, null);
|
|
867
|
+
const manualResult = this.handleManualRequest(null);
|
|
868
|
+
if (executeSpan) {
|
|
869
|
+
executeSpan.setAttributes({
|
|
870
|
+
toolType: "man",
|
|
871
|
+
requestType: "tools+manual"
|
|
872
|
+
});
|
|
873
|
+
endSpan(executeSpan);
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
content: [
|
|
877
|
+
...toolSchemas.content,
|
|
878
|
+
{
|
|
879
|
+
type: "text",
|
|
880
|
+
text: "\n---\n"
|
|
881
|
+
},
|
|
882
|
+
...manualResult.content
|
|
883
|
+
]
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
if (wantManual) {
|
|
887
|
+
return this.handleManualRequest(executeSpan);
|
|
888
|
+
}
|
|
889
|
+
return this.handleManCommand(tools, executeSpan);
|
|
806
890
|
}
|
|
807
891
|
const toolArgs = args.args || {};
|
|
808
892
|
return await this.executeTool(tool2, toolArgs, executeSpan);
|
|
@@ -825,6 +909,44 @@ var AgenticExecutor = class {
|
|
|
825
909
|
};
|
|
826
910
|
}
|
|
827
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Handle `man { manual: true }` - return full manual for progressive disclosure
|
|
914
|
+
*/
|
|
915
|
+
handleManualRequest(executeSpan) {
|
|
916
|
+
if (executeSpan) {
|
|
917
|
+
executeSpan.setAttributes({
|
|
918
|
+
toolType: "man",
|
|
919
|
+
requestType: "manual"
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
if (!this.manual) {
|
|
923
|
+
if (executeSpan) {
|
|
924
|
+
endSpan(executeSpan);
|
|
925
|
+
}
|
|
926
|
+
return {
|
|
927
|
+
content: [
|
|
928
|
+
{
|
|
929
|
+
type: "text",
|
|
930
|
+
text: "No manual available for this agent."
|
|
931
|
+
}
|
|
932
|
+
]
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
if (executeSpan) {
|
|
936
|
+
executeSpan.setAttributes({
|
|
937
|
+
success: true
|
|
938
|
+
});
|
|
939
|
+
endSpan(executeSpan);
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
content: [
|
|
943
|
+
{
|
|
944
|
+
type: "text",
|
|
945
|
+
text: this.manual
|
|
946
|
+
}
|
|
947
|
+
]
|
|
948
|
+
};
|
|
949
|
+
}
|
|
828
950
|
/**
|
|
829
951
|
* Handle `man` command - return schemas for requested tools
|
|
830
952
|
* @param requestedTools - Array of tool names (already validated via JSON Schema)
|
|
@@ -866,15 +988,29 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
866
988
|
* Execute a tool with runtime validation
|
|
867
989
|
*/
|
|
868
990
|
async executeTool(tool2, toolArgs, executeSpan) {
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
991
|
+
const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
|
|
992
|
+
const isInternalTool = this.allToolNames.includes(tool2);
|
|
993
|
+
if (!isExternalTool && !isInternalTool) {
|
|
872
994
|
if (executeSpan) {
|
|
873
995
|
executeSpan.setAttributes({
|
|
874
|
-
toolType: "
|
|
875
|
-
|
|
996
|
+
toolType: "not_found",
|
|
997
|
+
tool: tool2
|
|
876
998
|
});
|
|
999
|
+
endSpan(executeSpan);
|
|
877
1000
|
}
|
|
1001
|
+
return {
|
|
1002
|
+
content: [
|
|
1003
|
+
{
|
|
1004
|
+
type: "text",
|
|
1005
|
+
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
1006
|
+
}
|
|
1007
|
+
],
|
|
1008
|
+
isError: true
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
if (isExternalTool) {
|
|
1012
|
+
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
1013
|
+
const [, toolDetail] = externalTool;
|
|
878
1014
|
if (toolDetail.inputSchema) {
|
|
879
1015
|
const rawSchema = extractJsonSchema(toolDetail.inputSchema);
|
|
880
1016
|
const validation = validateSchema(toolArgs, rawSchema);
|
|
@@ -897,84 +1033,53 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
897
1033
|
};
|
|
898
1034
|
}
|
|
899
1035
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1036
|
+
}
|
|
1037
|
+
const toolType = isExternalTool ? "external" : "internal";
|
|
1038
|
+
if (executeSpan) {
|
|
1039
|
+
executeSpan.setAttributes({
|
|
1040
|
+
toolType,
|
|
1041
|
+
selectedTool: tool2
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
this.logger.debug({
|
|
1045
|
+
message: `Executing ${toolType} tool`,
|
|
1046
|
+
tool: tool2
|
|
1047
|
+
});
|
|
1048
|
+
try {
|
|
1049
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
1050
|
+
agentName: this.name
|
|
903
1051
|
});
|
|
904
|
-
const
|
|
1052
|
+
const callToolResult = result ?? {
|
|
1053
|
+
content: []
|
|
1054
|
+
};
|
|
905
1055
|
if (executeSpan) {
|
|
906
1056
|
executeSpan.setAttributes({
|
|
907
1057
|
success: true,
|
|
908
|
-
isError: !!
|
|
909
|
-
resultContentLength:
|
|
1058
|
+
isError: !!callToolResult.isError,
|
|
1059
|
+
resultContentLength: callToolResult.content?.length || 0
|
|
910
1060
|
});
|
|
911
1061
|
endSpan(executeSpan);
|
|
912
1062
|
}
|
|
913
|
-
return
|
|
914
|
-
}
|
|
915
|
-
if (this.allToolNames.includes(tool2)) {
|
|
1063
|
+
return callToolResult;
|
|
1064
|
+
} catch (error) {
|
|
916
1065
|
if (executeSpan) {
|
|
917
|
-
executeSpan
|
|
918
|
-
toolType: "internal",
|
|
919
|
-
selectedTool: tool2
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
this.logger.debug({
|
|
923
|
-
message: "Executing internal tool",
|
|
924
|
-
tool: tool2
|
|
925
|
-
});
|
|
926
|
-
try {
|
|
927
|
-
const result = await this.server.callTool(tool2, toolArgs, {
|
|
928
|
-
agentName: this.name
|
|
929
|
-
});
|
|
930
|
-
const callToolResult = result ?? {
|
|
931
|
-
content: []
|
|
932
|
-
};
|
|
933
|
-
if (executeSpan) {
|
|
934
|
-
executeSpan.setAttributes({
|
|
935
|
-
success: true,
|
|
936
|
-
isError: !!callToolResult.isError,
|
|
937
|
-
resultContentLength: callToolResult.content?.length || 0
|
|
938
|
-
});
|
|
939
|
-
endSpan(executeSpan);
|
|
940
|
-
}
|
|
941
|
-
return callToolResult;
|
|
942
|
-
} catch (error) {
|
|
943
|
-
if (executeSpan) {
|
|
944
|
-
endSpan(executeSpan, error);
|
|
945
|
-
}
|
|
946
|
-
this.logger.error({
|
|
947
|
-
message: "Error executing internal tool",
|
|
948
|
-
tool: tool2,
|
|
949
|
-
error: String(error)
|
|
950
|
-
});
|
|
951
|
-
return {
|
|
952
|
-
content: [
|
|
953
|
-
{
|
|
954
|
-
type: "text",
|
|
955
|
-
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
956
|
-
}
|
|
957
|
-
],
|
|
958
|
-
isError: true
|
|
959
|
-
};
|
|
1066
|
+
endSpan(executeSpan, error);
|
|
960
1067
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
tool: tool2
|
|
1068
|
+
this.logger.error({
|
|
1069
|
+
message: `Error executing ${toolType} tool`,
|
|
1070
|
+
tool: tool2,
|
|
1071
|
+
error: String(error)
|
|
966
1072
|
});
|
|
967
|
-
|
|
1073
|
+
return {
|
|
1074
|
+
content: [
|
|
1075
|
+
{
|
|
1076
|
+
type: "text",
|
|
1077
|
+
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
1078
|
+
}
|
|
1079
|
+
],
|
|
1080
|
+
isError: true
|
|
1081
|
+
};
|
|
968
1082
|
}
|
|
969
|
-
return {
|
|
970
|
-
content: [
|
|
971
|
-
{
|
|
972
|
-
type: "text",
|
|
973
|
-
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
974
|
-
}
|
|
975
|
-
],
|
|
976
|
-
isError: true
|
|
977
|
-
};
|
|
978
1083
|
}
|
|
979
1084
|
validate(args, schema) {
|
|
980
1085
|
return validateSchema(args, schema);
|
|
@@ -982,19 +1087,18 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
982
1087
|
};
|
|
983
1088
|
|
|
984
1089
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-tool-registrar.js
|
|
985
|
-
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList }) {
|
|
1090
|
+
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, manual }) {
|
|
986
1091
|
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
987
|
-
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
988
|
-
description = CompiledPrompts.
|
|
1092
|
+
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server, manual);
|
|
1093
|
+
description = manual ? CompiledPrompts.autonomousExecutionCompact({
|
|
1094
|
+
toolName: name,
|
|
1095
|
+
description
|
|
1096
|
+
}) : CompiledPrompts.autonomousExecution({
|
|
989
1097
|
toolName: name,
|
|
990
1098
|
description
|
|
991
1099
|
});
|
|
992
1100
|
const agenticArgsDef = createArgsDef.forAgentic(allToolNames);
|
|
993
|
-
const
|
|
994
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
995
|
-
type: "object",
|
|
996
|
-
properties: {}
|
|
997
|
-
};
|
|
1101
|
+
const schema = agenticArgsDef;
|
|
998
1102
|
server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
|
|
999
1103
|
return await agenticExecutor.execute(args, schema);
|
|
1000
1104
|
});
|
|
@@ -1013,7 +1117,8 @@ var createAgenticModePlugin = () => ({
|
|
|
1013
1117
|
name: context2.name,
|
|
1014
1118
|
allToolNames: context2.allToolNames,
|
|
1015
1119
|
depGroups: context2.depGroups,
|
|
1016
|
-
toolNameToDetailList: context2.toolNameToDetailList
|
|
1120
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
1121
|
+
manual: context2.manual
|
|
1017
1122
|
});
|
|
1018
1123
|
}
|
|
1019
1124
|
});
|
|
@@ -1415,7 +1520,7 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
1415
1520
|
let enhanced = systemPrompt || "";
|
|
1416
1521
|
const toolsPrompt = `
|
|
1417
1522
|
|
|
1418
|
-
|
|
1523
|
+
<available_tools>
|
|
1419
1524
|
You have access to the following tools. To use a tool, respond with this XML format:
|
|
1420
1525
|
<use_tool tool="tool_name">
|
|
1421
1526
|
{"param1": "value1", "param2": "value2"}
|
|
@@ -1424,23 +1529,34 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
1424
1529
|
Follow the JSON schema definition for each tool's parameters.
|
|
1425
1530
|
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
1426
1531
|
|
|
1427
|
-
|
|
1532
|
+
<tools>`;
|
|
1428
1533
|
const toolDescriptions = tools.map((tool2) => {
|
|
1429
1534
|
if (tool2.type === "function") {
|
|
1430
1535
|
const toolAny = tool2;
|
|
1431
1536
|
const description = toolAny.description || "No description provided";
|
|
1432
1537
|
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1538
|
+
const schemaStr = schema ? `
|
|
1539
|
+
<schema>
|
|
1540
|
+
${JSON.stringify(schema, null, 2)}
|
|
1541
|
+
</schema>` : "";
|
|
1435
1542
|
return `
|
|
1436
|
-
|
|
1543
|
+
<tool name="${tool2.name}">
|
|
1544
|
+
<description>
|
|
1545
|
+
${description}
|
|
1546
|
+
</description>${schemaStr}
|
|
1547
|
+
</tool>`;
|
|
1437
1548
|
} else if (tool2.type === "provider-defined") {
|
|
1438
1549
|
return `
|
|
1439
|
-
|
|
1550
|
+
<tool name="${tool2.name}">
|
|
1551
|
+
<description>${tool2.id || "No description provided"}</description>
|
|
1552
|
+
</tool>`;
|
|
1440
1553
|
}
|
|
1441
1554
|
return "";
|
|
1442
1555
|
}).filter(Boolean).join("");
|
|
1443
|
-
|
|
1556
|
+
const toolsEnd = `
|
|
1557
|
+
</tools>
|
|
1558
|
+
</available_tools>`;
|
|
1559
|
+
enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
|
|
1444
1560
|
return enhanced || void 0;
|
|
1445
1561
|
}
|
|
1446
1562
|
/**
|
|
@@ -1919,7 +2035,7 @@ function isMarkdownFile(path) {
|
|
|
1919
2035
|
}
|
|
1920
2036
|
|
|
1921
2037
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
|
|
1922
|
-
import { readFile } from "node:fs/promises";
|
|
2038
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
1923
2039
|
|
|
1924
2040
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/std__yaml/_chars.js
|
|
1925
2041
|
var TAB = 9;
|
|
@@ -3858,6 +3974,7 @@ function parse(content, options = {}) {
|
|
|
3858
3974
|
}
|
|
3859
3975
|
|
|
3860
3976
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
|
|
3977
|
+
import { join } from "node:path";
|
|
3861
3978
|
import process5 from "node:process";
|
|
3862
3979
|
function replaceEnvVars(str2) {
|
|
3863
3980
|
return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, varName) => {
|
|
@@ -3898,7 +4015,7 @@ function parseMarkdownAgent(content) {
|
|
|
3898
4015
|
}
|
|
3899
4016
|
return {
|
|
3900
4017
|
frontMatter,
|
|
3901
|
-
|
|
4018
|
+
body: markdownContent.trim()
|
|
3902
4019
|
};
|
|
3903
4020
|
}
|
|
3904
4021
|
var OPTION_KEYS = [
|
|
@@ -3913,16 +4030,20 @@ var OPTION_KEYS = [
|
|
|
3913
4030
|
];
|
|
3914
4031
|
function markdownAgentToComposeDefinition(parsed) {
|
|
3915
4032
|
const frontMatter = replaceEnvVarsInObject(parsed.frontMatter);
|
|
3916
|
-
const
|
|
4033
|
+
const body = replaceEnvVars(parsed.body);
|
|
3917
4034
|
const options = {};
|
|
3918
4035
|
for (const key of OPTION_KEYS) {
|
|
3919
4036
|
if (frontMatter[key] !== void 0) {
|
|
3920
4037
|
options[key] = frontMatter[key];
|
|
3921
4038
|
}
|
|
3922
4039
|
}
|
|
4040
|
+
const hasDescription = frontMatter.description !== void 0 && frontMatter.description !== "";
|
|
3923
4041
|
return {
|
|
3924
4042
|
name: frontMatter.name,
|
|
3925
|
-
description,
|
|
4043
|
+
description: hasDescription ? frontMatter.description : body,
|
|
4044
|
+
...hasDescription && body ? {
|
|
4045
|
+
manual: body
|
|
4046
|
+
} : {},
|
|
3926
4047
|
deps: frontMatter.deps,
|
|
3927
4048
|
plugins: frontMatter.plugins,
|
|
3928
4049
|
...Object.keys(options).length > 0 ? {
|
|
@@ -3935,6 +4056,45 @@ async function loadMarkdownAgentFile(filePath) {
|
|
|
3935
4056
|
const parsed = parseMarkdownAgent(content);
|
|
3936
4057
|
return markdownAgentToComposeDefinition(parsed);
|
|
3937
4058
|
}
|
|
4059
|
+
async function loadMarkdownAgentDirectory(dirPath, options = {}) {
|
|
4060
|
+
const { recursive = false } = options;
|
|
4061
|
+
const definitions = [];
|
|
4062
|
+
const errors = [];
|
|
4063
|
+
async function processDirectory(dir) {
|
|
4064
|
+
const entries = await readdir(dir, {
|
|
4065
|
+
withFileTypes: true
|
|
4066
|
+
});
|
|
4067
|
+
for (const entry of entries) {
|
|
4068
|
+
const fullPath = join(dir, entry.name);
|
|
4069
|
+
if (entry.isDirectory() && recursive) {
|
|
4070
|
+
await processDirectory(fullPath);
|
|
4071
|
+
} else if (entry.isFile() && isMarkdownFile(entry.name)) {
|
|
4072
|
+
try {
|
|
4073
|
+
const definition = await loadMarkdownAgentFile(fullPath);
|
|
4074
|
+
definitions.push(definition);
|
|
4075
|
+
} catch (error) {
|
|
4076
|
+
errors.push({
|
|
4077
|
+
path: fullPath,
|
|
4078
|
+
error: error instanceof Error ? error.message : String(error)
|
|
4079
|
+
});
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
await processDirectory(dirPath);
|
|
4085
|
+
return {
|
|
4086
|
+
definitions,
|
|
4087
|
+
errors
|
|
4088
|
+
};
|
|
4089
|
+
}
|
|
4090
|
+
async function isDirectory(path) {
|
|
4091
|
+
try {
|
|
4092
|
+
const stats = await stat(path);
|
|
4093
|
+
return stats.isDirectory();
|
|
4094
|
+
} catch {
|
|
4095
|
+
return false;
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
3938
4098
|
|
|
3939
4099
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/mod.ts
|
|
3940
4100
|
function markdownLoaderPlugin() {
|
|
@@ -3954,7 +4114,9 @@ var mod_default = defaultPlugin;
|
|
|
3954
4114
|
export {
|
|
3955
4115
|
createPlugin,
|
|
3956
4116
|
mod_default as default,
|
|
4117
|
+
isDirectory,
|
|
3957
4118
|
isMarkdownFile as isMarkdownAgentFile,
|
|
4119
|
+
loadMarkdownAgentDirectory,
|
|
3958
4120
|
loadMarkdownAgentFile,
|
|
3959
4121
|
markdownAgentToComposeDefinition,
|
|
3960
4122
|
markdownLoaderPlugin,
|
package/package.json
CHANGED
package/types/mod.d.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* @module
|
|
26
26
|
*/ import { type ToolPlugin } from "@jsr/mcpc__core";
|
|
27
27
|
export { setMarkdownAgentLoader } from "@jsr/mcpc__core";
|
|
28
|
-
export { isMarkdownAgentFile, loadMarkdownAgentFile, type MarkdownAgentFrontMatter, markdownAgentToComposeDefinition, type ParsedMarkdownAgent, parseMarkdownAgent } from "./src/markdown-loader.js";
|
|
28
|
+
export { isDirectory, isMarkdownAgentFile, type LoadDirectoryResult, loadMarkdownAgentDirectory, loadMarkdownAgentFile, type MarkdownAgentFrontMatter, markdownAgentToComposeDefinition, type ParsedMarkdownAgent, parseMarkdownAgent } from "./src/markdown-loader.js";
|
|
29
29
|
/**
|
|
30
30
|
* Create a Markdown loader plugin for mcpc().
|
|
31
31
|
*
|
package/types/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GAED,SAAiC,KAAK,UAAU,0BAAiC;AAIjF,SAAS,sBAAsB,0BAAiC;AAEhE,SACE,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,gCAAgC,EAChC,KAAK,mBAAmB,EACxB,kBAAkB,mCACc;AAElC;;;;;CAKC,GACD,OAAO,iBAAS,wBAAwB;AAWxC,qDAAqD,GACrD,OAAO,cAAM,kBAAoC;AAEjD,4DAA4D,GAC5D,cAAM,eAAe;AACrB,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GAED,SAAiC,KAAK,UAAU,0BAAiC;AAIjF,SAAS,sBAAsB,0BAAiC;AAEhE,SACE,WAAW,EACX,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,gCAAgC,EAChC,KAAK,mBAAmB,EACxB,kBAAkB,mCACc;AAElC;;;;;CAKC,GACD,OAAO,iBAAS,wBAAwB;AAWxC,qDAAqD,GACrD,OAAO,cAAM,kBAAoC;AAEjD,4DAA4D,GAC5D,cAAM,eAAe;AACrB,eAAe,cAAc"}
|
|
@@ -31,6 +31,11 @@ export { isMarkdownFile as isMarkdownAgentFile };
|
|
|
31
31
|
* Front matter configuration for Markdown agent definitions
|
|
32
32
|
*/ export interface MarkdownAgentFrontMatter {
|
|
33
33
|
/** Agent name (required) */ name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Short description for progressive disclosure.
|
|
36
|
+
* If provided, the Markdown body becomes the `manual` field.
|
|
37
|
+
* If not provided, the Markdown body becomes the `description` field.
|
|
38
|
+
*/ description?: string;
|
|
34
39
|
/** Execution mode */ mode?: "agentic" | "ai_sampling" | "ai_acp" | "code_execution";
|
|
35
40
|
/** Maximum execution steps */ maxSteps?: number;
|
|
36
41
|
/** Maximum tokens for sampling */ maxTokens?: number;
|
|
@@ -71,7 +76,7 @@ export { isMarkdownFile as isMarkdownAgentFile };
|
|
|
71
76
|
* Result of parsing a Markdown agent file
|
|
72
77
|
*/ export interface ParsedMarkdownAgent {
|
|
73
78
|
frontMatter: MarkdownAgentFrontMatter;
|
|
74
|
-
|
|
79
|
+
/** The Markdown body content */ body: string;
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
77
82
|
* Parse YAML front matter and Markdown content from a string
|
|
@@ -82,4 +87,27 @@ export { isMarkdownFile as isMarkdownAgentFile };
|
|
|
82
87
|
/**
|
|
83
88
|
* Load a Markdown agent definition from a file path
|
|
84
89
|
*/ export declare function loadMarkdownAgentFile(filePath: string): Promise<ComposeDefinition>;
|
|
90
|
+
/**
|
|
91
|
+
* Result of loading agents from a directory
|
|
92
|
+
*/ export interface LoadDirectoryResult {
|
|
93
|
+
/** Successfully loaded agent definitions */ definitions: ComposeDefinition[];
|
|
94
|
+
/** Errors encountered during loading (file path and error message) */ errors: Array<{
|
|
95
|
+
path: string;
|
|
96
|
+
error: string;
|
|
97
|
+
}>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Load all Markdown agent definitions from a directory.
|
|
101
|
+
* Only loads .md files in the directory (non-recursive by default).
|
|
102
|
+
*
|
|
103
|
+
* @param dirPath - Path to the directory containing Markdown agent files
|
|
104
|
+
* @param options - Options for loading
|
|
105
|
+
* @param options.recursive - If true, recursively search subdirectories (default: false)
|
|
106
|
+
* @returns Object containing definitions and any errors encountered
|
|
107
|
+
*/ export declare function loadMarkdownAgentDirectory(dirPath: string, options?: {
|
|
108
|
+
recursive?: boolean;
|
|
109
|
+
}): Promise<LoadDirectoryResult>;
|
|
110
|
+
/**
|
|
111
|
+
* Check if a path is a directory
|
|
112
|
+
*/ export declare function isDirectory(path: string): Promise<boolean>;
|
|
85
113
|
//# sourceMappingURL=markdown-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-loader.d.ts","sources":["../../src/markdown-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GAED,SACE,KAAK,iBAAiB,EACtB,cAAc,EACd,KAAK,eAAe,EAEpB,KAAK,cAAc,0BACW;
|
|
1
|
+
{"version":3,"file":"markdown-loader.d.ts","sources":["../../src/markdown-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GAED,SACE,KAAK,iBAAiB,EACtB,cAAc,EACd,KAAK,eAAe,EAEpB,KAAK,cAAc,0BACW;AAOhC,SAAyB,kBAAkB,mBAAmB,GAAG;AAgCjE;;CAEC,GACD,iBAAiB;EACf,0BAA0B,GAC1B,MAAM,MAAM;EACZ;;;;GAIC,GACD,cAAc,MAAM;EACpB,mBAAmB,GACnB,OAAO,YAAY,gBAAgB,WAAW;EAC9C,4BAA4B,GAC5B,WAAW,MAAM;EACjB,gCAAgC,GAChC,YAAY,MAAM;EAClB,mBAAmB,GACnB,iBAAiB,OAAO;EACxB,4BAA4B,GAC5B;IACE,YAAY,OAAO,MAAM,EAAE;;EAE7B,sBAAsB,GACtB,UAAU,MAAM;EAChB,oBAAoB,GACpB,OAAO,MAAM;EACb,2BAA2B,GAC3B,iBAAiB;EACjB,8CAA8C,GAC9C;IACE;MACE,QAAQ;QAAQ,OAAO,MAAM;;MAC7B,eAAe,MAAM;MACrB,gBAAgB,MAAM;MACtB,uBAAuB,MAAM;;;EAGjC,qCAAqC,GACrC;IACE,SAAS,MAAM;IACf,OAAO,MAAM;IACb,MAAM,OAAO,MAAM,EAAE,MAAM;IAC3B;MACE,MAAM,MAAM;MACZ,aAAa;QACX,MAAM,MAAM;QACZ,SAAS,MAAM;QACf,OAAO,MAAM;QACb,MAAM,OAAO,MAAM,EAAE,MAAM;;;IAG/B,iBAAiB,OAAO;;;AAI5B;;CAEC,GACD,iBAAiB;EACf,aAAa;EACb,8BAA8B,GAC9B,MAAM,MAAM;;AAGd;;CAEC,GACD,OAAO,iBAAS,mBAAmB,SAAS,MAAM,GAAG;AA8CrD;;CAEC,GACD,OAAO,iBAAS,iCACd,QAAQ,mBAAmB,GAC1B;AA6BH;;CAEC,GACD,OAAO,iBAAe,sBACpB,UAAU,MAAM,GACf,QAAQ;AAMX;;CAEC,GACD,iBAAiB;EACf,0CAA0C,GAC1C,aAAa;EACb,oEAAoE,GACpE,QAAQ;IAAQ,MAAM,MAAM;IAAE,OAAO,MAAM;;;AAG7C;;;;;;;;CAQC,GACD,OAAO,iBAAe,2BACpB,SAAS,MAAM,EACf;EAAW,YAAY,OAAO;CAAO,GACpC,QAAQ;AAgCX;;CAEC,GACD,OAAO,iBAAe,YAAY,MAAM,MAAM,GAAG,QAAQ,OAAO"}
|