Skip to main content
Glama

get_context

Retrieve stored context by ID to access persistent information across Claude sessions, with optional project filtering for organized management.

Instructions

Retrieve context by ID and optional project ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesID of the context to retrieve
projectIdNoOptional project ID for project contexts

Implementation Reference

  • Main execution handler for the 'get_context' tool: extracts id and optional projectId from arguments, calls getContext, returns context content as text or throws error if not found.
    case 'get_context': { const { id, projectId } = request.params.arguments as { id: string; projectId?: string; }; const context = await this.getContext(id, projectId); if (!context) { throw new McpError( ErrorCode.InvalidRequest, `Context not found with ID: ${id}` ); } return { content: [ { type: 'text', text: context.content, }, ], }; }
  • Input schema and metadata definition for the 'get_context' tool, used in list tools response.
    { name: 'get_context', description: 'Retrieve context by ID and optional project ID', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'ID of the context to retrieve', }, projectId: { type: 'string', description: 'Optional project ID for project contexts', }, }, required: ['id'], }, },
  • Core helper method to load and parse a specific context JSON file by ID and optional projectId, returning null if not found.
    private async getContext(id: string, projectId?: string): Promise<Context | null> { try { const contextPath = await this.getContextPath(id, projectId); const data = await fs.readFile(contextPath, 'utf-8'); return JSON.parse(data); } catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') { return null; } throw error; } }
  • Helper to compute the file path for a context, creating project directory if needed.
    private async getContextPath(id: string, projectId?: string): Promise<string> { if (projectId) { const projectDir = path.join(this.projectsDir, projectId); await fs.mkdir(projectDir, { recursive: true }); return path.join(projectDir, `${id}.json`); } return path.join(this.contextsDir, `${id}.json`); }

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/davidteren/claude-server'

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