diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..d32102bf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Google MCP Credentials +credentials.json +*-credentials.json +google-credentials*.json + +# MCP Configuration (may contain sensitive paths) +mcp_settings.json +claude_desktop_config.json + +# Backup files +*.backup.* diff --git a/CREDENTIALS_GUIDE.md b/CREDENTIALS_GUIDE.md new file mode 100644 index 000000000..ebd602b5c --- /dev/null +++ b/CREDENTIALS_GUIDE.md @@ -0,0 +1,406 @@ +# Google Cloud Credentials Setup Guide + +This guide provides detailed instructions for obtaining and configuring Google Cloud credentials for the MCP connection. + +## Table of Contents +1. [Creating a Google Cloud Project](#creating-a-google-cloud-project) +2. [Enabling Required APIs](#enabling-required-apis) +3. [Service Account Setup](#service-account-setup) +4. [OAuth Setup (Optional)](#oauth-setup-optional) +5. [Security Best Practices](#security-best-practices) + +--- + +## Creating a Google Cloud Project + +### Step 1: Access Google Cloud Console +1. Go to [Google Cloud Console](https://console.cloud.google.com/) +2. Sign in with your Google account +3. Accept the Terms of Service if prompted + +### Step 2: Create New Project +1. Click the project dropdown at the top of the page +2. Click **"New Project"** +3. Enter project details: + - **Project name**: e.g., "MCP Google Integration" + - **Organization**: (optional) Select your organization + - **Location**: (optional) Select parent folder +4. Click **"Create"** +5. Wait for the project to be created (usually takes a few seconds) + +### Step 3: Note Your Project ID +- Your Project ID will be displayed (e.g., `mcp-integration-123456`) +- **Save this** - you'll need it for API calls and billing + +--- + +## Enabling Required APIs + +You need to enable the Google APIs you plan to use. Here's how: + +### Method 1: Via Console UI + +1. In Google Cloud Console, select your project +2. Navigate to **"APIs & Services" > "Library"** +3. Search for and enable each of these APIs: + +#### Essential APIs: +- ? **Google Drive API** - For file access and management + - Search: "Google Drive API" + - Click "Enable" + +- ? **Gmail API** - For email operations + - Search: "Gmail API" + - Click "Enable" + +- ? **Google Calendar API** - For calendar management + - Search: "Google Calendar API" + - Click "Enable" + +#### Optional APIs: +- ?? **Google Maps Platform** - For location services + - Enable: Maps JavaScript API, Places API, Geocoding API + +- ?? **Custom Search API** - For web search + - Search: "Custom Search API" + - Note: Requires additional setup + +### Method 2: Via gcloud CLI + +If you have gcloud CLI installed: + +```bash +# Set your project +gcloud config set project YOUR_PROJECT_ID + +# Enable APIs +gcloud services enable drive.googleapis.com +gcloud services enable gmail.googleapis.com +gcloud services enable calendar-json.googleapis.com +gcloud services enable maps-backend.googleapis.com +gcloud services enable customsearch.googleapis.com +``` + +### Verify Enabled APIs +```bash +gcloud services list --enabled +``` + +--- + +## Service Account Setup + +Service accounts are used for application-level access (recommended for most MCP use cases). + +### Step 1: Create Service Account + +1. Navigate to **"IAM & Admin" > "Service Accounts"** +2. Click **"Create Service Account"** +3. Fill in details: + ``` + Service account name: mcp-google-connector + Service account ID: mcp-google-connector (auto-generated) + Description: Service account for MCP Google integration + ``` +4. Click **"Create and Continue"** + +### Step 2: Grant Permissions + +Choose the appropriate roles based on your needs: + +#### For Google Drive: +- **Basic Access**: `roles/drive.reader` (read-only) +- **Full Access**: `roles/drive.admin` or `roles/drive.file` (read/write) + +#### For Gmail: +- **Basic Access**: `roles/gmail.readonly` +- **Full Access**: `roles/gmail.admin` + +#### For Google Calendar: +- **Basic Access**: `roles/calendar.reader` +- **Full Access**: `roles/calendar.admin` + +**Recommendation**: Start with read-only access and expand as needed. + +### Step 3: Create and Download JSON Key + +1. After creating the service account, click on it +2. Go to the **"Keys"** tab +3. Click **"Add Key" > "Create New Key"** +4. Select **"JSON"** as the key type +5. Click **"Create"** +6. The JSON key file will automatically download + - Filename format: `PROJECT_ID-RANDOM_STRING.json` + +### Step 4: Secure the Credentials + +**CRITICAL SECURITY STEP:** + +```bash +# Create secure directory +mkdir -p ~/.config/google-mcp + +# Move the downloaded file +mv ~/Downloads/your-project-*-*.json ~/.config/google-mcp/credentials.json + +# Set strict permissions (owner read/write only) +chmod 600 ~/.config/google-mcp/credentials.json + +# Verify permissions +ls -l ~/.config/google-mcp/credentials.json +# Should show: -rw------- (owner read/write only) +``` + +### Step 5: Understanding the Credentials File + +Your JSON key file contains: + +```json +{ + "type": "service_account", + "project_id": "your-project-id", + "private_key_id": "key-id", + "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n", + "client_email": "service-account@project.iam.gserviceaccount.com", + "client_id": "123456789", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/..." +} +``` + +**Never share or commit this file!** + +--- + +## OAuth Setup (Optional) + +Use OAuth for user-specific data access (e.g., accessing a specific user's Gmail). + +### When to Use OAuth vs Service Account + +| Use Case | Recommendation | +|----------|----------------| +| Access your own Drive files | OAuth | +| Access organization Drive | Service Account | +| Read/send personal Gmail | OAuth | +| Application-level access | Service Account | +| Multiple user access | OAuth | + +### Step 1: Create OAuth Client ID + +1. Navigate to **"APIs & Services" > "Credentials"** +2. Click **"Create Credentials" > "OAuth Client ID"** +3. If prompted, configure the OAuth consent screen: + - User Type: **"External"** (for personal use) or **"Internal"** (for organization) + - Fill in required fields (App name, User support email) + - Add scopes you need + - Add test users (for external apps) + +4. For Application Type, select **"Desktop App"** +5. Name it (e.g., "MCP Google OAuth") +6. Click **"Create"** +7. Download the JSON file + +### Step 2: OAuth Scopes + +Configure the scopes your application needs: + +``` +# Google Drive +https://www.googleapis.com/auth/drive.readonly +https://www.googleapis.com/auth/drive + +# Gmail +https://www.googleapis.com/auth/gmail.readonly +https://www.googleapis.com/auth/gmail.modify + +# Calendar +https://www.googleapis.com/auth/calendar.readonly +https://www.googleapis.com/auth/calendar +``` + +### Step 3: Configure MCP with OAuth + +Update your MCP configuration: + +```json +{ + "mcpServers": { + "google": { + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-google"], + "env": { + "GOOGLE_OAUTH_CLIENT_ID": "your-client-id.apps.googleusercontent.com", + "GOOGLE_OAUTH_CLIENT_SECRET": "your-client-secret", + "GOOGLE_OAUTH_REDIRECT_URI": "http://localhost:3000/oauth/callback" + } + } + } +} +``` + +### Step 4: First-Time Authorization + +1. The first time you use the MCP connection, you'll be prompted to authorize +2. A browser window will open +3. Sign in with your Google account +4. Review and accept the requested permissions +5. The access token will be stored securely + +--- + +## Security Best Practices + +### ? DO: + +1. **Use least privilege principle** + - Only grant the minimum required permissions + - Start with read-only access + +2. **Secure your credentials** + ```bash + # Proper permissions + chmod 600 ~/.config/google-mcp/credentials.json + + # Add to .gitignore + echo "credentials.json" >> .gitignore + echo "*.json" >> .gitignore + ``` + +3. **Rotate keys regularly** + - Generate new service account keys every 90 days + - Delete old keys after rotation + +4. **Monitor usage** + - Check Google Cloud Console for unexpected API calls + - Set up billing alerts + - Review service account activity logs + +5. **Use separate service accounts** + - One per application or environment + - Makes debugging and auditing easier + +### ? DON'T: + +1. **Never commit credentials to version control** + ```bash + # Check for accidentally committed credentials + git log --all --full-history -- "*credentials*" + ``` + +2. **Never share credentials** + - Don't send via email, chat, or cloud storage + - Don't embed in code or documentation + +3. **Never use production credentials for testing** + - Create separate projects for dev/test/prod + +4. **Never grant excessive permissions** + - Avoid "Owner" or "Editor" roles unless absolutely necessary + +### ?? Auditing + +Regularly review: +- Service account key age (rotate old keys) +- Granted permissions (remove unused permissions) +- API usage (detect anomalies) +- Access logs (check for unauthorized access) + +--- + +## Troubleshooting + +### Error: "The caller does not have permission" + +**Solution**: Add the required role to your service account: +1. Go to **IAM & Admin > IAM** +2. Find your service account +3. Click edit (pencil icon) +4. Add the necessary role +5. Save + +### Error: "API not enabled" + +**Solution**: Enable the API: +```bash +gcloud services enable [API_NAME].googleapis.com +``` + +Or via console: **APIs & Services > Library** + +### Error: "Invalid grant" + +**Possible causes**: +- Service account key has been deleted +- Project has been disabled +- System clock is out of sync + +**Solution**: Generate a new key or check project status + +### Error: "Quota exceeded" + +**Solution**: +1. Check quota limits in **APIs & Services > Quotas** +2. Request quota increase if needed +3. Implement rate limiting in your application + +--- + +## Additional Resources + +- [Google Cloud IAM Documentation](https://cloud.google.com/iam/docs) +- [Service Accounts Best Practices](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys) +- [OAuth 2.0 Guide](https://developers.google.com/identity/protocols/oauth2) +- [Google APIs Explorer](https://developers.google.com/apis-explorer) +- [Quotas and Limits](https://cloud.google.com/docs/quota) + +--- + +## Quick Reference + +### Commands Cheat Sheet + +```bash +# List enabled APIs +gcloud services list --enabled + +# Enable an API +gcloud services enable [API_NAME].googleapis.com + +# List service accounts +gcloud iam service-accounts list + +# Create service account key +gcloud iam service-accounts keys create ~/key.json \ + --iam-account=SERVICE_ACCOUNT_EMAIL + +# List service account keys +gcloud iam service-accounts keys list \ + --iam-account=SERVICE_ACCOUNT_EMAIL + +# Delete a service account key +gcloud iam service-accounts keys delete KEY_ID \ + --iam-account=SERVICE_ACCOUNT_EMAIL +``` + +### Environment Variables + +```bash +# Service Account +export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json" + +# OAuth +export GOOGLE_OAUTH_CLIENT_ID="your-client-id" +export GOOGLE_OAUTH_CLIENT_SECRET="your-secret" +export GOOGLE_OAUTH_REDIRECT_URI="http://localhost:3000/oauth/callback" + +# Project +export GOOGLE_CLOUD_PROJECT="your-project-id" +``` + +--- + +**Last Updated**: 2025-10-31 +**Version**: 1.0 diff --git a/GOOGLE_MCP_README.md b/GOOGLE_MCP_README.md new file mode 100644 index 000000000..b3a79de86 --- /dev/null +++ b/GOOGLE_MCP_README.md @@ -0,0 +1,288 @@ +# Google MCP Connection Documentation + +Complete setup documentation and tools for connecting to Google services via Model Context Protocol (MCP). + +## ?? Documentation Overview + +This repository contains everything you need to connect your MCP client (Cursor IDE or Claude Desktop) to Google services. + +### Quick Navigation + +| Document | Purpose | Best For | +|----------|---------|----------| +| **[QUICKSTART.md](QUICKSTART.md)** | 5-minute setup guide | Getting started quickly | +| **[GOOGLE_MCP_SETUP.md](GOOGLE_MCP_SETUP.md)** | Comprehensive setup guide | Detailed instructions | +| **[CREDENTIALS_GUIDE.md](CREDENTIALS_GUIDE.md)** | Google Cloud credentials | Setting up authentication | +| **[mcp_config_template.json](mcp_config_template.json)** | Configuration template | Reference configuration | +| **[setup_google_mcp.sh](setup_google_mcp.sh)** | Automated setup script | Linux/macOS automated setup | + +## ?? Getting Started + +### Option 1: Quick Start (5 minutes) +Follow **[QUICKSTART.md](QUICKSTART.md)** for the fastest path to connection. + +### Option 2: Automated Setup (Linux/macOS) +```bash +chmod +x setup_google_mcp.sh +./setup_google_mcp.sh +``` + +### Option 3: Manual Setup +Follow **[GOOGLE_MCP_SETUP.md](GOOGLE_MCP_SETUP.md)** for detailed step-by-step instructions. + +## ?? What You Can Do + +Once connected to Google MCP, you'll have access to: + +### ?? Google Drive +- List, search, and manage files +- Read and write documents +- Create folders and organize content +- Share files and manage permissions + +### ?? Gmail +- Read and search emails +- Send and compose messages +- Manage labels and threads +- Filter and organize inbox + +### ?? Google Calendar +- View and create events +- Manage scheduling +- Handle attendees and invitations +- Set reminders and notifications + +### ??? Google Maps +- Search locations +- Get directions +- Geocoding services +- Place information + +### ?? Google Search +- Web search capabilities +- Custom search integration + +## ?? Setup Checklist + +- [ ] Node.js 16+ installed +- [ ] Google Cloud account created +- [ ] Google Cloud project created +- [ ] Required APIs enabled (Drive, Gmail, Calendar) +- [ ] Service account created +- [ ] JSON credentials downloaded +- [ ] Credentials saved securely +- [ ] MCP client configured (Cursor/Claude) +- [ ] Application restarted +- [ ] Connection tested + +## ?? Prerequisites + +### System Requirements +- **Node.js**: Version 16 or higher +- **npm**: Usually comes with Node.js +- **MCP Client**: Cursor IDE or Claude Desktop + +### Google Cloud Requirements +- Google account +- Google Cloud project +- Enabled APIs: + - Google Drive API + - Gmail API + - Google Calendar API + - (Optional) Google Maps API + - (Optional) Custom Search API + +### Accounts & Access +- Google Cloud Console access +- Permission to create service accounts +- Permission to enable APIs + +## ?? Detailed Documentation + +### For First-Time Users +1. Start with **[QUICKSTART.md](QUICKSTART.md)** +2. Reference **[CREDENTIALS_GUIDE.md](CREDENTIALS_GUIDE.md)** for Google Cloud setup +3. Use the automated script `setup_google_mcp.sh` (Linux/macOS) + +### For Advanced Setup +1. Read **[GOOGLE_MCP_SETUP.md](GOOGLE_MCP_SETUP.md)** thoroughly +2. Review **[CREDENTIALS_GUIDE.md](CREDENTIALS_GUIDE.md)** for OAuth setup +3. Customize **[mcp_config_template.json](mcp_config_template.json)** for your needs + +### For Troubleshooting +- Check the Troubleshooting section in **[GOOGLE_MCP_SETUP.md](GOOGLE_MCP_SETUP.md)** +- Review credential issues in **[CREDENTIALS_GUIDE.md](CREDENTIALS_GUIDE.md)** +- Verify configuration against **[mcp_config_template.json](mcp_config_template.json)** + +## ?? Security + +### Critical Security Practices + +? **DO:** +- Keep credentials.json secure (600 permissions) +- Use .gitignore to prevent committing credentials +- Rotate service account keys regularly +- Use least privilege principle for API access +- Monitor API usage in Google Cloud Console + +? **DON'T:** +- Never commit credentials to version control +- Never share credentials via email/chat +- Never grant excessive permissions +- Never use production credentials for testing + +### Files Excluded from Git +The `.gitignore` file automatically excludes: +- `credentials.json` +- `*-credentials.json` +- `google-credentials*.json` +- `mcp_settings.json` (may contain sensitive paths) +- `claude_desktop_config.json` + +## ??? Scripts & Tools + +### setup_google_mcp.sh +Interactive setup script that: +- ? Checks system requirements +- ? Installs Google MCP server +- ? Creates credentials directory +- ? Guides through credential setup +- ? Configures MCP client automatically +- ? Provides verification steps + +**Usage:** +```bash +chmod +x setup_google_mcp.sh +./setup_google_mcp.sh +``` + +### mcp_config_template.json +Template configuration for MCP clients. Copy and customize for your setup. + +**Usage:** +```bash +# For Cursor (Linux) +cp mcp_config_template.json ~/.config/cursor/mcp_settings.json + +# For Claude Desktop (Linux) +cp mcp_config_template.json ~/.config/claude/claude_desktop_config.json + +# Edit and update paths +nano ~/.config/cursor/mcp_settings.json +``` + +## ?? Testing Your Setup + +After completing setup, test with these commands in your MCP client: + +``` +# Google Drive +"List my Google Drive files" +"Search my Drive for documents about MCP" + +# Gmail +"Show my recent Gmail messages" +"Search my email for messages from last week" + +# Calendar +"What's on my calendar today?" +"Show my upcoming meetings this week" + +# General +"Help me organize my Drive files" +"Summarize my recent emails" +``` + +## ?? Common Issues + +### Installation Issues +**Problem**: "Cannot find module @modelcontextprotocol/server-google" +**Solution**: +```bash +npm install -g @modelcontextprotocol/server-google +``` + +### Credential Issues +**Problem**: "Invalid credentials" or "Permission denied" +**Solution**: +1. Verify path to credentials.json +2. Check file permissions: `chmod 600 ~/.config/google-mcp/credentials.json` +3. Ensure service account has required API access + +### API Issues +**Problem**: "API not enabled" +**Solution**: Enable the API in [Google Cloud Console](https://console.cloud.google.com/apis/library) + +### Configuration Issues +**Problem**: No tools appearing in MCP client +**Solution**: +1. Verify JSON syntax in config file +2. Check config file location +3. Restart MCP client +4. Check application logs + +## ?? Additional Resources + +### Official Documentation +- [Model Context Protocol](https://modelcontextprotocol.io/) +- [Google Cloud Console](https://console.cloud.google.com/) +- [Google APIs Documentation](https://developers.google.com/apis-explorer) + +### Google Cloud Guides +- [IAM Best Practices](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys) +- [Service Accounts](https://cloud.google.com/iam/docs/service-accounts) +- [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2) + +### API-Specific Docs +- [Google Drive API](https://developers.google.com/drive) +- [Gmail API](https://developers.google.com/gmail/api) +- [Google Calendar API](https://developers.google.com/calendar) +- [Google Maps Platform](https://developers.google.com/maps) + +## ?? Support + +If you encounter issues: + +1. **Check Documentation**: Review relevant guides above +2. **Verify Setup**: Run through checklist again +3. **Check Logs**: Look at MCP client logs for errors +4. **Test Credentials**: Verify Google Cloud Console settings +5. **Consult Community**: Check MCP GitHub issues + +## ?? Version History + +- **1.0** (2025-10-31) + - Initial release + - Complete setup documentation + - Automated setup script + - Configuration templates + - Security best practices + +## ??? Document Map + +``` +Google MCP Documentation/ +? +??? QUICKSTART.md # Start here! 5-min setup +??? GOOGLE_MCP_SETUP.md # Comprehensive guide +??? CREDENTIALS_GUIDE.md # Google Cloud setup +??? mcp_config_template.json # Config template +??? setup_google_mcp.sh # Automated setup +??? .gitignore # Security protection +??? GOOGLE_MCP_README.md # This file +``` + +## ?? Next Steps + +1. ? Choose your setup path (Quick/Automated/Manual) +2. ? Follow the guide step-by-step +3. ? Test your connection +4. ? Start using Google services via MCP! + +--- + +**Created**: 2025-10-31 +**Last Updated**: 2025-10-31 +**Branch**: cursor/connect-to-google-mcp-8a44 + +For questions or improvements, please refer to the detailed documentation files linked above. diff --git a/GOOGLE_MCP_SETUP.md b/GOOGLE_MCP_SETUP.md new file mode 100644 index 000000000..2c15473b2 --- /dev/null +++ b/GOOGLE_MCP_SETUP.md @@ -0,0 +1,248 @@ +# Google MCP Connection Setup Guide + +This guide will walk you through connecting to Google services via the Model Context Protocol (MCP). + +## What is MCP? + +Model Context Protocol (MCP) is an open protocol that enables AI assistants to securely connect to various data sources and tools. The Google MCP server allows integration with Google services like Drive, Gmail, Calendar, Maps, and Search. + +## Prerequisites + +- Node.js 16 or higher +- Google Cloud account +- Cursor IDE or Claude Desktop (or any MCP-compatible client) + +## Step 1: Install Node.js (if not already installed) + +Check if Node.js is installed: +```bash +node --version +``` + +If not installed, download from [nodejs.org](https://nodejs.org/) or use a package manager: +```bash +# Ubuntu/Debian +sudo apt update && sudo apt install nodejs npm + +# macOS +brew install node + +# Windows +winget install OpenJS.NodeJS +``` + +## Step 2: Set Up Google Cloud Credentials + +### 2.1 Create a Google Cloud Project + +1. Go to [Google Cloud Console](https://console.cloud.google.com/) +2. Create a new project or select an existing one +3. Note your Project ID + +### 2.2 Enable Required APIs + +Enable the APIs you want to use: +- **Google Drive API** - For file access +- **Gmail API** - For email operations +- **Google Calendar API** - For calendar management +- **Google Maps Platform** - For location services +- **Custom Search API** - For web search + +Enable them via: +```bash +gcloud services enable drive.googleapis.com +gcloud services enable gmail.googleapis.com +gcloud services enable calendar-json.googleapis.com +gcloud services enable maps-backend.googleapis.com +``` + +Or enable via the [API Library](https://console.cloud.google.com/apis/library) + +### 2.3 Create Service Account + +1. Navigate to **IAM & Admin > Service Accounts** +2. Click **Create Service Account** +3. Name it (e.g., "mcp-google-connector") +4. Grant necessary roles: + - **Google Drive**: "Drive Admin" or "Drive API User" + - **Gmail**: "Gmail API User" + - **Calendar**: "Calendar API User" +5. Click **Done** + +### 2.4 Generate JSON Key + +1. Click on the service account you created +2. Go to **Keys** tab +3. Click **Add Key > Create New Key** +4. Select **JSON** format +5. Download the key file +6. **Important**: Keep this file secure and never commit it to version control! + +### 2.5 Save Credentials + +Save the JSON key file to a secure location: +```bash +# Recommended location +mkdir -p ~/.config/google-mcp +mv ~/Downloads/your-project-*-*.json ~/.config/google-mcp/credentials.json +chmod 600 ~/.config/google-mcp/credentials.json +``` + +## Step 3: Install Google MCP Server + +You have two options: + +### Option A: Global Installation (Recommended) +```bash +npm install -g @modelcontextprotocol/server-google +``` + +### Option B: Use npx (No Installation) +The configuration will use `npx` to run the server on-demand. + +## Step 4: Configure MCP Client + +### For Cursor IDE + +Create or edit the MCP configuration file: + +**Location:** +- **Linux**: `~/.config/cursor/mcp_settings.json` +- **macOS**: `~/Library/Application Support/Cursor/mcp_settings.json` +- **Windows**: `%APPDATA%\Cursor\mcp_settings.json` + +**Configuration:** +```json +{ + "mcpServers": { + "google": { + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-google"], + "env": { + "GOOGLE_APPLICATION_CREDENTIALS": "/home/YOUR_USERNAME/.config/google-mcp/credentials.json" + } + } + } +} +``` + +**Replace** `/home/YOUR_USERNAME/` with your actual home directory path. + +### For Claude Desktop + +**Location:** +- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json` +- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json` +- **Linux**: `~/.config/claude/claude_desktop_config.json` + +Use the same JSON configuration as above. + +## Step 5: Configure OAuth (Optional, for User-Based Access) + +For accessing user-specific data (recommended for Gmail, Drive): + +1. Create OAuth 2.0 Credentials: + - Go to **APIs & Credentials > Create Credentials > OAuth Client ID** + - Choose **Desktop App** + - Download the JSON file + +2. Update your MCP configuration: +```json +{ + "mcpServers": { + "google": { + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-google"], + "env": { + "GOOGLE_OAUTH_CLIENT_ID": "your-client-id.apps.googleusercontent.com", + "GOOGLE_OAUTH_CLIENT_SECRET": "your-client-secret", + "GOOGLE_OAUTH_REDIRECT_URI": "http://localhost:3000/oauth/callback" + } + } + } +} +``` + +## Step 6: Restart Your MCP Client + +1. **Cursor**: Restart the application +2. **Claude Desktop**: Restart the application + +## Step 7: Verify Connection + +After restart, you should see Google MCP tools available. Try: +- "List files in my Google Drive" +- "Search my Gmail for recent messages" +- "Show my calendar events for today" + +## Troubleshooting + +### Error: "Cannot find module" +```bash +npm install -g @modelcontextprotocol/server-google +``` + +### Error: "Invalid credentials" +- Verify the path to your credentials.json is correct +- Check file permissions (should be readable) +- Ensure the service account has the necessary API permissions + +### Error: "API not enabled" +Enable the required API in Google Cloud Console: +```bash +gcloud services enable [API_NAME] +``` + +### Connection timeout +- Check your internet connection +- Verify firewall settings aren't blocking the connection +- Try increasing timeout in MCP settings + +### No tools appearing +1. Check the MCP server logs (usually in client app logs) +2. Verify the configuration file syntax is valid JSON +3. Ensure the command path is correct + +## Available Google MCP Tools + +Once connected, you'll have access to: + +- **Google Drive**: File search, read, write, create, delete +- **Gmail**: Email search, read, send, compose +- **Google Calendar**: Event creation, viewing, updating +- **Google Maps**: Location search, directions, geocoding +- **Google Search**: Web search capabilities + +## Security Best Practices + +1. ? **Never commit credentials to git** + ```bash + echo "credentials.json" >> .gitignore + echo "*.json" >> .gitignore # if storing in repo + ``` + +2. ? **Use least privilege** - Only grant necessary API permissions + +3. ? **Rotate keys regularly** - Generate new service account keys periodically + +4. ? **Monitor usage** - Check Google Cloud Console for unexpected API calls + +5. ? **Use OAuth for user data** - Service accounts for application data + +## Additional Resources + +- [MCP Documentation](https://modelcontextprotocol.io/) +- [Google Cloud IAM Guide](https://cloud.google.com/iam/docs) +- [Google APIs Documentation](https://developers.google.com/apis-explorer) + +## Support + +If you encounter issues: +1. Check the troubleshooting section above +2. Review MCP client logs +3. Verify Google Cloud Console for API quotas and errors +4. Consult the [MCP GitHub repository](https://github.com/modelcontextprotocol) + +--- + +**Last Updated**: 2025-10-31 diff --git a/QUICKSTART.md b/QUICKSTART.md new file mode 100644 index 000000000..eb92a0b21 --- /dev/null +++ b/QUICKSTART.md @@ -0,0 +1,210 @@ +# Google MCP Quick Start Guide + +Get connected to Google services via MCP in 5 minutes! ?? + +## Prerequisites +- ? Node.js 16+ installed +- ? Google account +- ? Cursor IDE or Claude Desktop + +## Quick Setup (Linux/macOS) + +### Option 1: Automated Setup (Recommended) + +Run the setup script: + +```bash +chmod +x setup_google_mcp.sh +./setup_google_mcp.sh +``` + +The script will: +1. ? Check Node.js installation +2. ? Install Google MCP server +3. ? Set up credentials directory +4. ? Configure your MCP client +5. ? Provide next steps + +### Option 2: Manual Setup + +#### Step 1: Install MCP Server +```bash +npm install -g @modelcontextprotocol/server-google +``` + +#### Step 2: Get Google Credentials +1. Go to [Google Cloud Console](https://console.cloud.google.com/) +2. Create a project +3. Enable these APIs: + - Google Drive API + - Gmail API + - Google Calendar API +4. Create a Service Account +5. Generate & download JSON key + +#### Step 3: Save Credentials +```bash +mkdir -p ~/.config/google-mcp +mv ~/Downloads/your-key-*.json ~/.config/google-mcp/credentials.json +chmod 600 ~/.config/google-mcp/credentials.json +``` + +#### Step 4: Configure MCP Client + +**For Cursor** (`~/.config/cursor/mcp_settings.json`): +```json +{ + "mcpServers": { + "google": { + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-google"], + "env": { + "GOOGLE_APPLICATION_CREDENTIALS": "/home/YOUR_USERNAME/.config/google-mcp/credentials.json" + } + } + } +} +``` + +**For Claude Desktop** (`~/.config/claude/claude_desktop_config.json`): Same config as above. + +**Replace** `/home/YOUR_USERNAME/` with your actual path! + +#### Step 5: Restart & Test +1. Restart Cursor or Claude Desktop +2. Try: "List my Google Drive files" + +## Windows Quick Setup + +### Step 1: Install MCP Server +```powershell +npm install -g @modelcontextprotocol/server-google +``` + +### Step 2: Get & Save Credentials +```powershell +# Create directory +New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.config\google-mcp" + +# Move credentials (adjust source path) +Move-Item "$env:USERPROFILE\Downloads\your-key-*.json" "$env:USERPROFILE\.config\google-mcp\credentials.json" +``` + +### Step 3: Configure MCP Client + +**Config location**: +- Cursor: `%APPDATA%\Cursor\mcp_settings.json` +- Claude: `%APPDATA%\Claude\claude_desktop_config.json` + +**Config content**: +```json +{ + "mcpServers": { + "google": { + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-google"], + "env": { + "GOOGLE_APPLICATION_CREDENTIALS": "C:\\Users\\YOUR_USERNAME\\.config\\google-mcp\\credentials.json" + } + } + } +} +``` + +**Replace** `YOUR_USERNAME` with your Windows username! + +### Step 4: Restart & Test +Restart your application and test the connection. + +## Verify Installation + +After setup, test with these commands: + +``` +?? "List my Google Drive files" +?? "Show my recent Gmail messages" +?? "What's on my calendar today?" +?? "Search my Drive for documents about MCP" +``` + +## What's Available? + +Once connected, you can: + +### Google Drive +- ?? List, search, read, create, update, delete files +- ?? Manage folders and permissions +- ?? Download and upload files + +### Gmail +- ?? Read, search, send emails +- ?? Manage labels and threads +- ?? Draft and compose messages + +### Google Calendar +- ?? View, create, update events +- ? Manage event reminders +- ?? Handle attendees and invitations + +### Google Maps (if enabled) +- ?? Search locations +- ??? Get directions +- ?? Geocoding and reverse geocoding + +### Google Search (if enabled) +- ?? Web search capabilities +- ?? Custom search integration + +## Troubleshooting + +### "Cannot find module" error +```bash +npm install -g @modelcontextprotocol/server-google +``` + +### "Invalid credentials" error +- Verify credentials file path is correct +- Check file permissions: `ls -l ~/.config/google-mcp/credentials.json` +- Ensure service account has required API access + +### "API not enabled" error +Enable missing APIs in [Google Cloud Console](https://console.cloud.google.com/apis/library) + +### No tools appearing +1. Check config file syntax (must be valid JSON) +2. Verify command path is correct +3. Check application logs for errors +4. Restart your MCP client + +## Need More Help? + +- ?? **Detailed Setup**: See `GOOGLE_MCP_SETUP.md` +- ?? **Credentials Guide**: See `CREDENTIALS_GUIDE.md` +- ??? **Configuration Template**: See `mcp_config_template.json` + +## Security Reminder + +?? **NEVER commit your credentials.json to version control!** + +The `.gitignore` file has been configured to prevent this, but always double-check: + +```bash +git status # Make sure credentials.json is not listed +``` + +## Next Steps + +1. ? Complete setup using automated script or manual steps +2. ? Enable required APIs in Google Cloud Console +3. ? Restart your MCP client +4. ? Test the connection +5. ?? Start using Google services via MCP! + +--- + +**Quick Links**: +- [Google Cloud Console](https://console.cloud.google.com/) +- [MCP Documentation](https://modelcontextprotocol.io/) +- [Google APIs Explorer](https://developers.google.com/apis-explorer) + +**Created**: 2025-10-31 diff --git a/mcp_config_template.json b/mcp_config_template.json new file mode 100644 index 000000000..edb19c75d --- /dev/null +++ b/mcp_config_template.json @@ -0,0 +1,11 @@ +{ + "mcpServers": { + "google": { + "command": "npx", + "args": ["-y", "@modelcontextprotocol/server-google"], + "env": { + "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/your/credentials.json" + } + } + } +} diff --git a/setup_google_mcp.sh b/setup_google_mcp.sh new file mode 100755 index 000000000..20e3b7840 --- /dev/null +++ b/setup_google_mcp.sh @@ -0,0 +1,231 @@ +#!/bin/bash +# Google MCP Setup Script +# This script helps you set up the Google MCP connection + +set -e + +echo "======================================" +echo "Google MCP Connection Setup" +echo "======================================" +echo "" + +# Colors for output +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +# Function to print colored output +print_success() { + echo -e "${GREEN}?${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}?${NC} $1" +} + +print_error() { + echo -e "${RED}?${NC} $1" +} + +# Check if Node.js is installed +echo "Step 1: Checking Node.js installation..." +if command -v node &> /dev/null; then + NODE_VERSION=$(node --version) + print_success "Node.js is installed: $NODE_VERSION" +else + print_error "Node.js is not installed!" + echo "Please install Node.js from https://nodejs.org/ or use:" + echo " Ubuntu/Debian: sudo apt update && sudo apt install nodejs npm" + echo " macOS: brew install node" + exit 1 +fi + +# Check npm +if command -v npm &> /dev/null; then + NPM_VERSION=$(npm --version) + print_success "npm is installed: $NPM_VERSION" +else + print_error "npm is not installed!" + exit 1 +fi + +# Ask if user wants to install the MCP server globally +echo "" +echo "Step 2: Install Google MCP Server" +read -p "Do you want to install @modelcontextprotocol/server-google globally? (y/n): " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Installing Google MCP server..." + npm install -g @modelcontextprotocol/server-google + print_success "Google MCP server installed!" +else + print_warning "Skipping installation. Configuration will use npx instead." +fi + +# Create credentials directory +echo "" +echo "Step 3: Setting up credentials directory..." +CRED_DIR="$HOME/.config/google-mcp" +mkdir -p "$CRED_DIR" +print_success "Created directory: $CRED_DIR" + +# Check for credentials file +CRED_FILE="$CRED_DIR/credentials.json" +echo "" +echo "Step 4: Google Cloud Credentials" +echo "You need to download your service account JSON key from Google Cloud Console." +echo "" +echo "Instructions:" +echo "1. Go to https://console.cloud.google.com/" +echo "2. Select your project (or create one)" +echo "3. Navigate to 'IAM & Admin > Service Accounts'" +echo "4. Create a service account or select an existing one" +echo "5. Go to 'Keys' tab and create a new JSON key" +echo "6. Download the key file" +echo "" + +if [ -f "$CRED_FILE" ]; then + print_success "Credentials file already exists at: $CRED_FILE" + read -p "Do you want to replace it? (y/n): " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + print_warning "Keeping existing credentials." + else + read -p "Enter the path to your downloaded credentials JSON file: " INPUT_CRED_PATH + if [ -f "$INPUT_CRED_PATH" ]; then + cp "$INPUT_CRED_PATH" "$CRED_FILE" + chmod 600 "$CRED_FILE" + print_success "Credentials copied and secured!" + else + print_error "File not found: $INPUT_CRED_PATH" + fi + fi +else + read -p "Enter the path to your downloaded credentials JSON file (or press Enter to skip): " INPUT_CRED_PATH + if [ -n "$INPUT_CRED_PATH" ] && [ -f "$INPUT_CRED_PATH" ]; then + cp "$INPUT_CRED_PATH" "$CRED_FILE" + chmod 600 "$CRED_FILE" + print_success "Credentials copied and secured!" + else + print_warning "Credentials not set. You'll need to manually copy them to: $CRED_FILE" + fi +fi + +# Detect OS and set config path +echo "" +echo "Step 5: Creating MCP configuration..." + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + CURSOR_CONFIG="$HOME/.config/cursor/mcp_settings.json" + CLAUDE_CONFIG="$HOME/.config/claude/claude_desktop_config.json" +elif [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + CURSOR_CONFIG="$HOME/Library/Application Support/Cursor/mcp_settings.json" + CLAUDE_CONFIG="$HOME/Library/Application Support/Claude/claude_desktop_config.json" +elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + # Windows + CURSOR_CONFIG="$APPDATA/Cursor/mcp_settings.json" + CLAUDE_CONFIG="$APPDATA/Claude/claude_desktop_config.json" +else + print_warning "Unknown OS type. You'll need to manually configure." + exit 0 +fi + +echo "Select your MCP client:" +echo "1) Cursor IDE" +echo "2) Claude Desktop" +echo "3) Both" +echo "4) Skip (I'll configure manually)" +read -p "Enter choice [1-4]: " -n 1 -r CHOICE +echo + +CONFIG_CONTENT=$(cat < "$CONFIG_PATH" + print_success "$CLIENT_NAME configuration updated! (Backup created)" + else + print_warning "Skipping $CLIENT_NAME configuration." + fi + else + echo "$CONFIG_CONTENT" > "$CONFIG_PATH" + print_success "$CLIENT_NAME configuration created!" + fi +} + +case $CHOICE in + 1) + configure_client "$CURSOR_CONFIG" "Cursor" + ;; + 2) + configure_client "$CLAUDE_CONFIG" "Claude Desktop" + ;; + 3) + configure_client "$CURSOR_CONFIG" "Cursor" + configure_client "$CLAUDE_CONFIG" "Claude Desktop" + ;; + 4) + print_warning "Skipping automatic configuration." + echo "You can manually create the config file at:" + echo " Cursor: $CURSOR_CONFIG" + echo " Claude: $CLAUDE_CONFIG" + ;; + *) + print_error "Invalid choice" + exit 1 + ;; +esac + +# Final instructions +echo "" +echo "======================================" +echo "Setup Complete!" +echo "======================================" +echo "" +print_success "Google MCP is configured!" +echo "" +echo "Next steps:" +echo "1. Ensure you have enabled the required Google APIs in Cloud Console:" +echo " - Google Drive API" +echo " - Gmail API" +echo " - Google Calendar API" +echo " - Google Maps API (if needed)" +echo " - Custom Search API (if needed)" +echo "" +echo "2. Restart your MCP client (Cursor or Claude Desktop)" +echo "" +echo "3. Test the connection by asking your AI assistant:" +echo " - 'List my Google Drive files'" +echo " - 'Show my calendar for today'" +echo "" +echo "For more details, see GOOGLE_MCP_SETUP.md" +echo "" +print_warning "Remember: Never commit your credentials.json file to version control!" +echo ""