update_file_metadata
Modify AI metadata within files to maintain accurate tracking and project awareness for coding assistants.
Instructions
Update AI metadata in a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file | |
| updates | Yes | Metadata updates to apply |
Implementation Reference
- src/metadata-parser.ts:140-149 (handler)Core handler function that reads the file content, updates the metadata block using helper method, and writes the changes back to the file.async updateFileMetadata(filePath: string, updates: Partial<AIMetadata>): Promise<void> { try { const content = await fs.readFile(filePath, 'utf-8'); const updatedContent = this.updateMetadataInContent(content, updates); await fs.writeFile(filePath, updatedContent); console.log(chalk.green(`✓ Updated metadata in ${filePath}`)); } catch (error) { console.error(chalk.red(`Error updating metadata in ${filePath}:`), error); } }
- src/index.ts:663-674 (registration)Registers the update_file_metadata tool with the MCP server, including name, description, and input schema definition.{ name: 'update_file_metadata', description: 'Update AI metadata in a file', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file' }, updates: { type: 'object', description: 'Metadata updates to apply' } }, required: ['filePath', 'updates'] } },
- src/index.ts:854-859 (handler)Tool dispatcher in the CallToolRequestHandler that extracts arguments and delegates to the MetadataParser's updateFileMetadata method.case 'update_file_metadata': { const filePath = args.filePath as string; const updates = args.updates as any; await this.metadataParser.updateFileMetadata(filePath, updates); return { content: [{ type: 'text', text: 'File metadata updated successfully' }] }; }
- src/index.ts:666-673 (schema)JSON schema defining the input parameters for the update_file_metadata tool: filePath (string) and updates (object).inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file' }, updates: { type: 'object', description: 'Metadata updates to apply' } }, required: ['filePath', 'updates'] }
- src/metadata-parser.ts:151-172 (helper)Helper method that processes the file content to update or create the AI metadata comment block.updateMetadataInContent(content: string, updates: Partial<AIMetadata>): string { const metadataRegex = /\/\*\*[\s\S]*?@ai-metadata[\s\S]*?\*\//; const match = content.match(metadataRegex); if (!match) { // If no metadata exists, create it const newMetadata = this.generateMetadataBlock(updates); return newMetadata + '\n' + content; } // Update existing metadata let metadataBlock = match[0]; // Update timestamp updates.lastUpdate = new Date().toISOString(); for (const [key, value] of Object.entries(updates)) { metadataBlock = this.updateMetadataField(metadataBlock, key, value); } return content.replace(metadataRegex, metadataBlock); }