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);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a mutation operation ('update') but doesn't disclose permissions needed, whether changes are reversible, potential side effects, or error conditions. This is inadequate for a tool that modifies data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and target, making it easy to parse quickly. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'AI metadata' includes, how updates are applied, what the response looks like, or error handling. Given the complexity implied by nested parameters, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are documented in the schema. The description adds no additional meaning beyond implying 'updates' relate to 'AI metadata', which is already inferred from the tool name. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Update AI metadata in a file' clearly states the action (update) and target (AI metadata in a file), distinguishing it from siblings like 'parse_file_metadata' (read) or 'set_file_approval' (different metadata type). However, it lacks specificity about what 'AI metadata' entails, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file existence), exclusions, or comparisons to siblings like 'update_last_editor' or 'set_file_approval', leaving the agent to infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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