Skip to main content
Glama

google_drive_get_file_content

Retrieve file content from Google Drive by providing the file ID. Integrates with AI clients via the Google MCP server for streamlined data access.

Instructions

Get the content of a file from Google Drive

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileIdYesID of the file to retrieve

Implementation Reference

  • Handler function that validates input arguments and delegates to GoogleDrive.getFileContent to execute the tool logic.
    export async function handleDriveGetFileContent(
      args: any,
      googleDriveInstance: GoogleDrive
    ) {
      if (!isGetFileContentArgs(args)) {
        throw new Error("Invalid arguments for google_drive_get_file_content");
      }
      const { fileId } = args;
      const result = await googleDriveInstance.getFileContent(fileId);
      return {
        content: [{ type: "text", text: result }],
        isError: false,
      };
    }
  • Core implementation in GoogleDrive class that interacts with Google Drive API to fetch file content, handling various MIME types appropriately.
    async getFileContent(fileId: string) {
      try {
        // First get the file metadata to check its type
        const fileMetadata = await this.drive.files.get({
          fileId: fileId,
          fields: "name,mimeType",
        });
    
        const { name, mimeType } = fileMetadata.data;
    
        // Handle text files directly
        if (
          mimeType === "text/plain" ||
          mimeType === "application/json" ||
          mimeType.includes("text/") ||
          mimeType.includes("application/javascript")
        ) {
          const response = await this.drive.files.get({
            fileId: fileId,
            alt: "media",
          });
    
          return `File: ${name}\nContent:\n\n${response.data}`;
        }
    
        // For Google Docs, get the content as plain text
        else if (
          mimeType === "application/vnd.google-apps.document" ||
          mimeType === "application/vnd.google-apps.spreadsheet"
        ) {
          let exportMimeType = "text/plain";
          if (mimeType === "application/vnd.google-apps.spreadsheet") {
            exportMimeType = "text/csv";
          }
    
          const response = await this.drive.files.export({
            fileId: fileId,
            mimeType: exportMimeType,
          });
    
          return `File: ${name}\nContent (exported as ${exportMimeType}):\n\n${response.data}`;
        }
    
        // For other file types, just return metadata
        else {
          return `File: ${name}\nType: ${mimeType}\nThis file type cannot be displayed as text. You can access it via Google Drive directly.`;
        }
      } catch (error) {
        throw new Error(
          `Failed to get file content: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
  • Tool schema defining the name, description, and input schema (requiring fileId).
    export const GET_FILE_CONTENT_TOOL: Tool = {
      name: "google_drive_get_file_content",
      description: "Get the content of a file from Google Drive",
      inputSchema: {
        type: "object",
        properties: {
          fileId: {
            type: "string",
            description: "ID of the file to retrieve",
          },
        },
        required: ["fileId"],
      },
    };
  • Registration in the main server switch statement that routes tool calls to the appropriate handler.
    case "google_drive_get_file_content":
      return await driveHandlers.handleDriveGetFileContent(
        args,
        googleDriveInstance
      );
  • Type guard function for runtime validation of tool input arguments.
    export function isGetFileContentArgs(args: any): args is {
      fileId: string;
    } {
      return args && typeof args.fileId === "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. It states the tool retrieves file content but lacks critical details: whether it requires specific permissions (e.g., read access), what formats are supported (e.g., text, binary), if there are rate limits, or how large files are handled. For a read operation with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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, clear sentence that directly states the tool's function without unnecessary words. It is front-loaded with the core action ('Get the content'), making it efficient and easy to parse. Every part of the sentence earns its place by conveying essential information.

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 complexity of file retrieval (which involves access control, format handling, and potential errors) and the lack of annotations and output schema, the description is insufficient. It doesn't explain what is returned (e.g., raw content, a download link, metadata), error conditions, or limitations. For a tool with no structured safety or output information, more context is needed to be complete.

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?

The input schema has 100% description coverage, with the single parameter 'fileId' documented as 'ID of the file to retrieve'. The description adds no additional meaning beyond this, such as examples of valid IDs or where to find them. With high schema coverage, the baseline score of 3 is appropriate, as the schema adequately explains the parameter without needing extra details in the description.

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 ('Get') and resource ('content of a file from Google Drive'), making the purpose immediately understandable. It distinguishes from siblings like google_drive_list_files (which lists metadata) and google_drive_get_file (which presumably retrieves metadata, though not in the sibling list). However, it doesn't explicitly differentiate from potential siblings like google_drive_download_file, which might serve a similar purpose.

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., file must exist, user must have access), nor does it contrast with siblings like google_drive_list_files (for browsing) or google_drive_update_file (for modifications). Usage is implied only by the tool name and description, with no explicit context 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

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