Skip to main content
Glama

codeFileRead

Reads code files with line numbers to verify actual line counts for editing operations, helping users confirm file structure before making changes.

Instructions

讀取程式碼檔案並顯示行號,用於確認檔案實際行數以便編輯操作。(如果不影響編譯器的話,不需要針對縮排等小問題修改。提醒User就好了)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes

Implementation Reference

  • Core handler logic: reads the specified file, checks existence, splits into lines, adds padded line numbers to each line, joins back, handles errors.
    static async readFileWithLineNumbers(filePath: string): Promise<string> {
        try {
            // 檢查檔案是否存在
            if (!existsSync(filePath)) {
                return `錯誤: 檔案 ${filePath} 不存在`;
            }
    
            // 讀取檔案內容
            const content = await fs.readFile(filePath, 'utf8');
            const lines = content.split(/\r?\n/);
    
            // 計算行號寬度 (最大行號的位數)
            const lineNumberWidth = lines.length.toString().length;
            
            // 為每行添加行號
            const numberedLines = lines.map((line, index) => {
                const lineNumber = (index + 1).toString().padStart(lineNumberWidth, '0');
                return `${lineNumber}: ${line}`;
            });
    
            return numberedLines.join('\n');
        } catch (error) {
            console.error(`讀取檔案時發生錯誤: ${error}`);
            return `讀取檔案時發生錯誤: ${error instanceof Error ? error.message : '未知錯誤'}`;
        }
    }
  • main.ts:70-85 (registration)
    Registers the 'codeFileRead' MCP tool with name, description, input schema (filePath: string), and thin async handler that delegates to myFileReader.readFileWithLineNumbers and formats MCP response.
    server.tool("codeFileRead",
        "讀取程式碼檔案並顯示行號,用於確認檔案實際行數以便編輯操作。(如果不影響編譯器的話,不需要針對縮排等小問題修改。提醒User就好了)",
        { filePath: z.string() },
        async ({ filePath }) => {
            try {
                const result = await myFileReader.readFileWithLineNumbers(filePath);
                return {
                    content: [{ type: "text", text: result }]
                };
            } catch (error) {
                return {
                    content: [{ type: "text", text: `讀取檔案失敗: ${error instanceof Error ? error.message : "未知錯誤"}` }]
                };
            }
        }
    );
  • main.ts:72-72 (schema)
    Input schema validation using Zod for the tool: requires 'filePath' as string.
    { filePath: z.string() },
  • main.ts:8-8 (helper)
    Import of the myFileReader class used by the tool handler.
    import { myFileReader } from "./tools/csFileReader.js";
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions that the tool reads files and displays line numbers, but doesn't disclose behavioral traits such as error handling (e.g., if the file doesn't exist), performance characteristics, or output format details. The advice about not modifying minor issues adds some context, but overall, the description lacks comprehensive behavioral disclosure for a read operation tool.

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

Conciseness4/5

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

The description is concise and front-loaded, stating the core purpose in the first sentence. The second sentence adds useful guidance without redundancy. However, the inclusion of parenthetical advice slightly reduces structural clarity, but overall, it's efficient with minimal waste.

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?

Given the tool's complexity (a read operation with 1 parameter), no annotations, no output schema, and low schema coverage, the description is incomplete. It doesn't explain the return values (e.g., what '顯示行號' entails), error conditions, or parameter details, leaving significant gaps for an AI agent to understand and invoke the tool correctly.

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?

The input schema has 1 parameter with 0% description coverage, and the tool description doesn't mention any parameters. It fails to explain what 'filePath' represents (e.g., absolute path, relative path, file format expectations) or provide any semantic context beyond what the bare schema offers. This is insufficient compensation for the low schema coverage.

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: '讀取程式碼檔案並顯示行號' (read code file and display line numbers). It specifies the resource (code files) and verb (read with line numbers), but doesn't explicitly differentiate from sibling 'fileRead' which might serve a similar function without line numbers.

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

Usage Guidelines3/5

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

The description provides implied usage guidance: '用於確認檔案實際行數以便編輯操作' (for confirming actual line counts for editing operations) and advises not to modify minor issues like indentation unless they affect compilation. However, it doesn't explicitly state when to use this tool versus alternatives like 'fileRead' or 'search_code', nor does it mention prerequisites or exclusions.

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