Skip to main content
Glama
rawr-ai

Filesystem MCP Server

read_file

Access and retrieve the complete contents of a specified file from the file system, supporting various text encodings. Requires a file path and maxBytes parameter to limit data read. Ideal for examining file content within permitted directories.

Instructions

Read the complete contents of a file from the file system. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to examine the contents of a single file. Requires maxBytes parameter. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxBytesYesMaximum bytes to read from the file. Must be a positive integer. Handler default: 10KB.
pathYes

Implementation Reference

  • The handleReadFile function that executes the core logic of the read_file tool: parses arguments using the schema, validates the file path against allowed directories, checks file size limit, reads the file content using fs.readFile, and returns it in a structured format.
    export async function handleReadFile(
      args: unknown,
      allowedDirectories: string[],
      symlinksMap: Map<string, string>,
      noFollowSymlinks: boolean
    ) {
      const { path: filePath, maxBytes } = parseArgs(ReadFileArgsSchema, args, 'read_file');
      const validPath = await validatePath(filePath, allowedDirectories, symlinksMap, noFollowSymlinks);
      
      // Check file size before reading
      const stats = await fs.stat(validPath);
      const effectiveMaxBytes = maxBytes ?? (10 * 1024); // Default 10KB
      if (stats.size > effectiveMaxBytes) {
        throw new Error(`File size (${stats.size} bytes) exceeds the maximum allowed size (${effectiveMaxBytes} bytes).`);
      }
      
      const content = await fs.readFile(validPath, "utf-8");
      return {
        content: [{ type: "text", text: content }],
      };
    }
  • TypeBox schema definition for read_file tool inputs: requires 'path' (string) and optional 'maxBytes' (positive integer with description). Also defines the TypeScript type ReadFileArgs.
    export const ReadFileArgsSchema = Type.Object({
      path: Type.String(),
      maxBytes: Type.Integer({
        minimum: 1,
        description: 'Maximum bytes to read from the file. Must be a positive integer. Handler default: 10KB.'
      })
    });
    export type ReadFileArgs = Static<typeof ReadFileArgsSchema>;
  • index.ts:167-168 (registration)
    Registration of the read_file handler in the toolHandlers object, mapping the tool name to the execution of handleReadFile with context parameters.
    read_file: (a: unknown) =>
      handleReadFile(a, allowedDirectories, symlinksMap, noFollowSymlinks),
  • index.ts:305-305 (registration)
    Declaration of the read_file tool metadata (name and description) in the allTools array used for server registration.
    { name: "read_file", description: "Read file contents" },
  • Re-export and mapping of ReadFileArgsSchema to the 'read_file' key in the central toolSchemas object used by the server.
    read_file: ReadFileArgsSchema,
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 useful behavioral traits: handles various text encodings, provides detailed error messages, and has directory restrictions. However, it doesn't mention performance characteristics, memory usage, or what happens with very large files beyond the maxBytes parameter.

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?

Three sentences with zero waste. The first states the core functionality, the second adds behavioral context, and the third provides usage guidance and constraints. Every sentence earns its place and the description is appropriately sized.

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

Completeness3/5

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

For a file reading tool with 2 parameters, no annotations, and no output schema, the description provides basic functionality and constraints. However, it doesn't explain return format, encoding details, or error handling specifics. Given the complexity and lack of structured data, it should do more to be complete.

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?

Schema description coverage is 50% (only maxBytes has a description). The description adds that 'Requires maxBytes parameter' but doesn't explain the 'path' parameter beyond what's in the schema. It provides some context about the tool's constraints but doesn't fully compensate for the undocumented 'path' parameter.

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

Purpose5/5

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

The description clearly states the specific action ('Read the complete contents'), resource ('a file from the file system'), and scope ('single file'). It distinguishes from sibling tools like 'read_multiple_files' by specifying 'single file' and from 'get_file_info' by focusing on content rather than metadata.

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

Usage Guidelines4/5

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

The description provides clear context for when to use ('when you need to examine the contents of a single file') and mentions constraints ('Only works within allowed directories'). However, it doesn't explicitly state when NOT to use it or name specific alternatives among the many sibling tools.

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

Related 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/rawr-ai/mcp-filesystem'

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