Skip to main content
Glama

write_file

Create or update files in the AICre8 project sandbox, automatically generating parent directories as needed for web development tasks.

Instructions

Write or update a file in the project sandbox. Creates parent directories automatically.

Input Schema

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

Implementation Reference

  • The handler function that executes the write_file tool logic. It calls client.writeFile() with the project_id, file_path, content, and encoding parameters, then returns a success message or error.
    async (params) => {
      try {
        const result = await client.writeFile(
          params.project_id,
          params.file_path,
          params.content,
          params.encoding,
        );
        return {
          content: [
            {
              type: 'text' as const,
              text: `Written: ${result.path}`,
            },
          ],
        };
      } catch (err: any) {
        return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
      }
    },
  • Zod schema definition for write_file tool inputs: project_id (string), file_path (string), content (string), and optional encoding (enum: '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")'),
      content: z.string().describe('File content to write'),
      encoding: z
        .enum(['utf-8', 'base64'])
        .optional()
        .describe('Encoding: "utf-8" (default) for text, "base64" for binary files'),
  • src/index.ts:152-184 (registration)
    Registration of the write_file tool with the MCP server using server.tool(). Includes tool name, description, input schema, and handler function.
    server.tool(
      'write_file',
      'Write or update a file in the project sandbox. Creates parent directories automatically.',
      {
        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")'),
        content: z.string().describe('File content to write'),
        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.writeFile(
            params.project_id,
            params.file_path,
            params.content,
            params.encoding,
          );
          return {
            content: [
              {
                type: 'text' as const,
                text: `Written: ${result.path}`,
              },
            ],
          };
        } catch (err: any) {
          return { content: [{ type: 'text' as const, text: `Error: ${err.message}` }], isError: true };
        }
      },
    );
  • The writeFile method in AICre8Client class that makes the actual HTTP PUT request to the API endpoint /projects/{projectId}/files/{filePath} with the file content and encoding.
    async writeFile(
      projectId: string,
      filePath: string,
      content: string,
      encoding?: 'utf-8' | 'base64',
    ): Promise<{ path: string; written: boolean }> {
      return this.request('PUT', `/projects/${projectId}/files/${filePath}`, {
        content,
        encoding,
      });
    }
Behavior4/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It effectively describes key behaviors: it performs write/update operations (implying mutation), automatically creates parent directories (a helpful implementation detail), and operates within a sandbox environment (suggesting isolation). However, it doesn't cover permissions, error conditions, or response format.

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 (two sentences) with zero wasted words. The first sentence states the core purpose, and the second adds valuable behavioral context. Every element earns its place.

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 mutation tool with no annotations and no output schema, the description provides adequate basic information about what the tool does and its automatic directory creation behavior. However, it lacks details about error handling, response format, or specific constraints that would be helpful for complete understanding.

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 already documents all four parameters thoroughly. The description adds no additional parameter information beyond what's in the schema, maintaining the baseline score of 3 for high schema coverage.

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 ('write or update a file'), the target resource ('in the project sandbox'), and includes a behavioral detail ('creates parent directories automatically'). It distinguishes itself from sibling tools like 'read_file' by specifying a write operation rather than a read operation.

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 file writing/updating in a project context, but provides no explicit guidance on when to use this tool versus alternatives like 'generate_code' or 'run_command'. It mentions the sandbox environment but doesn't clarify prerequisites or exclusions.

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