Skip to main content
Glama

get_session_context

Retrieve a snapshot of your RPG session context including location, party details, notes, combat state, and summary. Customize output with specific sections, formats, and limits to track game progress.

Instructions

Get comprehensive session context snapshot. Includes location, party, notes, combat state, and summary. Options: include (array of sections), format (detailed|compact|brief), maxNotes (limit), includeTimestamps (boolean).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeNo
formatNo
maxNotesNo
includeTimestampsNo

Implementation Reference

  • Main handler function that parses input, gathers session context from various modules (location, party, notes, combat, summary), formats it according to specified format (detailed/compact/brief), and returns boxed ASCII output.
    export async function getSessionContext(input: unknown): Promise<{ content: { type: 'text'; text: string }[] }> { try { const parsed = getSessionContextSchema.parse(input); const format = parsed.format || 'detailed'; const sections = parsed.include || ['location', 'party', 'notes', 'combat', 'summary']; const maxNotes = parsed.maxNotes; const includeTimestamps = parsed.includeTimestamps || false; const lines: string[] = []; // Build context based on requested sections for (const section of sections) { switch (section) { case 'location': lines.push(...getLocationContext(format)); break; case 'party': lines.push(...getPartyContext(format)); break; case 'notes': lines.push(...getNotesContext(format, maxNotes, includeTimestamps)); break; case 'combat': lines.push(...getCombatContext(format)); break; case 'summary': lines.push(...getSummaryContext()); break; } if (format !== 'brief') { lines.push(''); // spacing between sections } } // Remove trailing empty lines while (lines.length > 0 && lines[lines.length - 1] === '') { lines.pop(); } const output = createBox('SESSION CONTEXT', lines, DISPLAY_WIDTH); return { content: [{ type: 'text' as const, text: output }] }; } catch (error) { const lines: string[] = []; if (error instanceof z.ZodError) { for (const issue of error.issues) { lines.push(`${issue.path.join('.')}: ${issue.message}`); } } else if (error instanceof Error) { lines.push(error.message); } else { lines.push('An unknown error occurred'); } return { content: [{ type: 'text' as const, text: createBox('ERROR', lines, DISPLAY_WIDTH) }] }; } }
  • Zod schema defining input parameters for the get_session_context tool: sections to include, output format, note limit, and timestamp inclusion.
    export const getSessionContextSchema = z.object({ include: z.array(fuzzyEnum(['location', 'party', 'notes', 'combat', 'summary'] as const)).optional(), format: fuzzyEnum(['detailed', 'compact', 'brief'] as const, 'verbosity').optional(), maxNotes: z.number().int().positive().optional(), includeTimestamps: z.boolean().optional(), });
  • Tool registration in the central registry, including name, description, input schema conversion, and wrapper handler that calls the actual getSessionContext function.
    get_session_context: { name: 'get_session_context', description: 'Get comprehensive session context snapshot. Includes location, party, notes, combat state, and summary. Options: include (array of sections), format (detailed|compact|brief), maxNotes (limit), includeTimestamps (boolean).', inputSchema: toJsonSchema(getSessionContextSchema), handler: async (args) => { try { const result = await getSessionContext(args); return result; } catch (err) { if (err instanceof z.ZodError) { const messages = err.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', '); return error(`Validation failed: ${messages}`); } const message = err instanceof Error ? err.message : String(err); return error(message); } }, },

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/Mnehmos/ChatRPG'

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