Skip to main content
Glama

check_before_modification

Verify if a file can be modified by checking AI metadata rules before making changes to ensure compliance and prevent unauthorized alterations.

Instructions

Check if a file can be modified according to AI metadata rules

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file to check

Implementation Reference

  • MCP server tool handler for 'check_before_modification' that parses file metadata, retrieves approval status, calls RuleEngine for validation, and returns the result.
    case 'check_before_modification': { const filePath = args.filePath as string; const metadata = await this.metadataParser.parseFileMetadata(filePath); const approvals = await this.memoryManager.getFileApprovalStatus(filePath); const checkResult = await this.ruleEngine.checkBeforeModification(filePath, metadata, approvals); return { content: [{ type: 'text', text: JSON.stringify(checkResult, null, 2) }] }; }
  • src/index.ts:628-638 (registration)
    Registration of the 'check_before_modification' tool in the MCP server's tool list, including name, description, and input schema.
    { name: 'check_before_modification', description: 'Check if a file can be modified according to AI metadata rules', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to check' } }, required: ['filePath'] } },
  • Input schema definition for the 'check_before_modification' tool, specifying the required 'filePath' parameter.
    inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file to check' } }, required: ['filePath'] } },
  • Core logic implementation in RuleEngine that performs the actual checks for file modification permissions, approvals, risks, stability, and applies enabled rules.
    async checkBeforeModification(filePath: string, metadata: AIMetadata | null, approvals: ApprovalStatus | null): Promise<{ allowed: boolean; reasons: string[]; warnings: string[]; }> { const result = { allowed: true, reasons: [] as string[], warnings: [] as string[] }; if (!metadata) { result.warnings.push('No @ai-metadata found in file'); return result; } // Check edit permissions if (metadata.editPermissions === 'read-only') { result.allowed = false; result.reasons.push('File is marked as read-only'); } // Check if file requires dev approval if (metadata.breakingChangesRisk === 'high' && (!approvals?.devApproved)) { result.allowed = false; result.reasons.push('High-risk file requires dev approval before modification'); } // Check if review is required if (metadata.reviewRequired && (!approvals?.codeReviewApproved)) { result.allowed = false; result.reasons.push('File requires code review approval before modification'); } // Check stability if (metadata.stability === 'deprecated') { result.warnings.push('This file is deprecated - consider if modification is necessary'); } // Apply custom rules for (const rule of this.rules.filter(r => r.enabled)) { const ruleResult = this.evaluateRule(rule, metadata, approvals, filePath); if (!ruleResult.passed) { if (rule.priority > 8) { result.allowed = false; result.reasons.push(ruleResult.message); } else { result.warnings.push(ruleResult.message); } } } return result; }

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