Skip to main content
Glama

parse_file_metadata

Extract AI metadata from files to enable persistent memory and project awareness for coding assistants.

Instructions

Parse AI metadata from a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file

Implementation Reference

  • src/index.ts:652-662 (registration)
    Registration of the 'parse_file_metadata' tool in the MCP server, including name, description, and input schema requiring 'filePath'.
    { name: 'parse_file_metadata', description: 'Parse AI metadata from a file', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file' } }, required: ['filePath'] } },
  • Tool handler in the switch statement that processes 'parse_file_metadata' calls: extracts filePath, invokes MetadataParser.parseFileMetadata, and returns JSON-formatted result.
    case 'parse_file_metadata': { const filePath = args.filePath as string; const parsedMetadata = await this.metadataParser.parseFileMetadata(filePath); return { content: [{ type: 'text', text: JSON.stringify(parsedMetadata, null, 2) }] }; }
  • Core implementation of file metadata parsing: reads file content and delegates to extractMetadataFromContent, with error handling.
    async parseFileMetadata(filePath: string): Promise<AIMetadata | null> { try { const content = await fs.readFile(filePath, 'utf-8'); return this.extractMetadataFromContent(content); } catch (error) { console.error(chalk.red(`Error reading file ${filePath}:`), error); return null; } }
  • Helper function that extracts and parses the @ai-metadata block from file content using regex and field-specific parsers.
    extractMetadataFromContent(content: string): AIMetadata | null { // Look for @ai-metadata block const metadataRegex = /\/\*\*[\s\S]*?@ai-metadata[\s\S]*?\*\//; const match = content.match(metadataRegex); if (!match) { return null; } const metadataBlock = match[0]; const metadata: AIMetadata = {}; // Parse each field this.parseField(metadataBlock, '@class:', (value) => metadata.class = value); this.parseField(metadataBlock, '@description:', (value) => metadata.description = value); this.parseField(metadataBlock, '@last-update:', (value) => metadata.lastUpdate = value); this.parseField(metadataBlock, '@last-editor:', (value) => metadata.lastEditor = value); this.parseField(metadataBlock, '@changelog:', (value) => metadata.changelog = value); this.parseField(metadataBlock, '@stability:', (value) => metadata.stability = value as any); this.parseField(metadataBlock, '@edit-permissions:', (value) => metadata.editPermissions = value as any); this.parseField(metadataBlock, '@breaking-changes-risk:', (value) => metadata.breakingChangesRisk = value as any); this.parseField(metadataBlock, '@review-required:', (value) => metadata.reviewRequired = value === 'true'); this.parseField(metadataBlock, '@ai-context:', (value) => metadata.aiContext = value); // Parse arrays this.parseArrayField(metadataBlock, '@dependencies:', (value) => metadata.dependencies = value); this.parseArrayField(metadataBlock, '@tests:', (value) => metadata.tests = value); // Parse method permissions (JSON object) this.parseJsonField(metadataBlock, '@method-permissions:', (value) => metadata.methodPermissions = value); // Parse approvals metadata.approvals = this.parseApprovals(metadataBlock); return metadata; }

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