list_projects
Retrieve all projects sorted by last access timestamp for easy reference and continuity in coding sessions within the MCP Project Context Server.
Instructions
List all projects ordered by last accessed
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:136-169 (handler)Executes the list_projects tool: fetches all projects from storage, sorts by last accessed, formats into a markdown list, and returns as MCP content.async () => { try { const projects = await this.store.listProjects(); const projectList = projects .map( (p) => `- ${p.name} (${p.id}) - ${ p.status } - Last accessed: ${new Date( p.lastAccessedAt ).toLocaleDateString()}` ) .join("\n"); return { content: [ { type: "text", text: `Active Projects:\n${projectList || "No projects found"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error listing projects: ${ error instanceof Error ? error.message : "Unknown error" }`, }, ], }; } }
- src/server.ts:131-135 (schema)Input schema (empty object), title, and description for the list_projects tool.{ title: "List Projects", description: "List all projects ordered by last accessed", inputSchema: {}, },
- src/server.ts:129-170 (registration)Registers the list_projects tool with MCP server, including schema and handler.this.server.registerTool( "list_projects", { title: "List Projects", description: "List all projects ordered by last accessed", inputSchema: {}, }, async () => { try { const projects = await this.store.listProjects(); const projectList = projects .map( (p) => `- ${p.name} (${p.id}) - ${ p.status } - Last accessed: ${new Date( p.lastAccessedAt ).toLocaleDateString()}` ) .join("\n"); return { content: [ { type: "text", text: `Active Projects:\n${projectList || "No projects found"}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error listing projects: ${ error instanceof Error ? error.message : "Unknown error" }`, }, ], }; } } );
- src/storage/project-store.ts:75-91 (helper)Supporting method in ProjectStore that lists all project JSON files from storage directory, parses them, and sorts by lastAccessedAt descending.async listProjects(): Promise<ProjectContext[]> { const files = await fs.readdir(this.projectsDir); const projects: ProjectContext[] = []; for (const file of files) { if (file.endsWith(".json")) { const data = await fs.readJson(path.join(this.projectsDir, file)); projects.push(ProjectContextSchema.parse(data)); } } return projects.sort( (a, b) => new Date(b.lastAccessedAt).getTime() - new Date(a.lastAccessedAt).getTime() ); }