List Projects
list_projectsRetrieve all projects from the MCP Project Context Server, sorted by most recent access, to maintain coding context across sessions.
Instructions
List all projects ordered by last accessed
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:136-169 (handler)The core handler function for the 'list_projects' tool. It calls ProjectStore.listProjects(), formats the projects into a markdown list sorted by last access, and returns MCP-formatted text content or error.
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:129-170 (registration)Registers the 'list_projects' tool with the MCP server, specifying its name, metadata, empty input schema, and handler function.
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/server.ts:131-135 (schema)Tool metadata and input schema definition (no input parameters required).
{ title: "List Projects", description: "List all projects ordered by last accessed", inputSchema: {}, }, - src/storage/project-store.ts:75-91 (helper)Supporting method in ProjectStore that lists all projects by reading JSON files from the data directory, validates with ProjectContextSchema, 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() ); }