11/**
22 * MCPC Prompt Management System
3- *
3+ *
44 * Centralized management for all prompts and templates used across MCPC.
55 * Supports dynamic content replacement and template variables.
66 */
@@ -25,7 +25,6 @@ export const SystemPrompts = {
25252. **Plan Next Action:** Anticipate the likely next step needed (if any)
2626
2727**⚡ Key Rules:**
28- - Execute ONE action per iteration
2928- Use structured protocol - no direct tool calls
3029- Always analyze results before proceeding` ,
3130
@@ -44,7 +43,7 @@ export const SystemPrompts = {
4443**⚡ SUBSEQUENT CALLS (Execution):**
4544- Provide ONLY current step parameters
4645- **ADVANCE STEP**: Set \`proceed: true\` to move to next step
47- - **RETRY STEP**: Set \`proceed: false\` (or omit) to retry current step
46+ - **RETRY STEP**: Set \`proceed: false\`
4847- Use \`reasoning\` action for thinking/analysis
4948
5049**🚫 Do NOT include \`steps\` parameter during normal execution**
@@ -83,7 +82,7 @@ export const WorkflowPrompts = {
8382 */
8483 WORKFLOW_INIT : `Workflow initialized with {stepCount} steps. You MUST start the workflow with the first step to \`{currentStepDescription}\`.
8584
86- ## EXECUTE tool \`{toolName}\` with following new tool arguments
85+ ## EXECUTE tool \`{toolName}\` with the following new parameter definition
8786
8887{schemaDefinition}
8988
@@ -92,8 +91,9 @@ export const WorkflowPrompts = {
9291- **Do NOT include 'steps' parameter during normal step execution**
9392- **MUST Use the provided JSON schema definition above for parameter generation and validation**
9493- **ADVANCE STEP: Set 'proceed' to true to advance to next step**
95- - **RETRY STEP: Set 'proceed' to false or omit it to re-execute current step**
96- - **⚠️ CRITICAL: When retrying failed steps, NEVER set 'proceed' to true**
94+ - **RETRY STEP: Set 'proceed' to false to re-execute current step**
95+ - **⚠️ CRITICAL: When retrying failed steps, MUST set 'proceed' to false**
96+
9797{workflowSteps}` ,
9898
9999 /**
@@ -112,16 +112,79 @@ export const WorkflowPrompts = {
112112 * Planning instructions for dynamic workflows
113113 */
114114 DYNAMIC_WORKFLOW_PLANNING : `- Set \`init: true\` and define complete \`steps\` array` ,
115+
116+ /**
117+ * Next step decision prompt
118+ */
119+ NEXT_STEP_DECISION : `**Next Step Decision Required**
120+
121+ Previous step completed. Choose your action:
122+
123+ **🔄 RETRY Current Step:**
124+ - Call \`{toolName}\` with current parameters
125+ - ⚠️ CRITICAL: Set \`proceed: false\`
126+
127+ **▶️ PROCEED to Next Step:**
128+ - Call \`{toolName}\` with parameters below
129+ - Set \`proceed: true\`
130+
131+ Next step: \`{nextStepDescription}\`
132+
133+ {nextStepSchema}
134+
135+ **Important:** Exclude \`steps\` key from your parameters` ,
136+
137+ /**
138+ * Final step completion prompt
139+ */
140+ FINAL_STEP_COMPLETION : `**Step Complete - Workflow Ending** {statusIcon}
141+
142+ Current step executed {statusText}. Choose your next action:
143+
144+ **1. ▶️ Complete Workflow:** Call \`{toolName}\` with \`proceed: true\` to finish
145+ **2. 🔄 Retry Final Step:** Call \`{toolName}\` with final step parameters
146+ **3. 🆕 New Workflow:** Call \`{toolName}\` with \`init: true\`{newWorkflowInstructions}
147+
148+ **Note:** Use \`proceed: true\` to officially complete the workflow.` ,
149+
150+ /**
151+ * Workflow completion success message
152+ */
153+ WORKFLOW_COMPLETED : `**Workflow Completed Successfully** ✅
154+
155+ All workflow steps have been executed and the workflow is now complete.
156+
157+ **Summary:**
158+ - Total steps: {totalSteps}
159+ - All steps executed successfully
160+
161+ You can now start a new workflow if needed by calling \`{toolName}\` with \`init: true\`{newWorkflowInstructions}.` ,
162+
163+ /**
164+ * Error messages
165+ */
166+ ERRORS : {
167+ NOT_INITIALIZED : {
168+ WITH_PREDEFINED :
169+ "Error: Workflow not initialized. Please provide 'init' parameter to start a new workflow." ,
170+ WITHOUT_PREDEFINED :
171+ "Error: Workflow not initialized. Please provide 'init' and 'steps' parameter to start a new workflow." ,
172+ } ,
173+ ALREADY_AT_FINAL :
174+ "Error: Cannot proceed, you are already at the final step." ,
175+ NO_STEPS_PROVIDED : "Error: No steps provided" ,
176+ NO_CURRENT_STEP : "Error: No current step to execute" ,
177+ } ,
115178} ;
116179
117180/**
118181 * Response templates for different scenarios
119182 */
120183export const ResponseTemplates = {
121184 /**
122- * Success response for tool execution
185+ * Success response for action execution
123186 */
124- TOOL_SUCCESS : `# You WILL call this tool(\`{toolName}\`) AGAIN using the \`{nextAction}\` action, after evaluating the result from previous action({currentAction}):` ,
187+ ACTION_SUCCESS : `# You WILL call this tool(\`{toolName}\`) AGAIN using the \`{nextAction}\` action, after evaluating the result from previous action({currentAction}):` ,
125188
126189 /**
127190 * Planning prompt when no next action is specified
@@ -131,12 +194,12 @@ export const ResponseTemplates = {
131194 /**
132195 * Error response template
133196 */
134- ERROR_RESPONSE : `Tool /Function argument validation failed: {errorMessage}` ,
197+ ERROR_RESPONSE : `Action /Function argument validation failed: {errorMessage}` ,
135198
136199 /**
137200 * Completion message
138201 */
139- COMPLETION_MESSAGE : `Completed, no dependent tools to execute` ,
202+ COMPLETION_MESSAGE : `Completed, no dependent actions to execute` ,
140203
141204 /**
142205 * Security validation messages
@@ -183,7 +246,10 @@ export const CompiledPrompts = {
183246 toolUsageInstructions : p ( SystemPrompts . TOOL_USAGE_INSTRUCTIONS ) ,
184247 workflowInit : p ( WorkflowPrompts . WORKFLOW_INIT ) ,
185248 workflowToolDescription : p ( WorkflowPrompts . WORKFLOW_TOOL_DESCRIPTION ) ,
186- toolSuccess : p ( ResponseTemplates . TOOL_SUCCESS ) ,
249+ nextStepDecision : p ( WorkflowPrompts . NEXT_STEP_DECISION ) ,
250+ finalStepCompletion : p ( WorkflowPrompts . FINAL_STEP_COMPLETION ) ,
251+ workflowCompleted : p ( WorkflowPrompts . WORKFLOW_COMPLETED ) ,
252+ actionSuccess : p ( ResponseTemplates . ACTION_SUCCESS ) ,
187253 planningPrompt : p ( ResponseTemplates . PLANNING_PROMPT ) ,
188254 errorResponse : p ( ResponseTemplates . ERROR_RESPONSE ) ,
189255 securityPassed : p ( ResponseTemplates . SECURITY_VALIDATION . PASSED ) ,
@@ -199,36 +265,77 @@ export const PromptUtils = {
199265 /**
200266 * Generate tool list for descriptions
201267 */
202- generateToolList : ( tools : Array < { name : string ; description ?: string ; hide ?: boolean } > ) => {
268+ generateToolList : (
269+ tools : Array < { name : string ; description ?: string ; hide ?: boolean } >
270+ ) => {
203271 return tools
204- . filter ( tool => ! tool . hide )
205- . map ( tool => `<tool name="${ tool . name } "${ tool . description ? ` description="${ tool . description } "` : '' } />` )
206- . join ( '\n' ) ;
272+ . filter ( ( tool ) => ! tool . hide )
273+ . map (
274+ ( tool ) =>
275+ `<tool name="${ tool . name } "${
276+ tool . description ? ` description="${ tool . description } "` : ""
277+ } />`
278+ )
279+ . join ( "\n" ) ;
207280 } ,
208281
209282 /**
210283 * Generate hidden tool list for descriptions
211284 */
212285 generateHiddenToolList : ( tools : Array < { name : string ; hide ?: boolean } > ) => {
213286 return tools
214- . filter ( tool => tool . hide )
215- . map ( tool => `<tool name="${ tool . name } " hide/>` )
216- . join ( '\n' ) ;
287+ . filter ( ( tool ) => tool . hide )
288+ . map ( ( tool ) => `<tool name="${ tool . name } " hide/>` )
289+ . join ( "\n" ) ;
217290 } ,
218291
219292 /**
220293 * Format workflow steps for display
221294 */
222- formatWorkflowSteps : ( steps : Array < { description : string ; actions : string [ ] } > ) => {
223- if ( ! steps . length ) return '' ;
295+ formatWorkflowSteps : (
296+ steps : Array < { description : string ; actions : string [ ] } >
297+ ) => {
298+ if ( ! steps . length ) return "" ;
224299 return `## Workflow Steps\n${ JSON . stringify ( steps , null , 2 ) } ` ;
225300 } ,
226301
302+ /**
303+ * Format workflow progress display with status icons
304+ */
305+ formatWorkflowProgress : ( progressData : {
306+ steps : Array < { description : string ; actions : string [ ] } > ;
307+ statuses : Array < string > ;
308+ currentStepIndex : number ;
309+ } ) => {
310+ const statusIcons = {
311+ pending : "⏳" ,
312+ running : "🔄" ,
313+ completed : "✅" ,
314+ failed : "❌" ,
315+ } ;
316+
317+ return progressData . steps
318+ . map ( ( step , index ) => {
319+ const status = progressData . statuses [ index ] || "pending" ;
320+ const icon = statusIcons [ status as keyof typeof statusIcons ] || "⏳" ;
321+ const current =
322+ index === progressData . currentStepIndex ? " **[CURRENT]**" : "" ;
323+ const actions =
324+ step . actions . length > 0
325+ ? ` | Action: ${ step . actions . join ( ", " ) } `
326+ : "" ;
327+ return `${ icon } **Step ${ index + 1 } :** ${
328+ step . description
329+ } ${ actions } ${ current } `;
330+ } )
331+ . join ( "\n" ) ;
332+ } ,
333+
227334 /**
228335 * Generate user info for audit logs
229336 */
230337 formatUserInfo : ( user ?: string ) => {
231- return user ? ` by ${ user } ` : '' ;
338+ return user ? ` by ${ user } ` : "" ;
232339 } ,
233340
234341 /**
@@ -237,6 +344,20 @@ export const PromptUtils = {
237344 formatTimestamp : ( ) => {
238345 return new Date ( ) . toISOString ( ) ;
239346 } ,
347+
348+ /**
349+ * Extract and format text content from CallToolResult
350+ */
351+ extractActionResultText : ( actionResult : {
352+ content ?: Array < { type : string ; text ?: string } > ;
353+ } ) => {
354+ return (
355+ actionResult . content
356+ ?. filter ( ( item ) => item . type === "text" )
357+ ?. map ( ( item ) => item . text )
358+ ?. join ( "\n" ) || "No text content"
359+ ) ;
360+ } ,
240361} ;
241362
242363/**
0 commit comments