update_file_metadata
Modify AI metadata within files on the MCP Memory Server to ensure accurate tracking, updated project context, and controlled file changes during coding sessions.
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)Executes the tool logic: reads file content, updates metadata block via helper, writes back to 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:666-673 (schema)Input schema defining parameters: filePath (string, required), updates (object, required).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:663-674 (registration)Registers the tool in MCP server's tools list with name, description, and schema.{ 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-858 (handler)Top-level tool dispatcher case that extracts args and delegates to MetadataParser.updateFileMetadata.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/metadata-parser.ts:151-172 (helper)Core helper that updates or creates the @ai-metadata comment block in file content.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); }