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}`);
    }

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