Skip to main content
Glama
talentedmrweb

Local Dev Bridge MCP

edit_file

Replace specific text in local development files by matching exact content, enabling precise file modifications for coding tasks.

Instructions

Edit a file by replacing specific text. The old_text must match exactly (including whitespace).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file
old_textYesText to find and replace (must match exactly)
new_textYesText to replace it with

Implementation Reference

  • The handler function that implements the logic for the 'edit_file' tool: reads the file, checks if old_text exists, replaces it with new_text, and writes the file back.
    async editFile(filePath, oldText, newText) {
      const resolvedPath = this.resolvePath(filePath);
      let content = await fs.readFile(resolvedPath, 'utf-8');
      
      if (!content.includes(oldText)) {
        throw new Error(`Text not found in file: ${oldText.substring(0, 50)}...`);
      }
      
      content = content.replace(oldText, newText);
      await fs.writeFile(resolvedPath, content, 'utf-8');
      
      return {
        content: [
          {
            type: 'text',
            text: `File edited successfully: ${resolvedPath}`,
          },
        ],
      };
    }
  • index.js:79-100 (registration)
    Registration of the 'edit_file' tool in the ListTools response, including name, description, and input schema.
    {
      name: 'edit_file',
      description: 'Edit a file by replacing specific text. The old_text must match exactly (including whitespace).',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file',
          },
          old_text: {
            type: 'string',
            description: 'Text to find and replace (must match exactly)',
          },
          new_text: {
            type: 'string',
            description: 'Text to replace it with',
          },
        },
        required: ['path', 'old_text', 'new_text'],
      },
    },
  • The switch case in the CallToolRequestHandler that dispatches 'edit_file' calls to the editFile method.
    case 'edit_file':
      return await this.editFile(args.path, args.old_text, args.new_text);
  • The input schema defining the parameters for the 'edit_file' tool.
    inputSchema: {
      type: 'object',
      properties: {
        path: {
          type: 'string',
          description: 'Path to the file',
        },
        old_text: {
          type: 'string',
          description: 'Text to find and replace (must match exactly)',
        },
        new_text: {
          type: 'string',
          description: 'Text to replace it with',
        },
      },
      required: ['path', 'old_text', 'new_text'],
    },

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/talentedmrweb/local-dev-bridge-mcp'

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