Skip to main content
Glama
setContext.ts2.56 kB
/** * Set Context Tool - Session-level project binding * THE MOST IMPORTANT COMMAND - Solves context drift! */ import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; 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: unknown): Promise<CallToolResult> { 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 as any)?.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!` } ] }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/romiluz13/memory-engineering-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server