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