Skip to main content
Glama
arathald

mcp-editor

by arathald

view

Display file contents or directory listings from specified paths, optionally showing specific line ranges for focused viewing.

Instructions

View file contents or directory listing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the file or directory
view_rangeNoOptional range of lines to view [start, end]

Implementation Reference

  • The core handler function implementing the 'view' tool logic: views file contents with optional line range or lists directory contents.
    async view(args: ViewArgs): Promise<string> {
        await validatePath('view', args.path);
    
        if (await this.isDirectory(args.path)) {
            if (args.view_range) {
                throw new ToolError(
                    'The `view_range` parameter is not allowed when `path` points to a directory.'
                );
            }
    
            const { stdout, stderr } = await execAsync(
                `find "${args.path}" -maxdepth 2 -not -path '*/\\.*'`
            );
    
            if (stderr) throw new ToolError(stderr);
    
            return `Here's the files and directories up to 2 levels deep in ${args.path}, excluding hidden items:\n${stdout}\n`;
        }
    
        const fileContent = await readFile(args.path);
        let initLine = 1;
    
        if (args.view_range) {
            const fileLines = fileContent.split('\n');
            const nLinesFile = fileLines.length;
            const [start, end] = args.view_range;
    
            if (start < 1 || start > nLinesFile) {
                throw new ToolError(
                    `Invalid \`view_range\`: ${args.view_range}. Its first element \`${start}\` should be within the range of lines of the file: [1, ${nLinesFile}]`
                );
            }
    
            if (end !== -1) {
                if (end > nLinesFile) {
                    throw new ToolError(
                        `Invalid \`view_range\`: ${args.view_range}. Its second element \`${end}\` should be smaller than the number of lines in the file: \`${nLinesFile}\``
                    );
                }
                if (end < start) {
                    throw new ToolError(
                        `Invalid \`view_range\`: ${args.view_range}. Its second element \`${end}\` should be larger or equal than its first \`${start}\``
                    );
                }
            }
    
            const selectedLines = end === -1
                ? fileLines.slice(start - 1)
                : fileLines.slice(start - 1, end);
    
            return makeOutput(selectedLines.join('\n'), String(args.path), start);
        }
    
        return makeOutput(fileContent, String(args.path));
    }
  • TypeScript interface defining the input parameters for the 'view' tool.
    export interface ViewArgs extends Record<string, unknown> {
        path: string;
        view_range?: [number, number];
    }
  • Type guard function for validating 'view' tool arguments.
    export function isViewArgs(args: Record<string, unknown>): args is ViewArgs {
        return typeof args.path === "string" &&
            (args.view_range === undefined ||
                (Array.isArray(args.view_range) &&
                    args.view_range.length === 2 &&
                    args.view_range.every(n => typeof n === "number")));
    }
  • src/server.ts:40-62 (registration)
    Registration of the 'view' tool in the MCP server's listTools response, including schema.
    {
        name: "view",
        description: "View file contents or directory listing",
        inputSchema: {
            type: "object",
            properties: {
                path: {
                    type: "string",
                    description: "Absolute path to the file or directory"
                },
                view_range: {
                    type: "array",
                    items: {
                        type: "number"
                    },
                    minItems: 2,
                    maxItems: 2,
                    description: "Optional range of lines to view [start, end]"
                }
            },
            required: ["path"]
        }
    },
  • src/server.ts:150-155 (registration)
    Dispatch in callToolRequest handler: validates args and calls the 'view' handler.
    case "view":
        if (!request.params.arguments || !isViewArgs(request.params.arguments)) {
            throw new ToolError("Invalid arguments for view command");  // At least this one was right lol
        }
        result = await this.editor.view(request.params.arguments);
        break;
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 of behavioral disclosure. It states the tool is for viewing, implying read-only behavior, but doesn't disclose other traits like error handling (e.g., what happens if the path doesn't exist), permissions required, or output format. For a tool with no annotations, this leaves significant gaps in understanding its behavior beyond the basic purpose.

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

Conciseness5/5

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

The description is extremely concise with 'View file contents or directory listing', a single sentence that front-loads the core purpose without any wasted words. It efficiently communicates the tool's function, making it easy to parse and understand quickly.

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 no annotations and no output schema, the description is incomplete for a tool with 2 parameters. It lacks details on behavioral traits, error handling, and what the output looks like (e.g., text content vs. structured listing). For a read operation with no structured output info, more context is needed to fully understand how to use and interpret results.

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

Parameters3/5

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

The input schema has 100% description coverage, with clear docs for 'path' and 'view_range'. The description adds no additional meaning beyond the schema, such as examples or edge cases. Since schema coverage is high, the baseline score is 3, as the description doesn't compensate but also doesn't detract from the well-documented parameters.

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 with 'View file contents or directory listing', specifying both verb ('View') and resources ('file contents', 'directory listing'). It distinguishes from siblings like 'create', 'insert', and 'string_replace' by indicating read-only access, though it doesn't explicitly differentiate from 'undo_edit' which might also involve viewing. The description is specific but could be more precise about sibling differentiation.

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 implies usage for viewing files or directories, suggesting when to use it (e.g., to inspect content or list items). However, it lacks explicit guidance on when not to use it or alternatives, such as using other tools for editing or creation. No prerequisites or exclusions are mentioned, leaving usage context somewhat vague.

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/arathald/mcp-editor'

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