cnye36/gdrive-mcp-server
If you are the rightful owner of gdrive-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 dayong@mcphub.com.
A comprehensive Model Context Protocol (MCP) server for Google Drive with full OAuth authentication, read/write operations, and Docker support.
Google Drive MCP Server
A comprehensive Model Context Protocol (MCP) server for Google Drive with full OAuth authentication, read/write operations, and Docker support.
Features
Read Operations
- list_files - List files and folders with optional filtering
- get_file - Get detailed metadata for a specific file
- download_file - Download file content (supports export for Google Docs)
- search_files - Search files by name
- get_permissions - View sharing permissions for a file
Write Operations
- create_file - Create new files with content
- update_file - Update existing file content
- delete_file - Delete files
- create_folder - Create new folders
- copy_file - Create copies of files
- move_file - Move files between folders
- share_file - Share files with other users
Prerequisites
- Node.js 20+ and pnpm installed
- Google Cloud Project with Drive API enabled
- OAuth 2.0 credentials from Google Cloud Console
Google Cloud Setup
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Drive API:
- Navigate to "APIs & Services" > "Library"
- Search for "Google Drive API"
- Click "Enable"
- Create OAuth 2.0 credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Web application"
- Add authorized redirect URI:
http://localhost:3000/oauth/callback - Save the Client ID and Client Secret
Installation
Local Development
-
Clone or download this repository
-
Install dependencies:
pnpm install -
Create
.envfile from the example:cp .env.example .env -
Edit
.envwith your credentials:PORT=3000 NODE_ENV=development GOOGLE_CLIENT_ID=your_client_id_here.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=your_client_secret_here GOOGLE_REDIRECT_URI=http://localhost:3000/oauth/callback -
Build the TypeScript code:
pnpm run build -
Start the server:
pnpm start
Docker Deployment
-
Create
.envfile with your credentials (as above) -
Build and run with Docker Compose:
docker-compose up -d -
View logs:
docker-compose logs -f -
Stop the server:
docker-compose down
Authentication
First-Time Setup
- Start the server (local or Docker)
- Visit
http://localhost:3000/oauth/urlto get the authorization URL - Open the URL in your browser and authorize the application
- You'll be redirected back to the callback URL
- The tokens will be saved automatically
Check Authentication Status
curl http://localhost:3000/health
Response:
{
"status": "ok",
"authenticated": true,
"timestamp": "2025-10-21T12:00:00.000Z"
}
Usage
HTTP API Endpoints
Health Check
GET http://localhost:3000/health
Get OAuth URL
GET http://localhost:3000/oauth/url
List Available Tools
GET http://localhost:3000/mcp/tools
Execute a Tool
POST http://localhost:3000/mcp/execute
Content-Type: application/json
{
"tool": "list_files",
"arguments": {
"pageSize": 10
}
}
Example API Calls
List Files
curl -X POST http://localhost:3000/mcp/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "list_files",
"arguments": {
"pageSize": 20
}
}'
Search Files
curl -X POST http://localhost:3000/mcp/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "search_files",
"arguments": {
"query": "budget",
"pageSize": 10
}
}'
Create a File
curl -X POST http://localhost:3000/mcp/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "create_file",
"arguments": {
"name": "test.txt",
"content": "Hello, World!",
"mimeType": "text/plain"
}
}'
Download a File
curl -X POST http://localhost:3000/mcp/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "download_file",
"arguments": {
"fileId": "1234567890abcdef"
}
}'
Create a Folder
curl -X POST http://localhost:3000/mcp/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "create_folder",
"arguments": {
"name": "My New Folder"
}
}'
Share a File
curl -X POST http://localhost:3000/mcp/execute \
-H "Content-Type: application/json" \
-d '{
"tool": "share_file",
"arguments": {
"fileId": "1234567890abcdef",
"email": "user@example.com",
"role": "reader"
}
}'
Tool Reference
list_files
List files in Google Drive.
Arguments:
pageSize(number, optional): Number of files to return (default: 10)query(string, optional): Google Drive query stringfolderId(string, optional): ID of folder to list files from
get_file
Get metadata for a specific file.
Arguments:
fileId(string, required): The ID of the file
download_file
Download file content.
Arguments:
fileId(string, required): The ID of the fileexportMimeType(string, optional): For Google Docs, export format
search_files
Search for files by name.
Arguments:
query(string, required): Search querypageSize(number, optional): Number of results (default: 10)
create_file
Create a new file.
Arguments:
name(string, required): File namecontent(string, required): File contentmimeType(string, required): MIME typeparentId(string, optional): Parent folder ID
update_file
Update file content.
Arguments:
fileId(string, required): The ID of the filecontent(string, required): New contentmimeType(string, optional): MIME type
delete_file
Delete a file.
Arguments:
fileId(string, required): The ID of the file
create_folder
Create a new folder.
Arguments:
name(string, required): Folder nameparentId(string, optional): Parent folder ID
copy_file
Copy a file.
Arguments:
fileId(string, required): The ID of the filenewName(string, required): Name for the copyparentId(string, optional): Destination folder ID
move_file
Move a file to another folder.
Arguments:
fileId(string, required): The ID of the filenewParentId(string, required): Destination folder ID
share_file
Share a file with another user.
Arguments:
fileId(string, required): The ID of the fileemail(string, required): Email addressrole(string, optional): "reader", "writer", or "commenter" (default: "reader")
get_permissions
Get sharing permissions for a file.
Arguments:
fileId(string, required): The ID of the file
Project Structure
google-drive-mcp/
├── src/
│ ├── index.ts # HTTP server with Express
│ ├── google-drive-client.ts # Google Drive API wrapper
│ └── mcp-server.ts # MCP server implementation
├── Dockerfile
├── docker-compose.yml
├── package.json
├── tsconfig.json
├── .env.example
└── README.md
Development
Run in Development Mode
pnpm run dev
Build TypeScript
pnpm run build
Clean Build Files
pnpm run clean
Security Considerations
- Never commit
.envor.tokens.jsonfiles - Restrict OAuth scopes if you don't need full Drive access
- Use environment variables for all sensitive data
- Rotate credentials regularly
- Enable HTTPS in production environments
Troubleshooting
"Not authenticated" error
- Check if
.tokens.jsonexists - Visit
/oauth/urlto re-authenticate - Verify your OAuth credentials in
.env
Docker container won't start
- Check logs:
docker-compose logs - Verify
.envfile exists and is properly formatted - Ensure port 3000 is available
API errors
- Check Google Cloud Console for API quota limits
- Verify the Drive API is enabled
- Check token expiration in
.tokens.json
License
MIT
Contributing
Contributions are welcome! Please open an issue or submit a pull request.