mcp-gdrive MCP Server

repository·main·Indexed 43 days ago

https://github.com/isaacphi/mcp-gdrive

An MCP server for interacting with Google Drive and Google Sheets, allowing LLMs to search, read, and edit files and spreadsheet data. It provides tools like gdrive_search, gdrive_read_file, gsheets_read, and gsheets_update_cell, and supports a custom gdrive:/// URI scheme for accessing files as resources. The server automatically converts Google Workspace files to compatible formats such as Markdown, CSV, and plain text.

Tokens
2K
Snippets
2
Records
14
Agent score
51%

What's inside mcp-gdrive

  1. Overview of the Google Drive MCP Server

    main

    The mcp-gdrive server integrates with Google Drive to enable file management and data manipulation via the Model Context Protocol (MCP). It allows users to list, read, and search files, and provides specific capabilities for interacting with Google Sheets and Google Docs.

    Key capabilities include:

    • File Search: Locate files within Google Drive.
    • File Reading: Access contents of various file types.
    • Google Sheets Integration: Read data from spreadsheets and update specific cell values.
    • Automatic Exporting: Google Workspace files are automatically converted for easier consumption:
      • Docs $\rightarrow$ Markdown
      • Sheets $\rightarrow$ CSV
      • Presentations $\rightarrow$ Plain text
      • Drawings $\rightarrow$ PNG
  2. Access Google Drive files as Resources

    main

    The server provides access to Google Drive files via a custom URI scheme. You can reference files using the following format:

    gdrive:///<file_id>

    This resource access supports all file types. As noted in the overview, Google Workspace files are automatically exported to compatible formats (Markdown, CSV, Plain text, or PNG) when accessed this way.

  3. Setup and Authentication for Google Drive MCP Server

    main

    To use this server, you must configure a Google Cloud project and provide OAuth credentials.

    1. Google Cloud Configuration

    1. Create a new Google Cloud project.
    2. Enable the Google Drive API.
    3. Configure an OAuth consent screen (set to "internal" for testing).
    4. Add these OAuth scopes:
      • https://www.googleapis.com/auth/drive.readonly
      • https://www.googleapis.com/auth/spreadsheets
    5. Enable the Google Sheets API and Google Docs API in your Google Cloud Console.
    6. Create an OAuth Client ID for type "Desktop App".
    7. Download the JSON key file, rename it to gcp-oauth.keys.json, and place it in the directory specified by your GDRIVE_CREDS_DIR environment variable.

    2. Environment Variables

    Set up a .env file or provide the following environment variables:

    • GDRIVE_CREDS_DIR: The path to the directory containing gcp-oauth.keys.json.
    • CLIENT_ID: Your OAuth Client ID.
    • CLIENT_SECRET: Your OAuth Client Secret.

    3. Initial Authentication

    Build the server using npm run build or npm run watch, then run the following command to trigger the browser-based authentication flow:

    node ./dist/index.js

    You must authenticate with an account in the same organization as your Google Cloud project. The resulting OAuth token will be saved in your GDRIVE_CREDS_DIR.

  4. Integrate Google Drive MCP Server with a Desktop App

    main

    To use the Google Drive MCP server within an MCP-compatible desktop application, add the following configuration to your mcpServers settings. Ensure you replace the placeholders with your actual credentials and paths.

    {
      "mcpServers": {
        "gdrive": {
          "command": "npx",
          "args": ["-y", "@isaacphi/mcp-gdrive"],
          "env": {
            "CLIENT_ID": "<CLIENT_ID>",
            "CLIENT_SECRET": "<CLIENT_SECRET>",
            "GDRIVE_CREDS_DIR": "/path/to/config/directory"
          }
        }
      }
    }
  5. Execute Google Drive operations via MCP Tools

    main

    The server exposes various tools through the ListToolsRequestSchema and CallToolRequestSchema handlers.

    To use a tool:

    1. Call ListToolsRequestSchema to discover available tool names, descriptions, and their inputSchema.
    2. Call CallToolRequestSchema with the desired name and the required arguments.

    The server handles authentication automatically before executing tools via ensureAuth().

  6. How the Google Drive MCP server works

    main

    The mcp-gdrive server implements the Model Context Protocol (MCP) to provide access to Google Drive via a standard interface. It exposes two primary capabilities:

    1. Resources: It uses the gdrive:/// URI scheme to represent files. Users can list available files and read their contents.
    2. Tools: It provides a set of tools (defined in the tools module) that allow for more complex interactions with the Drive API.

    The server uses StdioServerTransport for communication and requires valid Google credentials, which it manages via ensureAuth and setupTokenRefresh to handle token lifecycles automatically.

  7. Access Google Drive files as MCP Resources

    main

    The server supports the gdrive:/// URI scheme for interacting with files as resources:

    • Listing Resources: When ListResourcesRequestSchema is called, the server returns a list of files with their uri (formatted as gdrive:///{fileId}), mimeType, and name. It supports pagination via the cursor parameter.
    • Reading Resources: When ReadResourceRequestSchema is called with a URI like gdrive:///FILE_ID, the server retrieves the file content. Note that the current implementation specifically extracts text content by skipping the Contents of file: prefix provided by the internal tool response.
  8. Tools available in the Google Drive MCP Server

    main

    The server exposes the following tools for interacting with Google Drive and Google Sheets:

    Drive Tools

    • gdrive_search: Search for files.
      • Inputs: query (string), pageToken (string, optional), pageSize (number, optional, max 100).
      • Output: File names and MIME types.
    • gdrive_read_file: Read file contents.
      • Inputs: fileId (string).
      • Output: File contents.

    Sheets Tools

    • gsheets_read: Read spreadsheet data.
      • Inputs: spreadsheetId (string), ranges (array of strings, optional, e.g., ['Sheet1!A1:B10']), sheetId (number, optional).
      • Output: Spreadsheet data.
    • gsheets_update_cell: Update a single cell.
      • Inputs: fileId (string), range (string, e.g., 'Sheet1!A1'), value (string).
      • Output: Confirmation of the updated value.
  9. Access all available MCP tools

    main

    The tools array exports all available Model Context Protocol (MCP) tools provided by this server. Each tool object contains a schema (defining its name, description, and input parameters) and a handler function that executes the tool logic.

    Available tools:

    • gdrive_search (via search)
    • gdrive_read_file (via readFile)
    • gsheets_update_cell (via updateCell)
    • gsheets_read (via readSheet)
    import { tools } from './tools/index.js';
    
    // The tools array contains Tool objects with schemas and handlers
    for (const tool of tools) {
      console.log(tool.name);
      console.log(tool.inputSchema);
    }