Skip to main content
Glama

google_drive_create_file

Create and save new files directly in Google Drive by specifying the file name, content, MIME type, and folder location. Integrates with Google MCP for efficient file management.

Instructions

Create a new file in Google Drive

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesContent of the file
folderIdNoID of the folder to create the file in
mimeTypeNoMIME type of the file (e.g., 'text/plain', 'application/vnd.google-apps.document')
nameYesName of the file to create

Implementation Reference

  • The MCP tool handler function that validates input arguments using isCreateFileArgs and delegates the file creation to the GoogleDrive instance's createFile method, returning the result in the expected format.
    export async function handleDriveCreateFile(
      args: any,
      googleDriveInstance: GoogleDrive
    ) {
      if (!isCreateFileArgs(args)) {
        throw new Error("Invalid arguments for google_drive_create_file");
      }
      const { name, content, mimeType, folderId } = args;
      const result = await googleDriveInstance.createFile(
        name,
        content,
        mimeType,
        folderId
      );
      return {
        content: [{ type: "text", text: result }],
        isError: false,
      };
    }
  • The Tool object definition providing the name, description, and inputSchema (JSON Schema) for the google_drive_create_file tool.
    export const CREATE_FILE_TOOL: Tool = {
      name: "google_drive_create_file",
      description: "Create a new file in Google Drive",
      inputSchema: {
        type: "object",
        properties: {
          name: {
            type: "string",
            description: "Name of the file to create",
          },
          content: {
            type: "string",
            description: "Content of the file",
          },
          mimeType: {
            type: "string",
            description:
              "MIME type of the file (e.g., 'text/plain', 'application/vnd.google-apps.document')",
          },
          folderId: {
            type: "string",
            description: "ID of the folder to create the file in",
          },
        },
        required: ["name", "content"],
      },
    };
  • The switch case in the main CallToolRequestSchema handler that registers and routes calls to the specific drive handler function.
    case "google_drive_create_file":
      return await driveHandlers.handleDriveCreateFile(
        args,
        googleDriveInstance
      );
  • The core implementation in GoogleDrive class that uses Google Drive API v3 to create files, handling both Google Apps mimeTypes and regular files with media body, optionally in a folder.
    async createFile(
      name: string,
      content: string,
      mimeType: string = "text/plain",
      folderId?: string
    ) {
      try {
        const fileMetadata: any = {
          name: name,
        };
    
        if (folderId) {
          fileMetadata.parents = [folderId];
        }
    
        // If creating a Google Doc, Spreadsheet, etc.
        if (mimeType.includes("application/vnd.google-apps")) {
          const response = await this.drive.files.create({
            requestBody: fileMetadata,
            fields: "id,name,webViewLink",
            mimeType: mimeType,
          });
    
          const { id, webViewLink } = response.data;
          return `Created ${mimeType} with name: ${name}\nID: ${id}\nLink: ${webViewLink}`;
        }
    
        // For regular files with content
        const response = await this.drive.files.create({
          requestBody: fileMetadata,
          media: {
            mimeType: mimeType,
            body: content,
          },
          fields: "id,name,webViewLink",
        });
    
        const { id, webViewLink } = response.data;
        return `Created file with name: ${name}\nID: ${id}\nLink: ${
          webViewLink || "N/A"
        }`;
      } catch (error) {
        throw new Error(
          `Failed to create file: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • Type guard function for input validation matching the tool's inputSchema, used in the handler to check arguments before execution.
    export function isCreateFileArgs(args: any): args is {
      name: string;
      content: string;
      mimeType?: string;
      folderId?: string;
    } {
      return (
        args &&
        typeof args.name === "string" &&
        typeof args.content === "string" &&
        (args.mimeType === undefined || typeof args.mimeType === "string") &&
        (args.folderId === undefined || typeof args.folderId === "string")
      );
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Create' implies a write operation, it doesn't describe permissions required, whether the operation is idempotent, rate limits, error conditions, or what happens on success (e.g., returns file ID). For a mutation tool with zero annotation coverage, this leaves significant behavioral 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 a single, efficient sentence with zero waste. It's front-loaded with the core purpose and appropriately sized for a tool with good schema coverage. Every word earns its place without redundancy.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like permissions, error handling, or return values, and while the schema covers parameters well, the overall context for safe and effective use is lacking. This is inadequate for a 4-parameter creation tool.

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 4 parameters with clear descriptions. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain parameter interactions or provide examples). Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('Create') and resource ('new file in Google Drive'), making the purpose immediately understandable. It distinguishes from siblings like 'google_drive_update_file' or 'google_drive_delete_file' by specifying creation. However, it doesn't explicitly mention what type of file or provide specific scope details beyond the basic verb+resource.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., authentication needs, folder permissions), when not to use it (e.g., for updating existing files), or refer to sibling tools like 'google_drive_update_file' for modifications. Usage is implied by the name but not explicitly stated.

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/vakharwalad23/google-mcp'

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