parse_file_metadata
Extract AI metadata from a file to enable project awareness and safety controls within the MCP Memory Server. Input the file path to proceed.
Instructions
Parse AI metadata from a file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file |
Implementation Reference
- src/metadata-parser.ts:47-55 (handler)Core implementation of parseFileMetadata: reads the file content and delegates to extractMetadataFromContent for parsing AI metadata headers.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; } }
- src/index.ts:848-852 (handler)MCP server request handler for the 'parse_file_metadata' tool, which delegates execution to the MetadataParser instance.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) }] }; }
- src/index.ts:652-662 (registration)Registration of the 'parse_file_metadata' tool in the MCP server's tools list, including description and input schema.{ 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'] } },
- src/types.ts:34-50 (schema)TypeScript interface defining the AIMetadata structure used as output schema for the parsed metadata.export interface AIMetadata { class?: string; description?: string; lastUpdate?: string; lastEditor?: string; changelog?: string; stability?: 'stable' | 'experimental' | 'deprecated'; editPermissions?: 'full' | 'add-only' | 'read-only' | 'method-specific'; methodPermissions?: Record<string, 'read-only' | 'allow' | 'restricted'>; dependencies?: string[]; tests?: string[]; breakingChangesRisk?: 'high' | 'medium' | 'low'; reviewRequired?: boolean; aiContext?: string; approvals?: ApprovalStatus; approvalRules?: ApprovalRules; }
- src/metadata-parser.ts:57-92 (helper)Key helper function implementing the regex parsing and field extraction logic from @ai-metadata comment blocks.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; }