Skip to main content
Glama

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
NameRequiredDescriptionDefault
filePathYesPath to the file
updatesYesMetadata updates to apply

Implementation Reference

  • 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); } }
  • 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'] } },
  • 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' }] };
  • 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); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/keleshteri/mcp-memory'

If you have feedback or need assistance with the MCP directory API, please join our Discord server