Skip to main content
Glama

get_session_context

Read-onlyIdempotent

Retrieve previous session context including memory, knowledge graphs, and recent work history to quickly understand project status when starting new conversations.

Instructions

πŸš€ [μƒˆ λŒ€ν™”/μ„Έμ…˜ μ‹œμž‘ μ‹œ μžλ™ μ‹€ν–‰ ꢌμž₯] 이전 μ„Έμ…˜μ˜ λ©”λͺ¨λ¦¬, 지식 κ·Έλž˜ν”„, 졜근 μž‘μ—… 내역을 ν•œ λ²ˆμ— μ‘°νšŒν•©λ‹ˆλ‹€.

이 λ„κ΅¬λŠ” μƒˆλ‘œμš΄ λŒ€ν™”λ₯Ό μ‹œμž‘ν•  λ•Œ κ°€μž₯ λ¨Όμ € μ‹€ν–‰ν•˜λ©΄ μ’‹μŠ΅λ‹ˆλ‹€. ν”„λ‘œμ νŠΈμ˜ μ»¨ν…μŠ€νŠΈλ₯Ό λΉ λ₯΄κ²Œ νŒŒμ•…ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

ν‚€μ›Œλ“œ: μ„Έμ…˜ μ‹œμž‘, μ»¨ν…μŠ€νŠΈ, 이전 μž‘μ—…, session start, context, previous work, what did we do

μ‚¬μš© μ˜ˆμ‹œ:

  • "이전에 무슨 μž‘μ—… ν–ˆμ—ˆμ§€?"

  • "ν”„λ‘œμ νŠΈ μ»¨ν…μŠ€νŠΈ μ•Œλ €μ€˜"

  • "μ„Έμ…˜ μ»¨ν…μŠ€νŠΈ 쑰회"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNameNoν”„λ‘œμ νŠΈλͺ…μœΌλ‘œ 필터링 (선택)
categoryNoμΉ΄ν…Œκ³ λ¦¬λ‘œ 필터링 (선택)
memoryLimitNoμ‘°νšŒν•  λ©”λͺ¨λ¦¬ 수 (κΈ°λ³Έκ°’: 15)
includeGraphNo지식 κ·Έλž˜ν”„ 포함 μ—¬λΆ€ (κΈ°λ³Έκ°’: true)
includeTimelineNoνƒ€μž„λΌμΈ 포함 μ—¬λΆ€ (κΈ°λ³Έκ°’: true)
timeRangeNoνƒ€μž„λΌμΈ 쑰회 λ²”μœ„7d

Implementation Reference

  • Main handler function that fetches and formats session context including memory stats, recent memories, knowledge graph summary, and recent timeline using MemoryManager. Handles optional filters like projectName, category, limits.
    export async function getSessionContext(args: GetSessionContextArgs): Promise<ToolResult> {
      try {
        const {
          projectName,
          category,
          memoryLimit = 15,
          includeGraph = true,
          includeTimeline = true,
          timeRange = '7d'
        } = args;
    
        const memoryManager = MemoryManager.getInstance();
        const sections: string[] = [];
    
        // Header
        sections.push('# 🧠 μ„Έμ…˜ μ»¨ν…μŠ€νŠΈ\n');
        sections.push(`> 이전 μ„Έμ…˜μ˜ λ©”λͺ¨λ¦¬μ™€ μž‘μ—… λ‚΄μ—­μž…λ‹ˆλ‹€.\n`);
    
        // 1. Memory Statistics
        const stats = memoryManager.getStats();
        sections.push('## πŸ“Š λ©”λͺ¨λ¦¬ 톡계\n');
        sections.push(`- **총 λ©”λͺ¨λ¦¬**: ${stats.total}개`);
    
        const categoryStats = Object.entries(stats.byCategory)
          .sort((a, b) => b[1] - a[1])
          .slice(0, 5)
          .map(([cat, count]) => `${cat}: ${count}`)
          .join(', ');
        sections.push(`- **μΉ΄ν…Œκ³ λ¦¬**: ${categoryStats || 'μ—†μŒ'}\n`);
    
        // 2. Recent Memories (Priority-sorted)
        sections.push('## πŸ“ μ£Όμš” λ©”λͺ¨λ¦¬\n');
    
        let memories = memoryManager.list(category);
    
        // Filter by project name if specified
        if (projectName) {
          memories = memories.filter(m =>
            m.key.toLowerCase().includes(projectName.toLowerCase()) ||
            m.value.toLowerCase().includes(projectName.toLowerCase()) ||
            m.category.toLowerCase().includes(projectName.toLowerCase())
          );
        }
    
        // Sort by priority (desc) then timestamp (desc)
        memories.sort((a, b) => {
          const priorityDiff = (b.priority || 0) - (a.priority || 0);
          if (priorityDiff !== 0) return priorityDiff;
          return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();
        });
    
        const topMemories = memories.slice(0, memoryLimit);
    
        if (topMemories.length === 0) {
          sections.push('_μ €μž₯된 λ©”λͺ¨λ¦¬κ°€ μ—†μŠ΅λ‹ˆλ‹€._\n');
        } else {
          for (const memory of topMemories) {
            const priority = memory.priority ? `⭐${memory.priority}` : '';
            const preview = memory.value.length > 120
              ? memory.value.substring(0, 120) + '...'
              : memory.value;
            const date = formatDate(memory.timestamp);
    
            sections.push(`### ${memory.key} ${priority}`);
            sections.push(`**[${memory.category}]** | ${date}`);
            sections.push(`> ${preview}\n`);
          }
        }
    
        // 3. Knowledge Graph (if enabled and has relations)
        if (includeGraph && memories.length > 0) {
          const graph = memoryManager.getMemoryGraph(undefined, 2);
    
          if (graph.edges.length > 0) {
            sections.push('## πŸ”— 지식 κ·Έλž˜ν”„\n');
    
            // Show key relationships
            const relationSummary = summarizeRelations(graph.edges);
            sections.push(relationSummary);
    
            // Show clusters
            if (graph.clusters.length > 0) {
              sections.push('\n**κ΄€λ ¨ κ·Έλ£Ή**:');
              for (const cluster of graph.clusters.slice(0, 3)) {
                sections.push(`- [${cluster.join(' ↔ ')}]`);
              }
            }
            sections.push('');
          }
        }
    
        // 4. Recent Timeline (if enabled)
        if (includeTimeline) {
          sections.push('## πŸ“… 졜근 νƒ€μž„λΌμΈ\n');
    
          const startDate = getStartDate(timeRange);
          const timeline = memoryManager.getTimeline(startDate, undefined, 10);
    
          if (timeline.length === 0) {
            sections.push('_졜근 ν™œλ™μ΄ μ—†μŠ΅λ‹ˆλ‹€._\n');
          } else {
            const groupedByDate = groupByDate(timeline);
    
            for (const [date, items] of Object.entries(groupedByDate).slice(0, 5)) {
              sections.push(`**${date}**`);
              for (const item of (items as any[]).slice(0, 3)) {
                sections.push(`- \`${item.key}\`: ${item.value.substring(0, 50)}${item.value.length > 50 ? '...' : ''}`);
              }
            }
            sections.push('');
          }
        }
    
        // 5. Quick Actions Hint
        sections.push('---');
        sections.push('## πŸ’‘ λ‹€μŒ 단계\n');
        sections.push('- νŠΉμ • λ©”λͺ¨λ¦¬ 상세 쑰회: `recall_memory`');
        sections.push('- μƒˆ λ©”λͺ¨λ¦¬ μ €μž₯: `save_memory`');
        sections.push('- κ·Έλž˜ν”„ 탐색: `get_memory_graph`');
        sections.push('- κ³ κΈ‰ 검색: `search_memories_advanced`');
    
        return {
          content: [{
            type: 'text',
            text: sections.join('\n')
          }]
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `βœ— μ„Έμ…˜ μ»¨ν…μŠ€νŠΈ 쑰회 였λ₯˜: ${error instanceof Error ? error.message : 'μ•Œ 수 μ—†λŠ” 였λ₯˜'}`
          }]
        };
      }
    }
  • ToolDefinition object defining the input schema, description, and annotations for the get_session_context tool.
    export const getSessionContextDefinition: ToolDefinition = {
      name: 'get_session_context',
      description: `πŸš€ [μƒˆ λŒ€ν™”/μ„Έμ…˜ μ‹œμž‘ μ‹œ μžλ™ μ‹€ν–‰ ꢌμž₯] 이전 μ„Έμ…˜μ˜ λ©”λͺ¨λ¦¬, 지식 κ·Έλž˜ν”„, 졜근 μž‘μ—… 내역을 ν•œ λ²ˆμ— μ‘°νšŒν•©λ‹ˆλ‹€.
    
    이 λ„κ΅¬λŠ” μƒˆλ‘œμš΄ λŒ€ν™”λ₯Ό μ‹œμž‘ν•  λ•Œ κ°€μž₯ λ¨Όμ € μ‹€ν–‰ν•˜λ©΄ μ’‹μŠ΅λ‹ˆλ‹€. ν”„λ‘œμ νŠΈμ˜ μ»¨ν…μŠ€νŠΈλ₯Ό λΉ λ₯΄κ²Œ νŒŒμ•…ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
    
    ν‚€μ›Œλ“œ: μ„Έμ…˜ μ‹œμž‘, μ»¨ν…μŠ€νŠΈ, 이전 μž‘μ—…, session start, context, previous work, what did we do
    
    μ‚¬μš© μ˜ˆμ‹œ:
    - "이전에 무슨 μž‘μ—… ν–ˆμ—ˆμ§€?"
    - "ν”„λ‘œμ νŠΈ μ»¨ν…μŠ€νŠΈ μ•Œλ €μ€˜"
    - "μ„Έμ…˜ μ»¨ν…μŠ€νŠΈ 쑰회"`,
      inputSchema: {
        type: 'object',
        properties: {
          projectName: {
            type: 'string',
            description: 'ν”„λ‘œμ νŠΈλͺ…μœΌλ‘œ 필터링 (선택)'
          },
          category: {
            type: 'string',
            description: 'μΉ΄ν…Œκ³ λ¦¬λ‘œ 필터링 (선택)'
          },
          memoryLimit: {
            type: 'number',
            description: 'μ‘°νšŒν•  λ©”λͺ¨λ¦¬ 수 (κΈ°λ³Έκ°’: 15)',
            default: 15
          },
          includeGraph: {
            type: 'boolean',
            description: '지식 κ·Έλž˜ν”„ 포함 μ—¬λΆ€ (κΈ°λ³Έκ°’: true)',
            default: true
          },
          includeTimeline: {
            type: 'boolean',
            description: 'νƒ€μž„λΌμΈ 포함 μ—¬λΆ€ (κΈ°λ³Έκ°’: true)',
            default: true
          },
          timeRange: {
            type: 'string',
            description: 'νƒ€μž„λΌμΈ 쑰회 λ²”μœ„',
            enum: ['1d', '7d', '30d', 'all'],
            default: '7d'
          }
        }
      },
      annotations: {
        title: 'Get Session Context',
        audience: ['user', 'assistant'],
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false
      }
    };
  • src/index.ts:175-175 (registration)
    Registration of the tool handler in the toolHandlers map for dynamic dispatch during tool execution.
    'get_session_context': getSessionContext,
  • src/index.ts:108-108 (registration)
    Registration of the tool definition in the tools array provided to ListToolsRequestHandler.
    getSessionContextDefinition,
  • src/index.ts:56-56 (registration)
    Import statement bringing in the handler and definition from the implementation file.
    import { getSessionContextDefinition, getSessionContext } from './tools/memory/getSessionContext.js';
Behavior4/5

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

Annotations already provide readOnlyHint=true, destructiveHint=false, idempotentHint=true, and openWorldHint=false. The description adds valuable context: it's 'μžλ™ μ‹€ν–‰ ꢌμž₯' (recommended for automatic execution) at session start, which helps the agent understand timing and importance. However, it doesn't mention rate limits, authentication needs, or specific error behaviors beyond what annotations cover.

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 well-structured with purpose, usage recommendation, keywords, and examples. However, the keyword section ('ν‚€μ›Œλ“œ: μ„Έμ…˜ μ‹œμž‘...') and examples could be slightly trimmed as they partially repeat the main points. Most sentences earn their place by reinforcing when and how to use the tool.

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

Completeness4/5

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

For a read-only, idempotent tool with no output schema, the description provides good context: purpose, timing, and examples. It covers the 'why' and 'when' well. However, it doesn't describe the return format (what 'λ©”λͺ¨λ¦¬, 지식 κ·Έλž˜ν”„, 졜근 μž‘μ—… λ‚΄μ—­' looks like) or potential limitations, which would help the agent interpret results.

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 parameters are fully documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema descriptions. It mentions general filtering ('ν”„λ‘œμ νŠΈμ˜ μ»¨ν…μŠ€νŠΈλ₯Ό λΉ λ₯΄κ²Œ νŒŒμ•…' - quickly grasp project context) but no details on parameter usage. Baseline 3 is appropriate given high schema coverage.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'μ‘°νšŒν•©λ‹ˆλ‹€' (retrieves) '이전 μ„Έμ…˜μ˜ λ©”λͺ¨λ¦¬, 지식 κ·Έλž˜ν”„, 졜근 μž‘μ—… λ‚΄μ—­' (previous session's memory, knowledge graph, recent work history). It distinguishes from siblings like 'list_memories' or 'get_memory_graph' by emphasizing it's a comprehensive context retrieval for session start, not just memory listing or graph analysis.

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

Usage Guidelines5/5

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

The description provides explicit guidance: '[μƒˆ λŒ€ν™”/μ„Έμ…˜ μ‹œμž‘ μ‹œ μžλ™ μ‹€ν–‰ ꢌμž₯]' (recommended to run automatically at new conversation/session start) and '이 λ„κ΅¬λŠ” μƒˆλ‘œμš΄ λŒ€ν™”λ₯Ό μ‹œμž‘ν•  λ•Œ κ°€μž₯ λ¨Όμ € μ‹€ν–‰ν•˜λ©΄ μ’‹μŠ΅λ‹ˆλ‹€' (this tool is good to run first when starting a new conversation). It implicitly suggests alternatives by specifying this is for session context, not for other analysis tasks handled by siblings.

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/su-record/hi-ai'

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