latest_project_data
Retrieve project file names and contents from a specified directory using the MCP server for streamlined access and error handling.
Instructions
Get latest project data including file names and contents
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | Yes | Path to the project directory |
Implementation Reference
- src/index.ts:79-139 (handler)Main handler logic for the 'latest_project_data' tool: validates input arguments, calls getProjectFiles to retrieve project files, serializes to JSON, and returns as text content or error.if (request.params.name === "latest_project_data") { if ( !request.params.arguments || typeof request.params.arguments !== "object" ) { return { content: [ { type: "text", text: "Invalid arguments provided", }, ], isError: true, }; } const { projectPath } = request.params.arguments as { projectPath: string; }; if (!projectPath || typeof projectPath !== "string") { return { content: [ { type: "text", text: "projectPath must be a valid string", }, ], isError: true, }; } try { const files = await this.getProjectFiles(projectPath); // Convert to JSON string const jsonString = JSON.stringify(files, null, 2); // Send the JSON string as individual characters (like FileReadingServer) return { content: [ { type: "text", text: jsonString } ], }; } catch (error) { const message = error instanceof Error ? error.message : "Unknown error occurred"; return { content: [ { type: "text", text: `Error: ${message}`, }, ], isError: true, }; } }
- src/index.ts:60-75 (schema)Schema definition for the 'latest_project_data' tool, including name, description, and input schema requiring 'projectPath'.{ name: "latest_project_data", description: "Get latest project data including file names and contents", inputSchema: { type: "object", properties: { projectPath: { type: "string", description: "Path to the project directory", }, }, required: ["projectPath"], }, }, ],
- src/index.ts:58-76 (registration)Registration of the 'latest_project_data' tool in the ListToolsRequestSchema handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: "latest_project_data", description: "Get latest project data including file names and contents", inputSchema: { type: "object", properties: { projectPath: { type: "string", description: "Path to the project directory", }, }, required: ["projectPath"], }, }, ], }));
- src/index.ts:158-229 (helper)Helper function that reads project files recursively based on directory mapping from MCP settings file, cleans contents, and returns a record of relative paths to cleaned file contents.private async getProjectFiles(projectPath: string) { const result: Record<string, string> = {}; const self = this; // Store reference to class instance const normalizePathForOutput = ( filePath: string, basePath: string ): string => { return path.relative(basePath, filePath).replace(/\\/g, "/"); }; try { const settingsPath = "C:/Users/Mahes/AppData/Roaming/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json"; let settings; try { const settingsContent = await fs.readFile(settingsPath, "utf-8"); settings = JSON.parse(settingsContent); } catch (err: unknown) { const errorMessage = err instanceof Error ? err.message : String(err); throw new Error( `Failed to read settings file at ${settingsPath}: ${errorMessage}` ); } const mapping = settings.mcpServers?.ProjectContentServer?.directoryMapping?.[ projectPath ]; if (!mapping) { throw new Error( `No directory mapping found for project path: ${projectPath}` ); } async function processPath(itemPath: string) { const fullPath = path.normalize(itemPath); try { const stats = await fs.stat(fullPath); if (stats.isDirectory()) { const files = await fs.readdir(fullPath); for (const file of files) { await processPath(path.join(itemPath, file)); } } else if (stats.isFile()) { const content = await fs.readFile(fullPath, { encoding: "utf8", flag: "r", }); const relativePath = normalizePathForOutput(fullPath, projectPath); // Use stored reference to access class method result[relativePath] = self.cleanFileContent(content); } } catch (err: unknown) { const errorMessage = err instanceof Error ? err.message : String(err); console.error(`Error processing path ${fullPath}: ${errorMessage}`); } } for (const pathItem of mapping) { await processPath(pathItem); } return result; } catch (err: unknown) { const errorMessage = err instanceof Error ? err.message : String(err); throw new Error(`Failed to process project files: ${errorMessage}`); } }
- src/index.ts:151-156 (helper)Helper function to clean file content by normalizing whitespace and line endings.private cleanFileContent(content: string): string { return content .replace(/\r\n|\n/g, " ") // Replace all line endings with space .replace(/\s+/g, " ") // Normalize multiple spaces to single .trim(); // Remove leading/trailing whitespace }