Skip to main content
Glama

auto_save_context

Automatically saves and compresses AI session context for backup, including progress, decisions, and code snippets, to preserve work and enable recovery.

Instructions

commit|checkpoint|backup|compress|auto-save - Auto-save and compress context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urgencyYesUrgency level
contextTypeYesType of context to save
sessionIdNoCurrent session identifier
summaryNoBrief summary of current context
fullContextNoFull context to compress and save
compressNoEnable smart compression (default: true)

Implementation Reference

  • The primary handler function that executes the auto_save_context tool. It compresses context if provided, saves it to MemoryManager with priority based on urgency, and returns a success message with compression stats if applicable.
    export async function autoSaveContext(args: {
      urgency: string;
      contextType: string;
      sessionId?: string;
      summary?: string;
      fullContext?: string;
      compress?: boolean;
    }): Promise<ToolResult> {
      const { urgency, contextType, sessionId, summary, fullContext, compress = true } = args;
    
      try {
        const memoryManager = MemoryManager.getInstance();
    
        let contextToSave = summary || '';
        let compressionStats = null;
    
        // Apply smart compression if full context provided and compression enabled
        if (fullContext && compress) {
          const targetTokens = urgency === 'critical' ? 8000 : urgency === 'high' ? 7000 : 4000;
          const compressionResult = ContextCompressor.compress(fullContext, targetTokens);
    
          contextToSave = compressionResult.compressed;
          compressionStats = {
            originalTokens: ContextCompressor.estimateTokens(fullContext),
            compressedTokens: ContextCompressor.estimateTokens(compressionResult.compressed),
            ratio: Math.round(compressionResult.compressionRatio * 100),
            removed: compressionResult.removedSections.length
          };
        } else if (fullContext) {
          contextToSave = fullContext;
        }
    
        const contextData = {
          timestamp: new Date().toISOString(),
          urgency,
          contextType,
          sessionId,
          summary,
          context: contextToSave,
          compressed: compress && !!fullContext,
          compressionStats
        };
    
        const priority = urgency === 'high' || urgency === 'critical' ? 2 : urgency === 'medium' ? 1 : 0;
        const contextKey = sessionId ? `context:session_${sessionId}_${Date.now()}` : `context:${Date.now()}`;
    
        memoryManager.save(contextKey, JSON.stringify(contextData), 'context', priority);
    
        let resultText = `✓ Context saved: ${contextType} (${urgency})`;
        if (sessionId) resultText += `\nSession: ${sessionId}`;
        if (compressionStats) {
          resultText += `\nCompressed: ${compressionStats.originalTokens} → ${compressionStats.compressedTokens} tokens (${compressionStats.ratio}%)`;
          resultText += `\nRemoved: ${compressionStats.removed} low-priority sections`;
        }
        if (summary) resultText += `\n${summary}`;
    
        return {
          content: [{
            type: 'text',
            text: resultText
          }]
        };
      } catch (error) {
        return {
          content: [{ type: 'text', text: `✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}` }]
        };
      }
    }
  • Defines the tool schema including name, description, inputSchema for parameters like urgency and contextType, and annotations.
    export const autoSaveContextDefinition: ToolDefinition = {
      name: 'auto_save_context',
      description: 'commit|checkpoint|backup|compress|auto-save - Auto-save and compress context',
      inputSchema: {
        type: 'object',
        properties: {
          urgency: { type: 'string', description: 'Urgency level', enum: ['low', 'medium', 'high', 'critical'] },
          contextType: { type: 'string', description: 'Type of context to save', enum: ['progress', 'decisions', 'code-snippets', 'debugging', 'planning'] },
          sessionId: { type: 'string', description: 'Current session identifier' },
          summary: { type: 'string', description: 'Brief summary of current context' },
          fullContext: { type: 'string', description: 'Full context to compress and save' },
          compress: { type: 'boolean', description: 'Enable smart compression (default: true)' }
        },
        required: ['urgency', 'contextType']
      },
      annotations: {
        title: 'Auto-Save Context',
        audience: ['user', 'assistant']
      }
    };
  • src/index.ts:104-160 (registration)
    Registers the autoSaveContextDefinition in the comprehensive tools array provided to the MCP server's listTools handler for tool discovery.
    const tools: ToolDefinition[] = [
      // Time Utility Tools
      getCurrentTimeDefinition,
    
      // Semantic Code Analysis Tools (Serena-inspired)
      findSymbolDefinition,
      findReferencesDefinition,
    
      // Sequential Thinking Tools
      createThinkingChainDefinition,
      analyzeProblemDefinition,
      stepByStepAnalysisDefinition,
      breakDownProblemDefinition,
      thinkAloudProcessDefinition,
      formatAsPlanDefinition,
    
      // Browser Development Tools
      monitorConsoleLogsDefinition,
      inspectNetworkRequestsDefinition,
    
      // Memory Management Tools
      saveMemoryDefinition,
      recallMemoryDefinition,
      listMemoriesDefinition,
      deleteMemoryDefinition,
      searchMemoriesDefinition,
      updateMemoryDefinition,
      autoSaveContextDefinition,
      restoreSessionContextDefinition,
      prioritizeMemoryDefinition,
      startSessionDefinition,
    
      // Convention Tools
      getCodingGuideDefinition,
      applyQualityRulesDefinition,
      validateCodeQualityDefinition,
      analyzeComplexityDefinition,
      checkCouplingCohesionDefinition,
      suggestImprovementsDefinition,
    
      // Planning Tools
      generatePrdDefinition,
      createUserStoriesDefinition,
      analyzeRequirementsDefinition,
      featureRoadmapDefinition,
    
      // Prompt Enhancement Tools
      enhancePromptDefinition,
      analyzePromptDefinition,
      enhancePromptGeminiDefinition,
    
      // Reasoning Tools
      applyReasoningFrameworkDefinition,
    
      // UI Preview Tools
      previewUiAsciiDefinition
    ];
  • src/index.ts:648-649 (registration)
    Registers the handler dispatch in the central executeToolCall switch statement within the CallToolRequestSchema handler.
    case 'auto_save_context':
      return await autoSaveContext(args as any) as CallToolResult;
  • src/index.ts:59-59 (registration)
    Imports the handler function and tool definition from the implementation file.
    import { autoSaveContext, autoSaveContextDefinition } from './tools/memory/autoSaveContext.js';
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only provide a title ('Auto-Save Context'), so the description carries the burden of behavioral disclosure. It mentions 'auto-save and compress', hinting at automation and data reduction, but lacks details on how compression works, what gets saved (e.g., overwrites, appends), authentication needs, rate limits, or side effects. No contradiction with annotations exists, but it adds minimal context beyond the basic operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise with a single phrase listing synonyms and the core action. It's front-loaded with key terms, but the synonym list ('commit|checkpoint|backup|compress|auto-save') is somewhat redundant and could be streamlined. Overall, it's efficient with minimal waste, though slightly cluttered.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, no output schema, minimal annotations), the description is incomplete. It covers the basic purpose but lacks details on behavior, output format, or integration with sibling tools. Without an output schema, the description should ideally hint at return values, but it doesn't. It's minimally adequate but leaves significant gaps for an agent to understand full usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with all parameters well-documented in the schema (e.g., urgency levels, context types). The description doesn't add any meaning beyond the schema, such as explaining parameter interactions or use cases. With high schema coverage, the baseline score is 3, as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description lists synonyms (commit, checkpoint, backup, compress, auto-save) and states 'Auto-save and compress context', which gives a vague purpose of saving and compressing context. However, it doesn't specify what 'context' refers to (e.g., conversation state, memory, session data) or distinguish it from sibling tools like 'save_memory' or 'restore_session_context', leaving ambiguity about the exact resource and operation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives is provided. The description doesn't mention when it's appropriate (e.g., during long conversations, before breaks) or when not to use it, nor does it reference sibling tools like 'save_memory' or 'restore_session_context' for comparison. Usage is implied by the name and description but not clearly defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/ssdeanx/ssd-ai'

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