update_active_context
Modify the active context file to track ongoing tasks, known issues, and next steps, ensuring centralized and up-to-date information in the MCP server with SSH support.
Instructions
Update the active context file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| issues | No | List of known issues | |
| nextSteps | No | List of next steps | |
| tasks | No | List of ongoing tasks |
Implementation Reference
- src/server/tools/ContextTools.ts:45-75 (handler)Handler function that processes the 'update_active_context' tool call by invoking ProgressTracker.updateActiveContext with the provided context (tasks, issues, nextSteps).export async function handleUpdateActiveContext( progressTracker: ProgressTracker, context: { tasks?: string[]; issues?: string[]; nextSteps?: string[]; } ) { try { await progressTracker.updateActiveContext(context); return { content: [ { type: 'text', text: 'Active context updated successfully', }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error updating active context: ${error}`, }, ], isError: true, }; } }
- src/core/ProgressTracker.ts:233-284 (helper)Core implementation of updateActiveContext method that reads active-context.md, updates or creates markdown sections for ongoing tasks, known issues, and next steps based on input, then writes back to the file.async updateActiveContext(context: { tasks?: string[]; issues?: string[]; nextSteps?: string[]; }): Promise<void> { const contextPath = path.join(this.memoryBankDir, 'active-context.md'); try { let contextContent = await FileUtils.readFile(contextPath); // Update ongoing tasks if (context.tasks && context.tasks.length > 0) { const tasksSection = `## Ongoing Tasks\n\n${context.tasks.map(task => `- ${task}`).join('\n')}\n`; if (/## Ongoing Tasks\s+([^#]*)/s.test(contextContent)) { contextContent = contextContent.replace(/## Ongoing Tasks\s+([^#]*)/s, tasksSection); } else { // If the section doesn't exist, add it contextContent += `\n\n${tasksSection}`; } } // Update known issues if (context.issues && context.issues.length > 0) { const issuesSection = `## Known Issues\n\n${context.issues.map(issue => `- ${issue}`).join('\n')}\n`; if (/## Known Issues\s+([^#]*)/s.test(contextContent)) { contextContent = contextContent.replace(/## Known Issues\s+([^#]*)/s, issuesSection); } else { // If the section doesn't exist, add it contextContent += `\n\n${issuesSection}`; } } // Update next steps if (context.nextSteps && context.nextSteps.length > 0) { const nextStepsSection = `## Next Steps\n\n${context.nextSteps.map(step => `- ${step}`).join('\n')}\n`; if (/## Next Steps\s+([^#]*)/s.test(contextContent)) { contextContent = contextContent.replace(/## Next Steps\s+([^#]*)/s, nextStepsSection); } else { // If the section doesn't exist, add it contextContent += `\n\n${nextStepsSection}`; } } await FileUtils.writeFile(contextPath, contextContent); } catch (error) { console.error(`Error updating active context: ${error}`); throw new Error(`Failed to update active context: ${error}`); } }
- Tool schema definition in contextTools array, specifying name 'update_active_context', description, and inputSchema for arrays of tasks, issues, nextSteps.{ name: 'update_active_context', description: 'Update the active context file', inputSchema: { type: 'object', properties: { tasks: { type: 'array', items: { type: 'string', }, description: 'List of ongoing tasks', }, issues: { type: 'array', items: { type: 'string', }, description: 'List of known issues', }, nextSteps: { type: 'array', items: { type: 'string', }, description: 'List of next steps', }, }, }, },
- src/server/tools/index.ts:192-213 (registration)Registration and dispatching logic in the main CallToolRequestSchema handler: switch case for 'update_active_context' that extracts arguments and calls handleUpdateActiveContext.// Context tools case 'update_active_context': { const progressTracker = getProgressTracker(); if (!progressTracker) { return { content: [ { type: 'text', text: 'Memory Bank not found. Use initialize_memory_bank to create one.', }, ], isError: true, }; } const { tasks, issues, nextSteps } = request.params.arguments as { tasks?: string[]; issues?: string[]; nextSteps?: string[]; }; return handleUpdateActiveContext(progressTracker, { tasks, issues, nextSteps }); }
- src/server/tools/index.ts:29-38 (registration)Tool list registration: includes ...contextTools in the tools array returned by ListToolsRequestSchema handler, making the tool discoverable by MCP clients.// Register tools for listing server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ ...coreTools, ...progressTools, ...contextTools, ...decisionTools, ...modeTools, ], }));