Skip to main content
Glama

delete_lines

Remove specific line ranges from files in Godot projects to clean up code or remove unwanted sections by specifying start and end positions.

Instructions

Delete a range of lines from a file. Line numbers are 1-based.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file
startYesFirst line to delete (1-based)
endYesLast line to delete (1-based, inclusive)

Implementation Reference

  • The implementation of the delete_lines tool, which reads a file, splits its content into lines, uses splice to remove the specified range, writes the updated content back, and emits a change event.
      name: "delete_lines",
      description: "Delete a range of lines from a file. Line numbers are 1-based.",
      schema: {
        path: z.string().describe("Path to the file"),
        start: z.number().int().min(1).describe("First line to delete (1-based)"),
        end: z.number().int().min(1).describe("Last line to delete (1-based, inclusive)"),
      },
      handler: async (ctx) => {
        const { path, start, end } = ctx.args;
        validatePath(path);
        try {
          const content = readFileSync(path, "utf-8");
          const lines = content.split("\n");
    
          if (start < 1 || end > lines.length || start > end) {
            return makeTextResponse({
              error: `Invalid line range: ${start}-${end} (file has ${lines.length} lines)`,
              data: null,
            });
          }
    
          const deleted = lines.splice(start - 1, end - start + 1);
          writeFileSync(path, lines.join("\n"), "utf-8");
    
          await eventBus.emit("file:changed", {
            path,
            type: "modified",
          });
    
          return makeTextResponse({
            data: { deletedLines: deleted.length, path },
            metadata: { source: "fallback" },
          });
        } catch (err) {
          return makeTextResponse({
            error: `Failed to delete lines: ${(err as Error).message}`,
            data: null,
          });
        }
      },
    },

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/woohq/godette-mcp'

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