Skip to main content
Glama
ai-yliu

Filesystem MCP Server

by ai-yliu

read_file

Retrieve complete file contents from the filesystem. Specify the file path to access text, code, or data stored in documents.

Instructions

Read complete contents of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the file to read

Implementation Reference

  • The handler logic for the 'read_file' tool. It extracts the file path from the request arguments, validates the path is allowed, reads the entire file content using fs.readFile, and returns it formatted as MCP tool content with type 'text'.
    case 'read_file': {
      const { path: filePath } = request.params.arguments as { path: string };
      validatePath(filePath);
      
      const content = await fs.readFile(filePath, 'utf8');
      return {
        content: [
          {
            type: 'text',
            text: content,
          },
        ],
      };
    }
  • The JSON schema defining the input parameters for the 'read_file' tool, requiring a single 'path' string property.
    inputSchema: {
      type: 'object',
      properties: {
        path: {
          type: 'string',
          description: 'Path to the file to read',
        },
      },
      required: ['path'],
    },
  • src/index.ts:95-108 (registration)
    The tool registration entry in the list_tools response, including name, description, and input schema for 'read_file'.
    {
      name: 'read_file',
      description: 'Read complete contents of a file',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to the file to read',
          },
        },
        required: ['path'],
      },
    },
  • Helper function called by the read_file handler to ensure the requested file path is within the server-allowed directories, throwing an error if not.
    function validatePath(filePath: string): void {
      if (!isPathAllowed(filePath)) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          `Access denied: ${filePath} is not within allowed directories`
        );
      }
    }
  • Supporting helper function used by validatePath to check if a resolved path is within any of the allowed directories.
    function isPathAllowed(filePath: string): boolean {
      const resolvedPath = path.resolve(filePath);
      return resolvedAllowedDirectories.some(allowedDir => 
        resolvedPath === allowedDir || resolvedPath.startsWith(allowedDir + path.sep)
      );
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool reads 'complete contents' but doesn't specify file size limits, encoding handling, error conditions (e.g., missing files), or performance implications. For a read operation with zero annotation coverage, this leaves critical behavioral traits undocumented.

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 a single, efficient sentence with zero waste. It's front-loaded with the core action and resource, making it immediately scannable. Every word earns its place, and there's no redundant or verbose phrasing.

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 simplicity (1 parameter, 100% schema coverage) but lack of annotations and output schema, the description is incomplete. It doesn't address return values (e.g., content format, encoding), error handling, or constraints like file size. For a read operation, this leaves significant gaps in understanding how to use it effectively.

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 100%, with the single parameter 'path' fully documented in the schema. The description doesn't add any parameter-specific information beyond what the schema provides (e.g., path format examples, relative vs. absolute paths). Baseline 3 is appropriate since the schema does the heavy lifting, but no extra value is added.

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 action ('Read') and target ('complete contents of a file'), making the purpose immediately understandable. It distinguishes from siblings like 'get_file_info' (metadata) and 'read_multiple_files' (batch operation), though it doesn't explicitly name these alternatives. The verb+resource combination is specific but could be more precise about scope.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention when to choose 'read_file' over 'read_multiple_files' for batch needs, 'get_file_info' for metadata only, or 'search_files' for content searching. There's no context about prerequisites like file existence or permissions, leaving usage decisions unclear.

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/ai-yliu/filesystem-mcp-server'

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