UNPKG

mcp-sequentialthinking-qa

Version:

A QA-focused adaptation of the MCP Sequential Thinking Server to guide tool usage in verification processes

223 lines (222 loc) 8.03 kB
/** * Process a syntax validation workflow * This workflow helps verify code syntax and patterns against best practices */ export function process_syntax_validation(params) { // Handle different steps based on thought number switch (params.thought_number) { case 1: return handle_initial_code_analysis(params); case 2: return handle_best_practices_check(params); case 3: return handle_syntax_correction(params); case 4: return handle_validation(params); default: return handle_generic_step(params); } } /** * Initial step: Analyze code syntax */ function handle_initial_code_analysis(params) { return { ...params, current_step: { step_description: 'Analyze code syntax and structure', expected_outcome: 'Identified syntax patterns and potential issues', recommended_tools: [ { tool_name: 'read_file', confidence: 0.9, rationale: 'Examine code files to understand syntax', priority: 1, }, { tool_name: 'execute_command', confidence: 0.8, rationale: 'Run linter or syntax checker', priority: 2, }, ], next_step_conditions: [ 'Code structure understood', 'Potential syntax issues identified', ], }, next_thought_needed: true, }; } /** * Second step: Check best practices and documentation */ function handle_best_practices_check(params) { // Simple condition to trigger branching for demonstration if (params.thought_number === 2 && !params.branch_from_thought) { const branch_id = `alternative-syntax-${Date.now()}`; // Generate a unique branch ID return { ...params, thought: 'Multiple valid syntax patterns found (simulated). Branching to explore an alternative.', branch_from_thought: params.thought_number, branch_id: branch_id, next_thought_needed: true, // Update current_step to reflect the branching task current_step: { step_description: 'Explore an alternative syntax pattern.', expected_outcome: 'Understanding of an alternative pattern.', recommended_tools: [ // Recommend tools for exploring alternative patterns { tool_name: 'use_mcp_tool', confidence: 0.9, rationale: 'Search for details on the alternative pattern', priority: 1, alternatives: [ 'mcp-omnisearch:brave_search', 'mcp-omnisearch:kagi_search', ], }, { tool_name: 'read_file', confidence: 0.8, rationale: 'Examine code examples', priority: 2, }, ], next_step_conditions: [ 'Alternative pattern understood', 'Ready to compare or implement', ], }, }; } return { ...params, current_step: { step_description: 'Research best practices and official syntax guidelines', expected_outcome: 'Understanding of correct syntax patterns', recommended_tools: [ { tool_name: 'use_mcp_tool', confidence: 0.9, rationale: 'Search for official documentation and best practices using an MCP search tool', priority: 1, alternatives: [ 'mcp-omnisearch:brave_search', 'mcp-omnisearch:kagi_search', ], suggested_inputs: { server_name: 'mcp-omnisearch', tool_name: 'brave_search', arguments: { query: 'code syntax best practices' }, }, }, { tool_name: 'browser_navigate', confidence: 0.8, rationale: 'Navigate to relevant documentation sites', priority: 2, }, { tool_name: 'browser_action', confidence: 0.7, rationale: 'Browse documentation sites for detailed syntax information', priority: 3, }, ], next_step_conditions: [ 'Best practices identified', 'Correct syntax patterns understood', ], }, next_thought_needed: true, }; } /** * Third step: Correct syntax issues */ function handle_syntax_correction(params) { return { ...params, current_step: { step_description: 'Implement syntax corrections based on best practices', expected_outcome: 'Corrected code syntax', recommended_tools: [ { tool_name: 'replace_in_file', confidence: 0.9, rationale: 'Make targeted syntax corrections', priority: 1, }, { tool_name: 'write_to_file', confidence: 0.7, rationale: 'Create new files with correct syntax if needed', priority: 2, }, ], next_step_conditions: [ 'Syntax corrections implemented', 'Ready for validation', ], }, next_thought_needed: true, }; } /** * Fourth step: Validate the syntax corrections */ function handle_validation(params) { return { ...params, current_step: { step_description: 'Validate syntax corrections', expected_outcome: 'Confirmed working code with correct syntax', recommended_tools: [ { tool_name: 'execute_command', confidence: 0.9, rationale: 'Run linter, tests, or build process to verify syntax', priority: 1, }, { tool_name: 'read_file', confidence: 0.7, rationale: 'Review corrected files to ensure syntax is correct', priority: 2, }, ], next_step_conditions: [], }, next_thought_needed: false, }; } /** * Generic step for any additional steps beyond the standard workflow */ function handle_generic_step(params) { return { ...params, current_step: { step_description: `Additional syntax validation step ${params.thought_number}`, expected_outcome: 'Further verification of syntax correctness', recommended_tools: [ { tool_name: 'execute_command', confidence: 0.8, rationale: 'Run additional verification commands', priority: 1, }, { tool_name: 'read_file', confidence: 0.7, rationale: 'Examine additional files for syntax correctness', priority: 2, }, ], next_step_conditions: ['Additional verification complete'], }, next_thought_needed: params.thought_number < params.total_thoughts, }; }