Skip to main content
Glama

codeLineDelete

Remove specific line ranges from code files to delete unwanted sections or clean up code. Specify file path and line numbers to execute deletions.

Instructions

每次使用前、使用後必須先使用(codeFileRead)。刪除程式碼檔案指定範圍的行。(如果不影響編譯器的話,不需要針對縮排等小問題修改。提醒User就好了)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes
startLineYes
endLineNo

Implementation Reference

  • Core handler function that deletes specified lines from a file by reading content, splitting into lines, removing the range with splice, and writing back. Handles validation and errors.
    static async deleteLines(
        filePath: string, 
        startLine: number, 
        endLine?: number
    ): Promise<string> {
        try {
            // 檢查檔案是否存在
            if (!existsSync(filePath)) {
                return `錯誤: 檔案 ${filePath} 不存在`;
            }
    
            // 設置結束行,如果未提供則等於起始行
            const effectiveEndLine = endLine || startLine;
            
            // 確保起始行小於等於結束行
            if (startLine > effectiveEndLine) {
                return `錯誤: 起始行 ${startLine} 大於結束行 ${effectiveEndLine}`;
            }
    
            // 讀取檔案內容
            const fileContent = await fs.readFile(filePath, 'utf8');
            const lines = fileContent.split(/\r?\n/);
    
            // 檢查行號是否有效
            if (startLine < 1 || startLine > lines.length) {
                return `錯誤: 起始行 ${startLine} 超出範圍,檔案共有 ${lines.length} 行`;
            }
            if (effectiveEndLine < 1 || effectiveEndLine > lines.length) {
                return `錯誤: 結束行 ${effectiveEndLine} 超出範圍,檔案共有 ${lines.length} 行`;
            }
    
            // 刪除指定範圍的行
            lines.splice(startLine - 1, effectiveEndLine - startLine + 1);
    
            // 寫回檔案
            await fs.writeFile(filePath, lines.join('\n'), 'utf8');
    
            if (startLine === effectiveEndLine) {
                return `成功刪除第 ${startLine} 行`;
            } else {
                return `成功刪除第 ${startLine} 行到第 ${effectiveEndLine} 行`;
            }
        } catch (error) {
            console.error(`刪除內容時發生錯誤: ${error}`);
            return `刪除內容時發生錯誤: ${error instanceof Error ? error.message : '未知錯誤'}`;
        }
    }
  • Zod input schema defining parameters for the codeLineDelete tool: filePath, startLine (required), endLine (optional).
    {
        filePath: z.string(),
        startLine: z.number(),
        endLine: z.number().optional()
    },
  • main.ts:109-128 (registration)
    Registers the 'codeLineDelete' MCP tool with name, description, input schema, and an async wrapper handler that calls the core deleteLines function and formats the MCP response.
    server.tool("codeLineDelete",
        "每次使用前、使用後必須先使用(codeFileRead)。刪除程式碼檔案指定範圍的行。(如果不影響編譯器的話,不需要針對縮排等小問題修改。提醒User就好了)",
        {
            filePath: z.string(),
            startLine: z.number(),
            endLine: z.number().optional()
        },
        async ({ filePath, startLine, endLine }) => {
            try {
                const result = await myFileDelete.deleteLines(filePath, startLine, endLine);
                return {
                    content: [{ type: "text", text: result }]
                };
            } catch (error) {
                return {
                    content: [{ type: "text", text: `刪除內容失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }]
                };
            }
        }
    );
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that this is a destructive operation (deletes lines) and mentions a prerequisite (codeFileRead). However, it doesn't cover important behavioral aspects like error handling, what happens if lines don't exist, whether changes are saved immediately, or permission requirements. The description adds some context but leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is relatively concise but could be better structured. The first sentence about prerequisites is front-loaded and important. The second sentence mixes the core purpose with implementation details about formatting. While not excessively wordy, the structure could be clearer by separating purpose from behavioral notes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive operation with 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficient. It mentions prerequisites and gives a hint about formatting behavior, but doesn't explain what the tool returns, error conditions, or the full implications of deleting code lines. The description should do more given the complexity and lack of structured documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage and 3 parameters, the description provides no information about what 'filePath', 'startLine', or 'endLine' mean or how they should be formatted. The baseline would be 1 for complete lack of parameter information, but it gets a 2 because the description implies line-based deletion (giving some context about the parameters' purpose), though not enough to compensate for the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '刪除程式碼檔案指定範圍的行' (delete specified lines from a code file). It specifies the resource (code file) and action (delete lines within a range). However, it doesn't explicitly differentiate from sibling tools like 'delete_from_file' or 'codeLineInsert', which reduces it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage guidelines: '每次使用前、使用後必須先使用(codeFileRead)' (must use codeFileRead before and after each use). It also mentions an alternative approach for minor formatting issues ('提醒User就好了' - just remind the user). This gives clear when-to-use and prerequisite instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/GonTwVn/GonMCPtool'

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