Skip to main content
Glama

diff_preview

Preview file modifications by generating a diff output between original and updated content. Test edits using tools like sed, awk, or perl before applying changes, ensuring accuracy in file modifications.

Instructions

Preview what changes would be made by showing a diff

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commandYesCommand that would make changes (e.g., "s/old/new/g")
fileYesFile to preview changes for
toolNoWhich tool to use for the previewperl

Implementation Reference

  • Handler for diff_preview tool: creates temporary copy of file, applies the given command using specified tool (perl/sed/awk), computes unified diff against original, cleans up temp files, and returns the diff preview.
    case 'diff_preview': { const { file, command, tool = 'perl' } = args; if (!existsSync(file)) { throw new Error(`File not found: ${file}`); } // Create temp file const tempFile = `${file}.preview.tmp`; await execAsync(`rm -f .bak; cp '${file}' '${tempFile}'`); // Apply command to temp file let editCmd; switch (tool) { case 'perl': editCmd = `perl -i -pe '${command}' '${tempFile}'`; break; case 'sed': editCmd = `sed -i.tmp '${command}' '${tempFile}' && rm -f '${tempFile}.tmp'`; break; case 'awk': editCmd = `awk '${command}' '${tempFile}' > '${tempFile}.new' && mv '${tempFile}.new' '${tempFile}'`; break; } await execAsync(editCmd); // Generate diff const { stdout } = await execAsync(`diff -u '${file}' '${tempFile}' || true`); // Cleanup await execAsync(`rm -f '${tempFile}'`); return { content: [{ type: 'text', text: stdout ? `Preview of changes:\n${stdout}` : 'No changes would be made' }] }; }
  • Input schema definition for the diff_preview tool, specifying parameters: file (string), command (string), optional tool (enum: sed/perl/awk, default perl).
    inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'File to preview changes for' }, command: { type: 'string', description: 'Command that would make changes (e.g., "s/old/new/g")' }, tool: { type: 'string', enum: ['sed', 'perl', 'awk'], default: 'perl', description: 'Which tool to use for the preview' } }, required: ['file', 'command'] }
  • src/index.ts:203-226 (registration)
    Registration of the diff_preview tool in the tools list returned by ListToolsRequestSchema handler.
    { name: 'diff_preview', description: 'Preview what changes would be made by showing a diff', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'File to preview changes for' }, command: { type: 'string', description: 'Command that would make changes (e.g., "s/old/new/g")' }, tool: { type: 'string', enum: ['sed', 'perl', 'awk'], default: 'perl', description: 'Which tool to use for the preview' } }, required: ['file', 'command'] } },

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/MikeyBeez/mcp-smalledit'

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