Skip to main content
Glama

get_session_context

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';

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