gdrive-mcp-server
by: felores
Efficient implementation of the Google Drive MCP server
πOverview
Purpose: The Google Drive MCP Server aims to facilitate seamless integration with Google Drive, allowing AI models to efficiently search, list, and read files stored in Google Drive.
Overview: This powerful Model Context Protocol (MCP) server enhances interaction with Google Drive, providing advanced functionalities for file management and content retrieval directly from the cloud. With built-in support for multiple file formats and robust authentication mechanisms, it streamlines the process of accessing and manipulating Google Drive files.
Key Features:
-
File Search (
gdrive_search
): Offers powerful full-text search capabilities, returning relevant files including their names, MIME types, IDs, modification times, and sizes based on user queries. -
File Reading (
gdrive_read_file
): Allows users to read contents of files directly using their Google Drive file IDs, with automatic format conversions for various Google Workspace file types, enhancing usability and accessibility of content.
Google Drive MCP Server
A powerful Model Context Protocol (MCP) server that provides seamless integration with Google Drive, allowing AI models to search, list, and read files from Google Drive.
π Features
Tools
1. gdrive_search
Search for files in your Google Drive with powerful full-text search capabilities.
- Input:
{ "query": "string (your search query)" }
- Output: List of files with:
- File name
- MIME type
- File ID
- Last modified time
- File size
2. gdrive_read_file
Read file contents directly using a Google Drive file ID.
- Input:
{ "file_id": "string (Google Drive file ID)" }
- Output: File contents with appropriate format conversion
Automatic File Format Handling
The server intelligently handles different Google Workspace file types:
- Google Docs β Markdown
- Google Sheets β CSV
- Google Presentations β Plain text
- Google Drawings β PNG
- Text/JSON files β UTF-8 text
- Other files β Base64 encoded
π οΈ Getting Started
Prerequisites
- Node.js (v16 or higher)
- npm or yarn
- A Google Cloud Project
- A Google Workspace or personal Google account
Google Cloud Setup
-
Create a Google Cloud Project
- Visit Google Cloud Console
- Click "New Project"
- Enter project name (e.g., "MCP GDrive Server")
- Click "Create" and select the project
-
Enable the Google Drive API
- Go to API Library
- Search for "Google Drive API"
- Click "Enable"
-
Configure OAuth Consent Screen
- Select User Type: "Internal" (Google Workspace) or "External" (personal)
- Fill in required fields (App name, support email, developer email)
- Add OAuth scope:
https://www.googleapis.com/auth/drive.readonly
-
Create OAuth Client ID
- Go to Credentials
- Click "Create Credentials" β "OAuth client ID"
- Choose Application type: "Desktop app"
- Name it and create
- Download the JSON file
-
Set Up Credentials in Project
mkdir credentials mv path/to/downloaded/client_secret_*.json credentials/gcp-oauth.keys.json
Installation
git clone https://github.com/felores/gdrive-mcp-server.git
cd gdrive-mcp-server
npm install
npm run build
Authentication
-
Place your OAuth JSON file as
credentials/gcp-oauth.keys.json
mkdir credentials # Move your OAuth JSON file here and rename
-
Run authentication command:
node dist/index.js auth
-
Complete the OAuth flow in your browser
-
Credentials saved in
credentials/.gdrive-server-credentials.json
π§ Usage
As a Command Line Tool
node dist/index.js
Integration with Desktop App
Add the following configuration to your app's server settings (replace paths appropriately):
{
"mcpServers": {
"gdrive": {
"command": "node",
"args": ["path/to/gdrive-mcp-server/dist/index.js"],
"env": {
"GOOGLE_APPLICATION_CREDENTIALS": "path/to/gdrive-mcp-server/credentials/gcp-oauth.keys.json",
"MCP_GDRIVE_CREDENTIALS": "path/to/gdrive-mcp-server/credentials/.gdrive-server-credentials.json"
}
}
}
}
Example Usage
-
Search for files:
const result = await gdrive_search({ query: "quarterly report" });
-
Read file contents:
const contents = await gdrive_read_file({ file_id: "your-file-id" });
π Security
- Credentials stored in the
credentials
directory - OAuth credentials and tokens are excluded from version control
- Read-only access to Google Drive
- Secure OAuth 2.0 authentication flow
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π License
This MCP server is licensed under the MIT License. See the LICENSE file for details.
π Troubleshooting
- Verify Google Cloud Project setup
- Ensure OAuth scopes are enabled
- Confirm credentials are correctly placed
- Check file permissions and access rights in Google Drive