Skip to main content
Glama

read_file

Read files from project sandboxes to access code and content for web development tasks. Use this tool to retrieve text or binary files from active AICre8 platform projects.

Instructions

Read a file from the project sandbox. Requires an active sandbox (run generate_code first to boot it).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID (UUID or url_id)
file_pathYesFile path relative to project root (e.g. "src/App.tsx")
encodingNoEncoding: "utf-8" (default) for text, "base64" for binary files

Implementation Reference

  • src/index.ts:116-148 (registration)
    Tool registration: Registers the 'read_file' tool with the MCP server using server.tool(), including the tool name, description, schema, and handler function.
    server.tool(
      'read_file',
      'Read a file from the project sandbox. Requires an active sandbox (run generate_code first to boot it).',
      {
        project_id: z.string().describe('Project ID (UUID or url_id)'),
        file_path: z.string().describe('File path relative to project root (e.g. "src/App.tsx")'),
        encoding: z
          .enum(['utf-8', 'base64'])
          .optional()
          .describe('Encoding: "utf-8" (default) for text, "base64" for binary files'),
      },
      async (params) => {
        try {
          const result = await client.readFile(
            params.project_id,
            params.file_path,
            params.encoding,
          );
          return {
            content: [
              {
                type: 'text' as const,
                text: params.encoding === 'base64'
                  ? `File: ${result.path} (base64, ${result.content.length} chars)`
                  : result.content,
              },
            ],
          };
        } catch (err: any) {
          return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
        }
      },
    );
  • Tool handler: Async function that executes the read_file tool logic. It calls client.readFile() with project_id, file_path, and encoding parameters, then formats the response based on encoding type (base64 vs text) and handles errors.
    async (params) => {
      try {
        const result = await client.readFile(
          params.project_id,
          params.file_path,
          params.encoding,
        );
        return {
          content: [
            {
              type: 'text' as const,
              text: params.encoding === 'base64'
                ? `File: ${result.path} (base64, ${result.content.length} chars)`
                : result.content,
            },
          ],
        };
      } catch (err: any) {
        return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
      }
    },
  • Schema definition: Zod schema defining the input parameters for read_file tool - project_id (required string), file_path (required string), and encoding (optional enum of 'utf-8' or 'base64').
    {
      project_id: z.string().describe('Project ID (UUID or url_id)'),
      file_path: z.string().describe('File path relative to project root (e.g. "src/App.tsx")'),
      encoding: z
        .enum(['utf-8', 'base64'])
        .optional()
        .describe('Encoding: "utf-8" (default) for text, "base64" for binary files'),
    },
  • Client helper method: Implements the actual HTTP request to the AICre8 API endpoint '/projects/{projectId}/files/{filePath}' with optional encoding query parameter. Returns an object with path, content, and encoding.
    async readFile(
      projectId: string,
      filePath: string,
      encoding?: 'utf-8' | 'base64',
    ): Promise<{ path: string; content: string; encoding: string }> {
      const query = encoding ? `?encoding=${encoding}` : '';
      return this.request('GET', `/projects/${projectId}/files/${filePath}${query}`);
    }
Behavior4/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 key behavioral traits: it's a read operation (implied by 'Read'), requires an active sandbox (a prerequisite condition), and hints at context (sandbox environment). However, it doesn't mention potential errors, rate limits, or output format details, leaving some gaps.

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 front-loaded with the core purpose in the first sentence and adds a crucial prerequisite in the second. Every sentence earns its place with no wasted words, making it highly efficient and well-structured.

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

Completeness4/5

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

Given the tool's moderate complexity (read operation with prerequisites), no annotations, and no output schema, the description is mostly complete. It covers purpose, usage, and prerequisites but lacks details on return values or error handling, which would be beneficial for full completeness.

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%, so the schema fully documents all parameters. The description adds no additional parameter semantics beyond what the schema provides, such as examples or usage notes. Baseline 3 is appropriate as the schema handles the heavy lifting.

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 a file') and resource ('from the project sandbox'), distinguishing it from siblings like write_file (which writes) or list_projects (which lists). It precisely defines the tool's function without ambiguity.

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?

It explicitly states when to use this tool ('Read a file from the project sandbox') and provides a prerequisite ('Requires an active sandbox') with a clear alternative action ('run generate_code first to boot it'), guiding the agent on proper usage versus other 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

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/AICre8dev/mcp-server'

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