google-drive-mcp-server

tammy-rb/google-drive-mcp-server

3.1

If you are the rightful owner of google-drive-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server that provides secure access to Google Drive files, allowing users to list, search, and read files through the MCP protocol.

Tools
3
Resources
0
Prompts
0

Google Drive MCP Server

A Model Context Protocol (MCP) server that provides secure access to Google Drive files. This server allows you to list, search, and read files from your Google Drive through the MCP protocol.

Features

  • 📁 List Drive Files: Browse files with pagination and filtering
  • 🔍 Search Files: Search by file name or content
  • 📖 Read Files: Access file content with automatic format conversion
  • 🔐 Secure Authentication: OAuth 2.0 with Google Drive API
  • 🏗️ MCP Protocol: Standard Model Context Protocol implementation

Setup

Prerequisites

  • Python 3.8+
  • Google Cloud Platform account
  • Google Drive API credentials

1. Install Dependencies

Using uv (recommended):

# Install uv if you haven't already
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# Navigate to project directory
cd gdrive-mcp

# Create virtual environment and install dependencies
uv venv
.venv\Scripts\activate
uv add mcp[cli] httpx google-api-python-client google-auth google-auth-oauthlib python-dotenv

2. Google Drive API Setup

  1. Go to Google Cloud Console
  2. Create a new project or select existing one
  3. Enable the Google Drive API
  4. Create OAuth 2.0 credentials:
    • Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client IDs"
    • Choose "Desktop application"
    • Download the JSON file
  5. Save the JSON file as credentials/gcp-oauth.keys.json

3. Configuration

The server will automatically handle OAuth authentication on first run. Make sure your credentials/gcp-oauth.keys.json file is properly configured.

Usage

Running the MCP Server

# Activate virtual environment
.venv\Scripts\activate

# Run the server
python gdrive_server.py

Testing the Server

# Run the test client
python test_client.py

Using with MCP Clients

The server implements the standard MCP protocol and can be used with any MCP-compatible client.

Available Tools
  1. list_drive_files

    • List files in Google Drive
    • Parameters: page_size (int), cursor (string), query (string)
  2. read_drive_file

    • Read content of a specific file
    • Parameters: file_id (string, required)
  3. search_drive_files

    • Search for files by name or content
    • Parameters: query (string, required), page_size (int)
Available Resources
  • gdrive://files - Lists recent files from Google Drive

Project Structure

gdrive-mcp/
├── credentials/
│   ├── gcp-oauth.keys.json          # Google OAuth credentials
│   └── .gdrive-server-credentials.json  # Saved user tokens (auto-generated)
├── gdrive_server.py                 # Main MCP server implementation
├── test_client.py                   # Test client for the server
├── agent.py                         # Original agent implementation
├── pyproject.toml                   # Project configuration
└── README.md                        # This file

File Types Supported

The server automatically handles different Google Drive file types:

  • Google Docs: Exported as Markdown
  • Google Sheets: Exported as CSV
  • Google Slides: Exported as plain text
  • Text files: Read directly
  • Binary files: Base64 encoded

Authentication Flow

  1. First run will open browser for OAuth consent
  2. Credentials are saved locally for future use
  3. Server uses read-only access to your Google Drive

Security Notes

  • Server only requests read-only access to Google Drive
  • Credentials are stored locally and never transmitted
  • OAuth tokens are securely managed by Google's client libraries

Troubleshooting

Common Issues

  1. Authentication Error: Ensure gcp-oauth.keys.json is valid and properly placed
  2. Permission Denied: Check that Google Drive API is enabled in your GCP project
  3. File Not Found: Verify file IDs and that files exist in your Drive

Debug Mode

Enable debug logging by setting the environment variable:

export LOG_LEVEL=DEBUG

Development

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test with the provided test client
  5. Submit a pull request

Adding New Features

The server is built with extensibility in mind. To add new tools:

  1. Define a new Pydantic model for arguments
  2. Add the tool definition in list_tools()
  3. Implement the tool logic in call_tool()
  4. Add corresponding implementation function

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects