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
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID of the context to retrieve | |
| projectId | No | Optional project ID for project contexts |
Implementation Reference
- src/index.ts:374-397 (handler)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, }, ], }; }
- src/index.ts:250-267 (schema)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'], }, },
- src/index.ts:114-125 (helper)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; } }
- src/index.ts:75-82 (helper)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`); }