Skip to main content
Glama

expand_memory

Retrieve and expand stored content from tiered responses using expandable IDs to access detailed architectural decision records and related context.

Instructions

Phase 3: Retrieve and expand stored content from a tiered response using its expandable ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
expandableIdYesExpandable ID from a tiered response
sectionNoOptional: specific section to expand
includeContextNoInclude related conversation context and knowledge graph state

Implementation Reference

  • The core handler function for the 'expand_memory' tool. Retrieves full analysis content from a tiered response expandable ID using ConversationMemoryManager, formats it with metadata, related turns, and knowledge graph context.
    export async function expandMemory(
      args: {
        expandableId: string;
        section?: string;
        includeContext?: boolean;
      },
      memoryManager: ConversationMemoryManager
    ): Promise<CallToolResult> {
      try {
        const request: MemoryExpansionRequest = {
          expandableId: args.expandableId,
          ...(args.section ? { section: args.section } : {}),
          includeContext: args.includeContext ?? true,
        };
    
        const result = await memoryManager.expandContent(request);
    
        // Format the expanded content
        let output = `# Expanded Content: ${args.expandableId}\n\n`;
    
        // Show section or full content
        if (args.section && result.content.sections[args.section]) {
          output += `## Section: ${args.section}\n\n`;
          output += result.content.sections[args.section];
        } else {
          output += `## Full Analysis\n\n`;
          output += result.content.content;
        }
    
        // Add metadata
        output += `\n\n---\n\n`;
        output += `**Tool**: ${result.content.metadata.toolName}\n`;
        output += `**Timestamp**: ${result.content.metadata.timestamp}\n`;
        output += `**Token Count**: ${result.content.metadata.tokenCount}\n`;
    
        // Add related turns if included
        if (result.relatedTurns && result.relatedTurns.length > 0) {
          output += `\n## Related Conversation Turns\n\n`;
          result.relatedTurns.forEach(turn => {
            output += `- **Turn ${turn.turnNumber}** (${turn.timestamp}): `;
            output += `${turn.request.toolName || 'message'}\n`;
          });
        }
    
        // Add knowledge graph context if included
        if (result.knowledgeGraphContext && result.knowledgeGraphContext.length > 0) {
          output += `\n## Knowledge Graph Context\n\n`;
          result.knowledgeGraphContext.forEach(context => {
            output += `- **${context.intent}**: ${context.outcome} (${context.timestamp})\n`;
          });
        }
    
        return {
          content: [
            {
              type: 'text',
              text: output,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `❌ Failed to expand content: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Type definition for MemoryExpansionRequest, which defines the input parameters for the expandMemory handler (expandableId, section, includeContext).
    export interface MemoryExpansionRequest {
      /** Expandable ID from tiered response */
      expandableId: string;
    
      /** Optional: specific section to expand */
      section?: string;
  • Metadata and approximate schema registration for the 'expand_memory' tool in the central tool catalog used for discovery and ListTools responses.
    TOOL_CATALOG.set('expand_memory', {
      name: 'expand_memory',
      shortDescription: 'Expand memory with new context',
      fullDescription: 'Expands memory with additional context information.',
      category: 'memory',
      complexity: 'simple',
      tokenCost: { min: 300, max: 800 },
      hasCEMCPDirective: true, // Phase 4.3: Simple tool - memory storage
      relatedTools: ['memory_loading', 'get_memory_stats'],
      keywords: ['memory', 'expand', 'add', 'context'],
      requiresAI: false,
      inputSchema: {
        type: 'object',
        properties: {
          key: { type: 'string' },
          value: { type: 'object' },
        },
        required: ['key', 'value'],
      },
    });
  • Function signature and dependencies showing integration with ConversationMemoryManager.
    export async function expandMemory(
      args: {
        expandableId: string;
        section?: string;
        includeContext?: boolean;
      },
      memoryManager: ConversationMemoryManager
    ): Promise<CallToolResult> {
      try {
        const request: MemoryExpansionRequest = {
          expandableId: args.expandableId,
          ...(args.section ? { section: args.section } : {}),
          includeContext: args.includeContext ?? true,
        };
    
        const result = await memoryManager.expandContent(request);
    
        // Format the expanded content
        let output = `# Expanded Content: ${args.expandableId}\n\n`;
    
        // Show section or full content
        if (args.section && result.content.sections[args.section]) {
          output += `## Section: ${args.section}\n\n`;
          output += result.content.sections[args.section];
        } else {
          output += `## Full Analysis\n\n`;
          output += result.content.content;
        }
    
        // Add metadata
        output += `\n\n---\n\n`;
        output += `**Tool**: ${result.content.metadata.toolName}\n`;
        output += `**Timestamp**: ${result.content.metadata.timestamp}\n`;
        output += `**Token Count**: ${result.content.metadata.tokenCount}\n`;
    
        // Add related turns if included
        if (result.relatedTurns && result.relatedTurns.length > 0) {
          output += `\n## Related Conversation Turns\n\n`;
          result.relatedTurns.forEach(turn => {
            output += `- **Turn ${turn.turnNumber}** (${turn.timestamp}): `;
            output += `${turn.request.toolName || 'message'}\n`;
          });
        }
    
        // Add knowledge graph context if included
        if (result.knowledgeGraphContext && result.knowledgeGraphContext.length > 0) {
          output += `\n## Knowledge Graph Context\n\n`;
          result.knowledgeGraphContext.forEach(context => {
            output += `- **${context.intent}**: ${context.outcome} (${context.timestamp})\n`;
          });
        }
    
        return {
          content: [
            {
              type: 'text',
              text: output,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `❌ Failed to expand content: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Reference listing of the tool in server context generator with accurate description matching handler purpose.
    {
      name: 'expand_memory',
      description: 'Retrieve and expand stored content from tiered responses',
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions retrieving and expanding content but does not specify what 'expand' entails (e.g., whether it modifies data, requires permissions, or has rate limits). The phrase 'Phase 3' hints at a workflow context but lacks details on side effects or response format, leaving significant gaps in transparency.

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 a single sentence that is front-loaded with the core action, making it efficient. However, the phrase 'Phase 3' adds unnecessary jargon without clarification, slightly reducing clarity. Overall, it is concise with minimal waste.

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

Completeness2/5

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

Given the complexity implied by 'tiered response' and 'Phase 3,' no annotations, and no output schema, the description is incomplete. It fails to explain what the tool returns, how expansion works, or the workflow context, making it inadequate for an AI agent to use effectively without additional context.

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%, so the schema already documents all parameters (expandableId, section, includeContext). The description does not add meaning beyond the schema, as it only references 'expandable ID' without explaining its format or origin. With high schema coverage, the baseline score of 3 is appropriate.

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 states the tool 'retrieve[s] and expand[s] stored content from a tiered response using its expandable ID,' which provides a verb ('retrieve and expand') and resource ('stored content from a tiered response'). However, it is vague about what 'tiered response' means and does not clearly differentiate from sibling tools like 'expand_analysis_section' or 'memory_loading,' leaving ambiguity in its specific role.

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?

The description mentions 'Phase 3' and 'expandable ID from a tiered response,' implying usage in a sequential workflow, but it does not provide explicit guidance on when to use this tool versus alternatives (e.g., 'expand_analysis_section' or 'memory_loading'). No exclusions or prerequisites are stated, offering minimal practical direction.

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/tosin2013/mcp-adr-analysis-server'

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