Skip to main content
Glama
FosterG4

Code Reference Optimizer MCP Server

by FosterG4

analyze_code_diff

Compare code versions to identify specific changes, extract minimal updates, and optimize code references efficiently for AI assistants. Supports TypeScript/JavaScript, Python, Go, and Rust.

Instructions

Analyze differences between code versions and provide minimal updates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the source file
newContentYesCurrent version of the code
oldContentYesPrevious version of the code

Implementation Reference

  • MCP server handler for the 'analyze_code_diff' tool: destructures input arguments (filePath, oldContent, newContent), logs the call, delegates analysis to CodeReferenceOptimizer.analyzeCodeDiff, and returns the result as a formatted text content block.
    private async handleAnalyzeCodeDiff(args: any) { const { filePath, oldContent, newContent } = args; this.logger.info(`analyze_code_diff: filePath=${filePath}`); const result = await this.optimizer.analyzeCodeDiff({ filePath, oldContent, newContent, }); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • Core implementation of code diff analysis: generates snapshots of old/new content using DiffManager, extracts and diffs symbols at semantic level using AST parsing, produces change summary, minimal update patch, and token savings estimate.
    async analyzeCodeDiff(options: DiffAnalysisOptions): Promise<{ changes: Array<{ type: 'added' | 'removed' | 'modified'; symbol: string; code: string; lineNumber: number; }>; affectedSymbols: string[]; minimalUpdate: string; tokenSavings: number; }> { const { filePath, oldContent, newContent } = options; // Create snapshot from old content this.diffManager.createSnapshotFromContent(filePath, oldContent); // Extract symbols from old content const oldSymbols = await this.extractSymbolsFromContent(oldContent, filePath); await this.diffManager.createSymbolSnapshots(filePath, oldSymbols); // Extract symbols from new content const newSymbols = await this.extractSymbolsFromContent(newContent, filePath); // Generate symbol-level diff const symbolChanges = await this.diffManager.generateSymbolDiff(filePath, newSymbols); // Convert SymbolChange[] to the expected format const changes = symbolChanges.map(change => ({ type: change.type, symbol: change.symbol, code: change.code, lineNumber: change.lineNumber, })); const affectedSymbols = changes.map(change => change.symbol); // Generate minimal update containing only changed parts const minimalUpdate = this.generateMinimalUpdate(changes); // Calculate token savings const fullContentTokens = this.estimateTokenCount(newContent); const minimalUpdateTokens = this.estimateTokenCount(minimalUpdate); const tokenSavings = fullContentTokens - minimalUpdateTokens; return { changes, affectedSymbols, minimalUpdate, tokenSavings, }; }
  • src/index.ts:143-164 (registration)
    Registration of the 'analyze_code_diff' tool in the ListToolsRequestSchema response: specifies name, description, and input schema validation requiring filePath, oldContent, newContent.
    { name: 'analyze_code_diff', description: 'Perform intelligent analysis of code differences between two versions of a file. Identifies semantic changes, structural modifications, and provides minimal update suggestions. Helps understand the impact of changes and suggests optimizations for code evolution.', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the source file being analyzed. Used for context and language detection.', }, oldContent: { type: 'string', description: 'Complete content of the previous version of the file. Should be the full file content, not just a snippet.', }, newContent: { type: 'string', description: 'Complete content of the current version of the file. Should be the full file content, not just a snippet.', }, }, required: ['filePath', 'oldContent', 'newContent'], }, },
  • src/index.ts:233-234 (registration)
    Dispatch/registration of tool handler in CallToolRequestSchema switch statement: routes 'analyze_code_diff' calls to handleAnalyzeCodeDiff method.
    case 'analyze_code_diff': return await this.handleAnalyzeCodeDiff(args);

Other Tools

Related 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/FosterG4/mcpsaver'

If you have feedback or need assistance with the MCP directory API, please join our Discord server