google-drive-mcp

enablis-co/google-drive-mcp

3.2

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

A Model Context Protocol (MCP) server that syncs any Google Drive folder and makes it searchable to AI assistants with powerful semantic search capabilities.

Tools
9
Resources
0
Prompts
0

Google Drive MCP Server

A Model Context Protocol (MCP) server that syncs any Google Drive folder and makes it searchable to AI assistants with powerful semantic search capabilities.

Architecture

This server uses a local sync approach:

  • Downloads documents from any Google Drive folder to local storage
  • Extracts text content from PDFs, Google Docs, and other documents
  • Auto-syncs every 6 hours to stay updated
  • Provides fast queries through local indexing with semantic search
  • Works offline once synced

Features

Semantic Search

  • Meaning-based search using transformer embeddings (runs locally, no API keys needed)
  • Understands context and meaning, not just keywords
  • Returns relevance scores and matched sections
  • Ideal for natural language queries like "What are the key requirements for access control?"

Duplicate Detection

  • Find where concepts or content are defined multiple times
  • Similarity scoring to identify near-duplicates
  • Section-by-section comparison across documents

Cross-Reference Analysis

  • Automatically extract document references (ISO standards, RFC documents, IEEE standards, NIST publications, custom document IDs)
  • Analyze which documents reference other standards/documents
  • See context around each reference

MCP Resources

  • Exposes each document as a resource (gdrive:///{document-id})
  • Documents can be read directly by AI assistants

MCP Tools

Search & Discovery
  1. search_documents - Smart search using semantic understanding (meaning-based) with fallback to keyword matching
  2. semantic_search - Advanced semantic search with relevance scores and matched sections
  3. list_documents - List all available documents with metadata
  4. get_document - Get full content of a specific document
Duplicate Detection & Analysis
  1. find_duplicates - Find duplicate or similar content across documents
  2. analyze_cross_references - Analyze document references across all documents (ISO, RFC, IEEE, NIST, custom IDs)
  3. get_document_references - Extract all document references from a specific document with context
Sync Management
  1. sync_documents - Manually trigger a sync from Google Drive
  2. get_sync_status - Check sync status and statistics

Setup

1. Google Cloud Console Setup

  1. Go to Google Cloud Console
  2. Create a new project (or select existing)
  3. Enable the Google Drive API:
    • Navigate to "APIs & Services" → "Library"
    • Search for "Google Drive API"
    • Click "Enable"
  4. Create OAuth 2.0 credentials:
    • Go to "APIs & Services" → "Credentials"
    • Click "Create Credentials" → "OAuth client ID"
    • Choose "Desktop app" as application type
    • Download the credentials JSON file
    • Save it as credentials.json in the project root

2. Install Dependencies

npm install

3. Authenticate with Google Drive

npm run build
node dist/setup-auth.js

This will:

  • Open a browser for Google authentication (if it lands on a page not found, update the url to have port 3000 and hit enter)
  • Generate a token.json file for future access
  • The token will be saved locally and reused
  • Token Refresh: Access tokens expire after ~1 hour but are automatically refreshed using the refresh token and persisted to disk

4. Configure Google Drive Folder

Find the folder ID of your Google Drive folder:

  • Open the folder in Google Drive
  • The URL will look like: https://drive.google.com/drive/folders/FOLDER_ID_HERE
  • Copy the FOLDER_ID

Set the environment variable:

export GOOGLE_DRIVE_FOLDER_ID="your-folder-id-here"

Or create a .env file (optional - you can load it with dotenv if needed):

# Copy the example file
cp .env.example .env

# Then edit .env and add your folder ID
GOOGLE_DRIVE_FOLDER_ID=your-folder-id-here

5. Run the MCP Server

npm run dev

On first run, it will sync all documents from Google Drive.

Using with Claude Desktop

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "google-drive": {
      "command": "node",
      "args": ["/path/to/google-drive-mcp/dist/index.js"],
      "env": {
        "GOOGLE_DRIVE_FOLDER_ID": "your-folder-id-here"
      }
    }
  }
}

Restart Claude Desktop, and your Google Drive documents will be available!

Development

# Build TypeScript
npm run build

# Watch mode
npm run watch

# Run server
npm start

File Structure

google-drive-mcp/
├── src/
│   ├── index.ts              # Main entry point
│   ├── types.ts              # TypeScript type definitions
│   ├── google-drive-sync.ts  # Google Drive sync logic
│   ├── semantic-search.ts    # Semantic search implementation
│   ├── mcp-server.ts         # MCP server implementation
│   ├── setup-auth.ts         # Authentication setup script
│   ├── manual-auth.ts        # Manual authentication (fallback)
│   └── complete-auth.ts      # Complete auth with code
├── storage/                  # Local document storage (created on first run)
│   ├── documents.json        # Document metadata database
│   └── [file-ids]            # Downloaded documents
├── credentials.json          # Google OAuth credentials (you provide)
├── token.json               # Google OAuth token (auto-generated)
├── package.json
├── tsconfig.json
└── README.md

How It Works

  1. Initial Sync: On startup, downloads all documents from the specified Google Drive folder
  2. Text Extraction: Extracts searchable text from PDFs and Google Docs
  3. Semantic Indexing: Builds semantic search indexes using transformer embeddings
  4. Local Storage: Stores documents locally for fast access
  5. Auto-Sync: Checks for updates every 6 hours
  6. MCP Interface: Exposes documents and search capabilities via MCP protocol
  7. AI Integration: AI assistants can search, read, and reference your documents

Supported File Types

  • PDF documents (with text extraction)
  • Google Docs (exported as text)
  • Google Sheets (exported as CSV)
  • Google Slides (exported as text)
  • Plain text files
  • Other file types (downloaded but text extraction may not be available)

Security Notes

  • credentials.json and token.json contain sensitive data - never commit them
  • The server only requests read-only access to Google Drive
  • Documents are stored locally in the storage/ directory
  • Ensure proper file permissions on the storage directory
  • Token Refresh: Access tokens expire after ~1 hour but are automatically refreshed using the refresh token and persisted to disk, so the server continues working without re-authentication

Troubleshooting

"No token found" error

Run the setup script: node dist/setup-auth.js

"GOOGLE_DRIVE_FOLDER_ID is required" error

Set the environment variable with your folder ID

Documents not syncing

  • Check the folder ID is correct
  • Ensure the Google account has access to the folder
  • Check network connectivity
  • Run sync_documents tool manually to see detailed errors

PDF text extraction failing

Some PDFs may be scanned images without text. Consider using OCR tools for these documents.

Authentication errors after server has been running

If you see authentication errors after the server has been running for a while:

  • The server automatically refreshes expired access tokens and saves them to token.json
  • If the refresh token itself expires (after ~6 months of no use), you'll need to re-authenticate: node dist/setup-auth.js
  • Check the token.json file has a valid refresh_token field

Use Cases

This MCP server is perfect for:

  • Documentation Libraries: Make your team's documentation searchable
  • ISO/Compliance Documents: Search ISO standards, compliance docs, and policies
  • Research Papers: Index and search academic papers
  • Technical Specs: Query technical specifications and standards
  • Legal Documents: Search contracts, agreements, and legal docs
  • Knowledge Bases: Any collection of documents that need intelligent search

AI Query Examples

Once connected to Claude or another AI assistant, you can ask questions like:

  • "What documents mention risk assessment?"
  • "Find all documents that discuss data encryption"
  • "Where is the backup policy defined?"
  • "Show me all references to ISO 27001 across the documents"
  • "What documents are similar to each other?"
  • "Find duplicate content in the policy documents"

Future Enhancements

  • Incremental sync (only changed files)
  • OCR for scanned PDFs
  • Document versioning
  • Document categorization and tagging
  • Query expansion and synonym handling
  • Multi-language support
  • Support for additional file formats
  • Custom reference pattern configuration

License

MIT