Skip to main content
Glama

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

Implementation Reference

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

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