Skip to main content
Glama

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
NameRequiredDescriptionDefault
projectIdNoOptional project ID to filter by
tagNoOptional tag to filter by
typeNoOptional type to filter by

Implementation Reference

  • 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() ); }
  • 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', }, }, }, },
  • 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), }, ], }; }

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