list_contexts
Retrieve and filter available contexts in Claude Server MCP by project, tag, or type to manage persistent conversations and project organization.
Instructions
List contexts with filtering options
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | No | Optional project ID to filter by | |
| tag | No | Optional tag to filter by | |
| type | No | Optional type to filter by |
Implementation Reference
- src/index.ts:127-170 (handler)Core implementation of listContexts: scans project and conversation directories for JSON files, parses contexts, applies filters for projectId/tag/type, sorts by recency.private async listContexts(options: { projectId?: string; tag?: string; type?: 'project' | 'conversation'; } = {}): Promise<Context[]> { await this.ensureDirectories(); const getContextsFromDir = async (dir: string): Promise<Context[]> => { const files = await fs.readdir(dir); const contexts: Context[] = []; for (const file of files) { if (file.endsWith('.json')) { const data = await fs.readFile(path.join(dir, file), 'utf-8'); contexts.push(JSON.parse(data)); } } return contexts; }; let contexts: Context[] = []; if (options.projectId) { const projectDir = path.join(this.projectsDir, options.projectId); contexts = await getContextsFromDir(projectDir); } else if (options.type === 'project') { contexts = await getContextsFromDir(this.projectsDir); } else if (options.type === 'conversation') { contexts = await getContextsFromDir(this.contextsDir); } else { const projectContexts = await getContextsFromDir(this.projectsDir); const conversationContexts = await getContextsFromDir(this.contextsDir); contexts = [...projectContexts, ...conversationContexts]; } if (options.tag) { contexts = contexts.filter(ctx => ctx.tags?.includes(options.tag!)); } return contexts.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime() ); }
- src/index.ts:271-288 (schema)Input schema defining optional parameters for filtering contexts: projectId, tag, type.inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: 'Optional project ID to filter by', }, tag: { type: 'string', description: 'Optional tag to filter by', }, type: { type: 'string', enum: ['project', 'conversation'], description: 'Optional type to filter by', }, }, },
- src/index.ts:268-289 (registration)Registration of the list_contexts tool in the ListTools response, including name, description, and schema.{ name: 'list_contexts', description: 'List contexts with filtering options', inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: 'Optional project ID to filter by', }, tag: { type: 'string', description: 'Optional tag to filter by', }, type: { type: 'string', enum: ['project', 'conversation'], description: 'Optional type to filter by', }, }, }, },
- src/index.ts:399-416 (handler)Dispatcher handler in CallToolRequest that parses arguments, calls listContexts, and returns JSON string of results.case 'list_contexts': { const { projectId, tag, type } = request.params.arguments as { projectId?: string; tag?: string; type?: 'project' | 'conversation'; }; const contexts = await this.listContexts({ projectId, tag, type }); return { content: [ { type: 'text', text: JSON.stringify(contexts, null, 2), }, ], }; }