memory-engineering-mcp
Version:
š§ AI Memory System powered by MongoDB Atlas & Voyage AI - Autonomous memory management with zero manual work
80 lines (71 loc) ⢠2.62 kB
JavaScript
/**
* Set Context Tool - Session-level project binding
* THE MOST IMPORTANT COMMAND - Solves context drift!
*/
import { z } from 'zod';
import { setActiveProject, getContextHeader } from '../utils/sessionContext.js';
import { getSyncRecommendations } from '../utils/frameworkDetection.js';
import { logger } from '../utils/logger.js';
const SetContextSchema = z.object({
projectPath: z.string().describe('Path to the project directory'),
projectName: z.string().optional().describe('Optional project name')
});
export async function setContextTool(args) {
try {
const params = SetContextSchema.parse(args);
logger.info('šÆ SETTING PROJECT CONTEXT', params);
// Set the active project
const context = setActiveProject(params.projectPath, params.projectName);
if (!context.activeProject) {
throw new Error('\ud83d\udc80 CONTEXT SETTING FAILED! Unable to establish project binding!');
}
// Build success response
let response = getContextHeader();
response += `
ā
PROJECT CONTEXT ACTIVATED!
This project is now your active context for ALL commands.
All memory operations will use this project automatically.
${getSyncRecommendations(context.activeProject.framework)}
š Next Steps:
1. Check project status: memory_engineering_status
2. Initialize memories: memory_engineering_init --with-sync
3. Start working: Your context is saved!
š” Pro Tips:
⢠This context persists across sessions
⢠Switch projects anytime with set_context
⢠View all projects with status --all
š„ Your AI now knows EXACTLY where to work!`;
return {
content: [
{
type: 'text',
text: response
}
]
};
}
catch (error) {
logger.error('š SET CONTEXT FAILED!', error);
return {
isError: true,
content: [
{
type: 'text',
text: `š CONTEXT SETTING CATASTROPHE!
${error instanceof Error ? error.message : 'Unknown error'}
š TROUBLESHOOTING:
1. Check path exists: ls "${args?.projectPath || 'path/not/provided'}"
2. Use absolute paths: /Users/you/project
3. Or use current dir: memory_engineering_set_context --projectPath "."
š Common Paths:
⢠Current directory: "."
⢠Parent directory: ".."
⢠Home directory: "~"
⢠Absolute: "/Users/username/Dev/project"
š„ CANNOT PROCEED WITHOUT VALID PROJECT CONTEXT!`
}
]
};
}
}
//# sourceMappingURL=setContext.js.map