Google Calendar MCP Server
This MCP server allows Claude to interact with your Google Calendar, enabling capabilities like listing events, creating meetings, and finding free time slots.
Prerequisites
- Node.js (v16 or higher)
- Claude Desktop App
- A Google Cloud Project
- Google Calendar API enabled
- OAuth 2.0 credentials
Setup Instructions
1. Create a Google Cloud Project
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Calendar API:
- Go to "APIs & Services" > "Library"
- Search for "Google Calendar API"
- Click "Enable"
2. Configure OAuth Consent Screen
- Go to "APIs & Services" > "OAuth consent screen"
- Select "External" user type (unless you have a Google Workspace organization)
- Fill in the required information:
- App name
- User support email
- Developer contact information
- Add the following scopes:
https://www.googleapis.com/auth/calendar
https://www.googleapis.com/auth/calendar.events
- Add your email address as a test user
3. Create OAuth 2.0 Credentials
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Desktop app" as the application type
- Name your client (e.g., "MCP Calendar Client")
- Click "Create"
- Download the client configuration file (you'll need the client ID and client secret)
4. Get Refresh Token
- Create a new file named
getToken.js
:
1const { google } = require('googleapis'); 2const http = require('http'); 3const url = require('url'); 4 5// Replace these with your OAuth 2.0 credentials 6const CLIENT_ID = 'your-client-id'; 7const CLIENT_SECRET = 'your-client-secret'; 8const REDIRECT_URI = 'http://localhost:3000/oauth2callback'; 9 10// Configure OAuth2 client 11const oauth2Client = new google.auth.OAuth2( 12 CLIENT_ID, 13 CLIENT_SECRET, 14 REDIRECT_URI 15); 16 17// Define scopes 18const scopes = [ 19 'https://www.googleapis.com/auth/calendar', 20 'https://www.googleapis.com/auth/calendar.events' 21]; 22 23async function getRefreshToken() { 24 return new Promise((resolve, reject) => { 25 try { 26 // Create server to handle OAuth callback 27 const server = http.createServer(async (req, res) => { 28 try { 29 const queryParams = url.parse(req.url, true).query; 30 31 if (queryParams.code) { 32 // Get tokens from code 33 const { tokens } = await oauth2Client.getToken(queryParams.code); 34 console.log('\n================='); 35 console.log('Refresh Token:', tokens.refresh_token); 36 console.log('=================\n'); 37 console.log('Save this refresh token in your configuration!'); 38 39 // Send success response 40 res.end('Authentication successful! You can close this window.'); 41 42 // Close server 43 server.close(); 44 resolve(tokens); 45 } 46 } catch (error) { 47 console.error('Error getting tokens:', error); 48 res.end('Authentication failed! Please check console for errors.'); 49 reject(error); 50 } 51 }).listen(3000, () => { 52 // Generate auth url 53 const authUrl = oauth2Client.generateAuthUrl({ 54 access_type: 'offline', 55 scope: scopes, 56 prompt: 'consent' // Force consent screen to ensure refresh token 57 }); 58 59 console.log('1. Copy this URL and paste it in your browser:'); 60 console.log('\n', authUrl, '\n'); 61 console.log('2. Follow the Google authentication process'); 62 console.log('3. Wait for the refresh token to appear here'); 63 }); 64 65 } catch (error) { 66 console.error('Server creation error:', error); 67 reject(error); 68 } 69 }); 70} 71 72// Run the token retrieval 73getRefreshToken().catch(console.error);
- Install required dependency:
1npm install googleapis
-
Update the script with your OAuth credentials:
- Replace
your-client-id
with your actual client ID - Replace
your-client-secret
with your actual client secret
- Replace
-
Run the script:
1node getToken.js
- Follow the instructions in the console:
- Copy the provided URL
- Paste it into your browser
- Complete the Google authentication process
- Copy the refresh token that appears in the console
5. Configure Claude Desktop
- Open your Claude Desktop configuration file:
For MacOS:
1code ~/Library/Application\ Support/Claude/claude_desktop_config.json
For Windows:
1code %AppData%\Claude\claude_desktop_config.json
- Add or update the configuration:
1{ 2 "mcpServers": { 3 "google-calendar": { 4 "command": "node", 5 "args": [ 6 "/ABSOLUTE/PATH/TO/YOUR/build/index.js" 7 ], 8 "env": { 9 "GOOGLE_CLIENT_ID": "your_client_id_here", 10 "GOOGLE_CLIENT_SECRET": "your_client_secret_here", 11 "GOOGLE_REDIRECT_URI": "http://localhost", 12 "GOOGLE_REFRESH_TOKEN": "your_refresh_token_here" 13 } 14 } 15 } 16}
- Save the file and restart Claude Desktop
Initial Project Setup
- Create a new directory for your project:
1mkdir google-calendar-mcp 2cd google-calendar-mcp
- Initialize a new npm project:
1npm init -y
- Install dependencies:
1npm install @modelcontextprotocol/sdk googleapis google-auth-library zod 2npm install -D @types/node typescript
- Create a tsconfig.json file:
1{ 2 "compilerOptions": { 3 "target": "ES2022", 4 "module": "Node16", 5 "moduleResolution": "Node16", 6 "outDir": "./build", 7 "rootDir": "./src", 8 "strict": true, 9 "esModuleInterop": true, 10 "skipLibCheck": true, 11 "forceConsistentCasingInFileNames": true 12 }, 13 "include": ["src/**/*"], 14 "exclude": ["node_modules"] 15}
- Update package.json:
1{ 2 "type": "module", 3 "scripts": { 4 "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"" 5 } 6}
- Create your source directory:
1mkdir src
- Create a .env file for local development (don't commit this file):
1GOOGLE_CLIENT_ID=your_client_id_here 2GOOGLE_CLIENT_SECRET=your_client_secret_here 3GOOGLE_REDIRECT_URI=http://localhost 4GOOGLE_REFRESH_TOKEN=your_refresh_token_here
Building and Running
- Build the server:
1npm run build
- The server will automatically start when you open Claude Desktop
Available Tools
The server provides the following tools:
list_events
: List calendar events within a specified time rangecreate_event
: Create a new calendar eventupdate_event
: Update an existing calendar eventdelete_event
: Delete a calendar eventfind_free_time
: Find available time slots in the calendar
Example Usage in Claude
After setup, you can use commands like:
- "Show me my calendar events for next week"
- "Schedule a meeting with [email_id] tomorrow at 2 PM for 1 hour"
- "Find a free 30-minute slot this afternoon"
- "Update my 3 PM meeting to 4 PM"
- "Cancel my meeting with ID [event_id]"
Troubleshooting
Common Issues
-
Tools not appearing in Claude:
- Check Claude Desktop logs:
tail -f ~/Library/Logs/Claude/mcp*.log
- Verify all environment variables are set correctly
- Ensure the path to index.js is absolute and correct
- Check Claude Desktop logs:
-
Authentication Errors:
- Verify your OAuth credentials are correct
- Check if refresh token is valid
- Ensure required scopes are enabled
-
Server Connection Issues:
- Check if the server built successfully
- Verify file permissions on build/index.js (should be 755)
- Try running the server directly:
node /path/to/build/index.js
Viewing Logs
To view server logs:
1# For MacOS/Linux: 2tail -n 20 -f ~/Library/Logs/Claude/mcp*.log 3 4# For Windows: 5Get-Content -Path "$env:AppData\Claude\Logs\mcp*.log" -Wait -Tail 20
Environment Variables
If you're getting environment variable errors, verify each one:
- GOOGLE_CLIENT_ID: Should start with something like "123456789-..."
- GOOGLE_CLIENT_SECRET: Usually ends in ".apps.googleusercontent.com"
- GOOGLE_REDIRECT_URI: Should be "http://localhost"
- GOOGLE_REFRESH_TOKEN: A long string that doesn't expire
Security Considerations
- Keep your OAuth credentials secure
- Don't commit credentials to version control
- Use environment variables for sensitive data
- Regularly rotate refresh tokens
- Monitor API usage in Google Cloud Console
License
MIT License - See LICENSE file for details.
Support
If you encounter any issues:
- Check the troubleshooting section above
- Review Claude Desktop logs
- Open an issue on GitHub
- Contact the maintainer